Skip to content

Commit

Permalink
Merge pull request #144 from nyaruka/quick_reply_tweak
Browse files Browse the repository at this point in the history
Fix quick replies when language translations are missing
  • Loading branch information
rowanseymour authored Jan 25, 2018
2 parents 8d8fdcb + ddb7b22 commit 90f5046
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
6 changes: 4 additions & 2 deletions flows/definition/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
7 changes: 4 additions & 3 deletions flows/definition/testdata/migrations/actions.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@
},
"quick_replies": [
{"eng": "Yes", "fra": "Oui"},
{"eng": "No", "fra": "Non"}
{"eng": "No", "fra": "Non"},
{"eng": "Maybe"}
],
"send_all": true
},
Expand All @@ -164,15 +165,15 @@
"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": {
"fra": {
"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", ""]
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions flows/runs/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 90f5046

Please sign in to comment.