Does not translate to the right language using react native
haowei99 opened this issue · 4 comments
I have a function as below:
store(text, lang){
console.log(lang);
//change language
this.setState({ languageCode: lang });
const translator = TranslatorFactory.createTranslator();
translator.translate('Engineering physics or engineering science').then(translated => {
if(text == 'text'){
this.setState({text: translated})
console.log("text= " + translated);
}
else{
this.setState({text1: translated})
}
});
However, I ussually have to call this the second time for it to translate to the right language. If the lang is currently to French. And I pass it store("Hello", "ru") it returns a translation of french instead of russian. I have to call it the second time.
@haowei99 Thanks for reporting this issue. I'll try to look into this as soon as possible!!
I found out why. Because when it's fetching the config it's still using the current config. I have to manually change the configure to get the language I want. I wrote a wrapper for this function that can translate to a specific language. I can create a pull request :)
@haowei99 sure, that would be nice. Looking forward to it!
I created the pull request. It is a minor change, but this should help make the function easier to use. (it took some time trying to figure out the problem, so I think this fix will make things simpler).
Hope this helps!