Skip to content

Commit

Permalink
Merge branch 'master' into feature/download-cboardSER
Browse files Browse the repository at this point in the history
  • Loading branch information
tomivm committed Apr 20, 2022
2 parents 00b9897 + f33f31c commit c91d197
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 22 deletions.
60 changes: 38 additions & 22 deletions src/components/Settings/Language/Language.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,39 @@ class Language extends React.Component {
return null;
}

getFormattedName(lang) {
const locale = lang.slice(0, 2).toLowerCase();
let name = <FormattedMessage {...messages[locale]} />;

//handle custom names
if (lang === 'sr-ME') {
name = <FormattedMessage {...messages['srme']} />;
}
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,
Expand Down Expand Up @@ -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 (
Expand All @@ -291,8 +307,8 @@ class Language extends React.Component {
>
<div className="Language__LangMenuItemText">
<ListItemText
primary={nativeName}
secondary={<FormattedMessage {...messages[locale]} />}
primary={this.getNativeName(lang)}
secondary={this.getFormattedName(lang)}
/>
{!isLocalLang && (
<Chip label="online" size="small" color="secondary" />
Expand All @@ -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 (
Expand All @@ -337,8 +353,8 @@ class Language extends React.Component {
>
<div className="Language__LangMenuItemText">
<ListItemText
primary={nativeName ? nativeName : lang}
secondary={<FormattedMessage {...messages[langCode]} />}
primary={this.getNativeName(lang)}
secondary={this.getFormattedName(lang)}
className={'Language__LangListItemText'}
/>
{(!availableTts || sameTts) && (
Expand Down
4 changes: 4 additions & 0 deletions src/components/Settings/Language/Language.messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit c91d197

Please sign in to comment.