-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi18n.js
More file actions
51 lines (46 loc) · 1.21 KB
/
Copy pathi18n.js
File metadata and controls
51 lines (46 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import i18n from 'i18next';
import ChainedBackend from 'i18next-chained-backend';
import resourcesToBackend from 'i18next-resources-to-backend';
import { initReactI18next } from 'react-i18next';
import Phrase from 'react-native-phrase-sdk';
import translationEN from './locales/en/translation.json';
import translationRU from './locales/ru/translation.json';
const localResources = {
en: {
translation: translationEN,
},
ru: {
translation: translationRU,
},
};
let phrase = new Phrase(
'YOUR_DISTRIBUTION_ID',
'YOUR_ENVIRONMENT_ID',
require('./package.json').version,
'i18next',
);
const backendPhrase = resourcesToBackend((language, namespace, callback) => {
phrase
.requestTranslation(language)
.then((remoteResources) => {
callback(null, remoteResources);
})
.catch((error) => {
callback(error, null);
});
});
const backendFallback = resourcesToBackend(localResources);
i18n
.use(ChainedBackend)
.use(initReactI18next)
.init({
backend: {
backends: [backendPhrase, backendFallback],
},
debug: true,
lng: 'en',
fallbackLng: 'en',
interpolation: {
escapeValue: false, // not needed for react as it escapes by default
},
});