Add basic example

This commit is contained in:
Mathieu Acthernoene 2017-05-25 17:49:37 +02:00
parent de7bcfef94
commit a867e8ca40
6 changed files with 37 additions and 15 deletions

View File

@ -1,9 +1,7 @@
// @ flow
import React, { Component } from 'react';
// import { languages, getLanguages } from 'react-native-i18n';
import { NativeModules } from 'react-native';
const { getLanguages, languages } = NativeModules.RNI18n;
import I18n, { getLanguages } from 'react-native-i18n';
import {
Platform,
@ -13,6 +11,20 @@ import {
View,
} from 'react-native';
// Enable fallbacks if you want `en-US`
// and `en-GB` to fallback to `en`
I18n.fallbacks = true;
// Available languages
I18n.translations = {
'en': require('./translations/en'),
'fr': require('./translations/fr'),
'fr-CA': require('./translations/fr-CA'),
'es': require('./translations/es'),
};
console.log(I18n.locales)
export default class extends Component {
state = { languages: [] }
@ -25,19 +37,19 @@ export default class extends Component {
render() {
return (
<ScrollView style={styles.container}>
<Text style={styles.title}>Internal constants</Text>
<View style={styles.line}>
<Text style={styles.label}>languages: </Text>
<Text>{JSON.stringify(languages)}</Text>
</View>
<Text style={styles.title}>Internal methods</Text>
<Text style={styles.title}>Additional methods</Text>
<View style={styles.line}>
<Text style={styles.label}>getLanguages (Promise): </Text>
<Text>{JSON.stringify(this.state.languages)}</Text>
</View>
<Text style={styles.title}>Demos</Text>
<View style={styles.line}>
<Text style={styles.label}>I18n.t('hello world'): </Text>
<Text>{I18n.t('hello world')}</Text>
</View>
</ScrollView>
);
}

View File

@ -0,0 +1,3 @@
{
"hello world": "hello world"
}

View File

@ -0,0 +1,3 @@
{
"hello world": "hola mundo"
}

View File

@ -0,0 +1,3 @@
{
"hello world": "allo le monde"
}

View File

@ -0,0 +1,3 @@
{
"hello world": "bonjour le monde"
}

View File

@ -4,9 +4,7 @@ import { NativeModules } from 'react-native';
import I18n from 'i18n-js';
const { RNI18n } = NativeModules;
// I18n.locale = RNI18n.language;
// export const getLanguages = RNI18n.getLanguages;
// export const languages = RNI18n.languages;
I18n.locale = RNI18n.languages[0];
export const getLanguages = RNI18n.getLanguages;
export default I18n;