Skip to content

Commit

Permalink
Merge pull request #180 from nyaruka/broadcast_languages
Browse files Browse the repository at this point in the history
Broadcast languages
  • Loading branch information
rowanseymour authored Mar 13, 2018
2 parents d53330d + ec38a7d commit 666ef45
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion flows/actions/send_broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ func (a *SendBroadcastAction) Execute(run flows.FlowRun, step flows.Step, log fl
}

translations := make(map[utils.Language]*events.BroadcastTranslation)
languages := append(utils.LanguageList{run.Flow().Language()}, run.Flow().Translations().Languages()...)

// evaluate the broadcast in each language we have translations for
for _, language := range run.Session().Environment().Languages() {
for _, language := range languages {
languages := utils.LanguageList{language, run.Flow().Language()}.RemoveDuplicates()

evaluatedText, evaluatedAttachments, evaluatedQuickReplies := a.evaluateMessage(run, languages, a.Text, a.Attachments, a.QuickReplies, log)
Expand Down
2 changes: 1 addition & 1 deletion flows/definition/flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ func ReadFlow(data json.RawMessage) (flows.Flow, error) {
f.name = envelope.Name
f.language = envelope.Language
f.expireAfterMinutes = envelope.ExpireAfterMinutes
f.translations = &envelope.Localization
f.translations = envelope.Localization

f.nodes = make([]flows.Node, len(envelope.Nodes))
f.nodeMap = make(map[flows.NodeUUID]flows.Node)
Expand Down
12 changes: 10 additions & 2 deletions flows/definition/localization.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,16 @@ func (t *languageTranslations) GetTextArray(uuid utils.UUID, key string) []strin
// flowTranslations are our top level container for all the translations for a language
type flowTranslations map[utils.Language]*languageTranslations

func (t *flowTranslations) GetLanguageTranslations(lang utils.Language) flows.Translations {
translations, found := (*t)[lang]
func (t flowTranslations) Languages() utils.LanguageList {
languages := make(utils.LanguageList, 0, len(t))
for lang := range t {
languages = append(languages, lang)
}
return languages
}

func (t flowTranslations) GetLanguageTranslations(lang utils.Language) flows.Translations {
translations, found := t[lang]
if found {
return translations
}
Expand Down
1 change: 1 addition & 0 deletions flows/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type Wait interface {
// FlowTranslations provide a way to get the Translations for a flow for a specific language
type FlowTranslations interface {
GetLanguageTranslations(utils.Language) Translations
Languages() utils.LanguageList
}

// Translations provide a way to get the translation for a specific language for a uuid/key pair
Expand Down

0 comments on commit 666ef45

Please sign in to comment.