Skip to content

Commit

Permalink
Merge pull request #1137 from nyaruka/localization_fix_for_the_fix
Browse files Browse the repository at this point in the history
Ignore empty string translations in flow localization sections
  • Loading branch information
rowanseymour authored Oct 21, 2022
2 parents 1fd735a + 56aa1de commit 097d32b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
30 changes: 19 additions & 11 deletions flows/definition/localization.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
}
Expand Down
12 changes: 12 additions & 0 deletions flows/runs/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 13 additions & 0 deletions flows/runs/testdata/translation_assets.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,19 @@
"si"
]
}
},
"fra": {
"0a8467eb-911a-41db-8101-ccf415c48e6a": {
"text": [
"Bonjour"
],
"attachments": [
""
],
"quick_replies": [
""
]
}
}
},
"nodes": [
Expand Down

0 comments on commit 097d32b

Please sign in to comment.