react-native-tts icon indicating copy to clipboard operation
react-native-tts copied to clipboard

How to speak multiple languages in an application?

Open longunibbo opened this issue 6 years ago • 1 comments

My application needs to speak multiple languages. How to effectively implement it? Thank you

longunibbo avatar May 25 '19 13:05 longunibbo

use a locale code Tts.setDefaultLanguage([YOUR_LOCALE]); like Tts.setDefaultLanguage('en-IE');

You can store a locale array and when you want to change locale, you can set it to your state and put it as parameter to above function.

Example.

constructor(props){
    super(props);
    this.state = {
        currentLocale: "en-IE"
    }
}

... When you want to change locale, change currentLocale state to new locale like

this.setState({currentLocale:"YOUR_NEW_LOCALE_CODE"});

use this state object like;

Tts.setDefaultLanguage(this.state.currentLocale);

hakkikonu avatar Jun 26 '19 14:06 hakkikonu