mirror of
https://github.com/status-im/react-native-i18n.git
synced 2025-02-13 04:26:47 +00:00
Add basic example
This commit is contained in:
parent
de7bcfef94
commit
a867e8ca40
@ -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>
|
||||
);
|
||||
}
|
||||
|
3
example/translations/en.json
Normal file
3
example/translations/en.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"hello world": "hello world"
|
||||
}
|
3
example/translations/es.json
Normal file
3
example/translations/es.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"hello world": "hola mundo"
|
||||
}
|
3
example/translations/fr-CA.json
Normal file
3
example/translations/fr-CA.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"hello world": "allo le monde"
|
||||
}
|
3
example/translations/fr.json
Normal file
3
example/translations/fr.json
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"hello world": "bonjour le monde"
|
||||
}
|
6
index.js
6
index.js
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user