2018-05-28 21:18:11 +02:00
|
|
|
import LocalizedStrings from 'react-localization';
|
|
|
|
import { AsyncStorage } from 'react-native';
|
|
|
|
import { Util } from 'expo';
|
|
|
|
import { AppStorage } from '../class';
|
|
|
|
let strings;
|
|
|
|
|
|
|
|
// first-time loading sequence
|
|
|
|
(async () => {
|
|
|
|
// finding out whether lang preference was saved
|
|
|
|
let lang = await AsyncStorage.getItem(AppStorage.LANG);
|
|
|
|
if (lang) {
|
|
|
|
strings.setLanguage(lang);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: rewrite this when Expo version is upped
|
|
|
|
if (Util.getCurrentLocaleAsync) {
|
|
|
|
let locale = await Util.getCurrentLocaleAsync();
|
|
|
|
if (locale) {
|
|
|
|
locale = locale.split('-');
|
|
|
|
locale = locale[0];
|
|
|
|
console.log('current locale:', locale);
|
2018-05-31 20:43:56 +02:00
|
|
|
if (
|
|
|
|
locale === 'en' ||
|
|
|
|
locale === 'ru' ||
|
2018-06-02 14:18:50 +02:00
|
|
|
locale === 'ua' ||
|
2018-05-31 20:43:56 +02:00
|
|
|
locale === 'es' ||
|
|
|
|
locale === 'pt'
|
|
|
|
) {
|
2018-05-31 20:38:20 +02:00
|
|
|
strings.setLanguage(locale);
|
2018-05-31 20:43:56 +02:00
|
|
|
} else {
|
|
|
|
strings.setLanguage('en');
|
2018-05-28 21:18:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})();
|
|
|
|
|
|
|
|
strings = new LocalizedStrings({
|
|
|
|
en: require('./en.js'),
|
|
|
|
ru: require('./ru.js'),
|
2018-05-31 20:38:20 +02:00
|
|
|
pt: require('./pt_BR.js'),
|
|
|
|
es: require('./es.js'),
|
2018-06-02 14:18:50 +02:00
|
|
|
ua: require('./ua.js'),
|
2018-05-28 21:18:11 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
strings.saveLanguage = lang => AsyncStorage.setItem(AppStorage.LANG, lang);
|
|
|
|
|
|
|
|
module.exports = strings;
|