diff --git a/flows/definition/localization.go b/flows/definition/localization.go index 91dfad1fe..54c9e2d93 100644 --- a/flows/definition/localization.go +++ b/flows/definition/localization.go @@ -10,20 +10,22 @@ import ( ) // holds all property translations for a specific item, e.g. -// { -// "text": "Do you like cheese?" -// "quick_replies": ["Yes", "No"] -// } +// +// { +// "text": "Do you like cheese?" +// "quick_replies": ["Yes", "No"] +// } type itemTranslation map[string][]string // holds all the item translations for a specific language, e.g. -// { -// "f3368070-8db8-4549-872a-e69a9d060612": { -// "text": "Do you like cheese?" -// "quick_replies": ["Yes", "No"] -// }, -// "7a1aec43-f3e1-42f0-b967-0ee75e725e3a": { ... } -// } +// +// { +// "f3368070-8db8-4549-872a-e69a9d060612": { +// "text": "Do you like cheese?" +// "quick_replies": ["Yes", "No"] +// }, +// "7a1aec43-f3e1-42f0-b967-0ee75e725e3a": { ... } +// } type languageTranslation map[uuids.UUID]itemTranslation // returns the requested item translation @@ -32,6 +34,12 @@ func (t languageTranslation) getTextArray(uuid uuids.UUID, property string) []st if found { translation, found := item[property] if found { + // TODO editor sometimes saves empty rule translations as [""] which we should fix in a flow migration + // but for now need to ignore + if len(translation) == 0 || (len(translation) == 1 && translation[0] == "") { + return nil + } + return translation } } diff --git a/flows/runs/run_test.go b/flows/runs/run_test.go index 76ea02e81..e8461a00f 100644 --- a/flows/runs/run_test.go +++ b/flows/runs/run_test.go @@ -404,6 +404,18 @@ func TestTranslation(t *testing.T) { }, expectedQuickReplies: []string{"si"}, }, + { + description: "attachments and quick replies translations are single empty strings and should be ignored", + envLangs: []envs.Language{"eng", "fra"}, + contactLang: "fra", + msgAction: msgAction1, + expectedText: "Bonjour", + expectedAttachments: []utils.Attachment{ + "image/jpeg:http://media.com/hello.jpg", + "audio/mp4:http://media.com/hello.m4a", + }, + expectedQuickReplies: []string{"yes", "no"}, + }, } for _, tc := range tcs { diff --git a/flows/runs/testdata/translation_assets.json b/flows/runs/testdata/translation_assets.json index 0e3d662c6..0bf19e7c9 100644 --- a/flows/runs/testdata/translation_assets.json +++ b/flows/runs/testdata/translation_assets.json @@ -34,6 +34,19 @@ "si" ] } + }, + "fra": { + "0a8467eb-911a-41db-8101-ccf415c48e6a": { + "text": [ + "Bonjour" + ], + "attachments": [ + "" + ], + "quick_replies": [ + "" + ] + } } }, "nodes": [