From ddb7b22fa2f9403240bc00d4d22c6e658a959b14 Mon Sep 17 00:00:00 2001 From: Rowan Seymour Date: Thu, 25 Jan 2018 13:46:24 -0500 Subject: [PATCH] Fix quick replies when language translations are missing --- flows/definition/legacy_test.go | 6 ++++-- flows/definition/testdata/migrations/actions.json | 7 ++++--- flows/runs/run.go | 14 ++++++++++++-- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/flows/definition/legacy_test.go b/flows/definition/legacy_test.go index ad2387e8d..06bda9a84 100644 --- a/flows/definition/legacy_test.go +++ b/flows/definition/legacy_test.go @@ -304,9 +304,11 @@ func TestTranslations(t *testing.T) { translations := []map[utils.Language]string{ {"eng": "Yes", "fra": "Oui"}, {"eng": "No", "fra": "Non"}, + {"eng": "Maybe"}, + {"eng": "Never", "fra": "Jamas"}, } assert.Equal(t, map[utils.Language][]string{ - "eng": {"Yes", "No"}, - "fra": {"Oui", "Non"}, + "eng": {"Yes", "No", "Maybe", "Never"}, + "fra": {"Oui", "Non", "", "Jamas"}, }, transformTranslations(translations)) } diff --git a/flows/definition/testdata/migrations/actions.json b/flows/definition/testdata/migrations/actions.json index b1c3197da..0aeac315c 100644 --- a/flows/definition/testdata/migrations/actions.json +++ b/flows/definition/testdata/migrations/actions.json @@ -155,7 +155,8 @@ }, "quick_replies": [ {"eng": "Yes", "fra": "Oui"}, - {"eng": "No", "fra": "Non"} + {"eng": "No", "fra": "Non"}, + {"eng": "Maybe"} ], "send_all": true }, @@ -164,7 +165,7 @@ "uuid": "5a4d00aa-807e-44af-9693-64b9fdedd352", "text": "Do you still live in @contact.fields.city?", "attachments": ["image/jpeg:http://s3.amazon.com/bucket/test_en.jpg?a=@contact.fields.age"], - "quick_replies": ["Yes", "No"], + "quick_replies": ["Yes", "No", "Maybe"], "all_urns": true }, "expected_localization": { @@ -172,7 +173,7 @@ "5a4d00aa-807e-44af-9693-64b9fdedd352": { "attachments": ["image/jpeg:http://s3.amazon.com/bucket/test_fr.jpg?a=@contact.fields.age"], "text": ["Vous habitez toujours à @contact.fields.city"], - "quick_replies": ["Oui", "Non"] + "quick_replies": ["Oui", "Non", ""] } } } diff --git a/flows/runs/run.go b/flows/runs/run.go index 6c871d2d9..cda043d9d 100644 --- a/flows/runs/run.go +++ b/flows/runs/run.go @@ -270,9 +270,19 @@ func (r *flowRun) GetTextArray(uuid flows.UUID, key string, native []string) []s translations := r.Flow().Translations().GetLanguageTranslations(lang) if translations != nil { textArray := translations.GetTextArray(uuid, key) - if textArray != nil && len(textArray) == len(native) { - return textArray + if textArray == nil { + return native } + + merged := make([]string, len(native)) + for s := range native { + if textArray[s] != "" { + merged[s] = textArray[s] + } else { + merged[s] = native[s] + } + } + return merged } } return native