From a98c8f300e6dbaf1482e842bc64549f7bf7b515f Mon Sep 17 00:00:00 2001 From: martin bedouret Date: Tue, 19 Apr 2022 23:04:18 -0300 Subject: [PATCH] fix language labels --- .../Settings/Language/Language.component.js | 60 ++++++++++++------- .../Settings/Language/Language.messages.js | 4 ++ 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/src/components/Settings/Language/Language.component.js b/src/components/Settings/Language/Language.component.js index cfe162a20..b0a60a8cd 100644 --- a/src/components/Settings/Language/Language.component.js +++ b/src/components/Settings/Language/Language.component.js @@ -233,6 +233,39 @@ class Language extends React.Component { return null; } + getFormattedName(lang) { + const locale = lang.slice(0, 2).toLowerCase(); + let name = ; + + //handle custom names + if (lang === 'sr-ME') { + name = ; + } + return name; + } + + getNativeName(lang) { + const { langs } = this.props; + const locale = lang.slice(0, 2).toLowerCase(); + const showLangCode = + langs.filter(langCode => langCode.slice(0, 2).toLowerCase() === locale) + .length > 1; + const langCode = showLangCode ? `(${lang})` : ''; + let nativeName = `${ISO6391.getNativeName(locale)} ${langCode}`; + + //handle custom native name + if (lang === 'sr-ME') { + nativeName = 'Crnogorski jezik'; + } else if (lang === 'sr-SP') { + nativeName = `Српски језик ${langCode}`; + } else if (lang === 'sr-RS') { + nativeName = `Srpski jezik ${langCode}`; + } else if (lang === 'pt-TL') { + nativeName = `Tetum`; + } + return nativeName; + } + render() { const { langs, @@ -260,23 +293,6 @@ class Language extends React.Component { const ttsEnginesNames = ttsEngines.map(tts => tts.name); const langItems = langs.map((lang, index, array) => { - const locale = lang.slice(0, 2).toLowerCase(); - const showLangCode = - langs.filter(langCode => langCode.slice(0, 2).toLowerCase() === locale) - .length > 1; - const langCode = showLangCode ? `(${lang})` : ''; - let nativeName = `${ISO6391.getNativeName(locale)} ${langCode}`; - //handle custom native name - if (lang === 'sr-ME') { - nativeName = 'Crnogorski jezik'; - } else if (lang === 'sr-SP') { - nativeName = `Српски језик ${langCode}`; - } else if (lang === 'sr-RS') { - nativeName = `Srpski jezik ${langCode}`; - } else if (lang === 'pt-TL') { - nativeName = `Tetum`; - } - const isLocalLang = localLangs.includes(lang); return ( @@ -291,8 +307,8 @@ class Language extends React.Component { >
} + primary={this.getNativeName(lang)} + secondary={this.getFormattedName(lang)} /> {!isLocalLang && ( @@ -311,7 +327,7 @@ class Language extends React.Component { }); const downloadableLangItems = downloadablesLangsOnly?.map( - ({ lang, langCode, nativeName, marketId, ttsName }, index, array) => { + ({ lang, marketId, ttsName }, index, array) => { const availableTts = ttsEnginesNames.includes(ttsName); const sameTts = ttsEngine && ttsEngine.name === ttsName; return ( @@ -337,8 +353,8 @@ class Language extends React.Component { >
} + primary={this.getNativeName(lang)} + secondary={this.getFormattedName(lang)} className={'Language__LangListItemText'} /> {(!availableTts || sameTts) && ( diff --git a/src/components/Settings/Language/Language.messages.js b/src/components/Settings/Language/Language.messages.js index 1e10529d3..74c1bb3a5 100644 --- a/src/components/Settings/Language/Language.messages.js +++ b/src/components/Settings/Language/Language.messages.js @@ -177,6 +177,10 @@ export default defineMessages({ id: 'cboard.components.Settings.Language.albanian', defaultMessage: 'Albanian' }, + srme: { + id: 'cboard.components.Settings.Language.montenegrin', + defaultMessage: 'Montenegrin' + }, ttsEnginesSubheader: { id: 'cboard.components.Settings.Language.ttsEnginesSubheader', defaultMessage: 'Text to speech engine'