Skip to content

Commit

Permalink
Make flow happy
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Apr 20, 2017
1 parent 4b3e86e commit bb5bb2e
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions web/static/js/reducers/questionnaire.js
Original file line number Diff line number Diff line change
Expand Up @@ -1484,30 +1484,39 @@ const translateChoice = (choice, defaultLanguage, lookup) => {

if (responses.sms && responses.sms[defaultLanguage]) {
const defLangSms = getChoiceResponseSmsJoined(choice, defaultLanguage)
newChoice.responses.sms = processTranslations(defLangSms, newChoice.responses.sms || {}, lookup)
newChoice.responses.sms = processTranslationsArray(defLangSms, newChoice.responses.sms || {}, lookup)
}

if (responses.mobileweb && responses.mobileweb[defaultLanguage]) {
const defLangMobileWeb = getChoiceResponseMobileWebJoined(choice, defaultLanguage)
newChoice.responses.mobileweb = processTranslations(defLangMobileWeb, newChoice.responses.mobileweb || {}, lookup, false)
newChoice.responses.mobileweb = processTranslationsString(defLangMobileWeb, newChoice.responses.mobileweb || {}, lookup)
}

return newChoice
}

const processTranslations = (value, obj, lookup, split = true) => {
const processTranslationsArray = (value, obj, lookup, split = true) => {
let translations

if (value && (translations = lookup[value])) {
for (let lang in translations) {
let result = translations[lang]
if (split) {
result = result.split(',').map(s => s.trim())
obj = {
...obj,
[lang]: translations[lang].split(',').map(s => s.trim())
}
}
}
return obj
}

const processTranslationsString = (value, obj, lookup) => {
let translations

if (value && (translations = lookup[value])) {
for (let lang in translations) {
obj = {
...obj,
[lang]: result
[lang]: translations[lang]
}
}
}
Expand Down

0 comments on commit bb5bb2e

Please sign in to comment.