Skip to content

Commit

Permalink
Merge pull request #716 from cboard-org/feature/serbian-cyrilic
Browse files Browse the repository at this point in the history
Include Cyrillic script into Cboard using existing Alfanum Serbian voices
  • Loading branch information
martinbedouret authored Jun 19, 2020
2 parents 30e4edb + d46813d commit 9f5a9d1
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 87 deletions.
15 changes: 10 additions & 5 deletions src/components/Settings/Language/Language.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ const Language = ({
.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}`;
}

return (
<ListItem
Expand All @@ -62,11 +71,7 @@ const Language = ({
key={index}
>
<ListItemText
primary={
lang !== 'sr-ME'
? `${ISO6391.getNativeName(locale)} ${langCode}`
: `Crnogorski jezik`
}
primary={nativeName}
secondary={<FormattedMessage {...messages[locale]} />}
/>
{selectedLang === lang && <CheckIcon />}
Expand Down
3 changes: 3 additions & 0 deletions src/components/Settings/Settings.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class SettingsContainer extends Component {
const sLanguages = getVoicesLangs(voices);
if (sLanguages !== undefined && sLanguages.length) {
supportedLangs = sLanguages;
if(supportedLangs.includes('sr-RS')){
supportedLangs.push('sr-SP');
}
}
}
setLangs(supportedLangs);
Expand Down
8 changes: 6 additions & 2 deletions src/providers/SpeechProvider/SpeechProvider.container.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,19 @@ export class SpeechProvider extends Component {
setLangs,
changeLang,
voiceURI,
changeVoice
changeVoice,
getVoices
} = this.props;
if (tts.isSupported()) {
const voices = await this.props.getVoices();
const voices = await getVoices();
let supportedLangs = [DEFAULT_LANG];
if (voices.length) {
const sLanguages = getVoicesLangs(voices);
if (sLanguages !== undefined && sLanguages.length) {
supportedLangs = sLanguages;
if (supportedLangs.includes('sr-RS')) {
supportedLangs.push('sr-SP');
}
}
}
const lang = supportedLangs.includes(propsLang)
Expand Down
36 changes: 27 additions & 9 deletions src/providers/SpeechProvider/SpeechProvider.reducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,14 @@ function speechProviderReducer(state = initialState, action) {
options
};
case RECEIVE_VOICES:
const langs = [...new Set(action.voices.map(voice => voice.lang))];
if (langs.includes('sr-RS')) {
langs.push('sr-SP');
}
return {
...state,
voices: action.voices,
langs: [...new Set(action.voices.map(voice => voice.lang))].sort()
langs: langs.sort()
};
case CHANGE_VOICE:
return {
Expand All @@ -57,14 +61,28 @@ function speechProviderReducer(state = initialState, action) {
}
};
case CHANGE_LANG:
return {
...state,
options: {
...state.options,
lang: action.lang,
voiceURI: getVoiceURI(action.lang, state.voices)
}
};
// hack just for alfanum voice
if (action.lang === 'sr-SP' || action.lang === 'sr-RS') {
const language = 'sr-RS';
return {
...state,
options: {
...state.options,
lang: language,
voiceURI: getVoiceURI(language, state.voices)
},
langs: ['sr-SP', 'sr-RS']
};
} else {
return {
...state,
options: {
...state.options,
lang: action.lang,
voiceURI: getVoiceURI(action.lang, state.voices)
}
};
}
case CHANGE_PITCH:
return { ...state, options: { ...state.options, pitch: action.pitch } };
case CHANGE_RATE:
Expand Down
Loading

0 comments on commit 9f5a9d1

Please sign in to comment.