How can I set a default language when missing translation?
Example:
I18n.translations = {
en: {
choose: 'Choose'
},
es: {
choose: 'seleccionar!'
}
}
If I run this code on device with pt-BR language, It will cause an error saying that the language is missing pt-BR
You can apply some configuration before I18n is loaded:
I18n.defaultLocale = 'pt-BR'
More infos here https://github.com/fnando/i18n-js#setting-up
thanks dude =)
Hi, I'm having some problem configuration with this plugin...
My device is on English, and I would like that Spanish Language was the default language, if for example, an Italian Device install the app the language default must be Spanish. But my device is ignoring my language device (en output of I18n.currentLocale() function)
This is my current configuration and code:
// Import
import I18n from 'react-native-i18n';
.. stuff code ...
// Configuration I18n
I18n.defaultLocale = 'es-ES';
I18n.fallbacks = true;
I18n.translations = {
en: {
greeting: 'Hi!'
},
es: {
greeting: 'Hola!'
}
};
.. stuff code ...
// Component Class and StyleSheet code...
export default class MyScreen extends Component {
render() {
return (
<View>
<Text style={styles.signupLinkText}>{I18n.t('greeting')}</Text>
</View>
)
}
}
Output desired:
Italian Device -> locale (it) -> greeting message -> Hola!
Spanish Device -> locale (es) -> greeting message -> Hola!
USA Device -> locale (en-US) -> greeting message -> Hi!
UK Device -> locale (en-UK) -> greeting message -> Hi!
Thank you so much!! Excellent work!!
Hi, I solved adding this to my configuration:
I18n.locale = I18n.currentLocale();
I think that this is a bug, check this: https://github.com/AlexanderZaytsev/react-native-i18n/issues/43
But we can not get the devices default locale. It always returns 'en'
@isener Ok, you are right... always return 'en', I don't know why in one moment, it was returning other language, sorry for the mistake...
@chemitaxis mate I couldn't resolved why it happened. If I would, also notice to you. Thanks
I will try to help in solve the problem ;)
On Mon, 20 Mar 2017 at 19:43, Ismail Sener notifications@github.com wrote:
@chemitaxis https://github.com/chemitaxis mate I couldn't resolved why
it happened. If I would, also notice to you. Thanks—
You are receiving this because you were mentioned.Reply to this email directly, view it on GitHub
https://github.com/AlexanderZaytsev/react-native-i18n/issues/53#issuecomment-287858564,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABWseRDNQacZEUfkDaxtiVS3BMo-WbUeks5rnsiygaJpZM4LiLea
.
Somebody solved it?
This is dont work:
I18n.defaultLocale = 'pt-BR'
When my app doesn't have the translations, I put I18n.locale = 'pt-BR'; rather than I18n.defaultLocale = 'pt-BR' and works.
Most helpful comment
You can apply some configuration before I18n is loaded:
More infos here https://github.com/fnando/i18n-js#setting-up