jiti-meet/react/features/base/i18n/languageDetector.native.js

37 lines
782 B
JavaScript
Raw Normal View History

// @flow
2017-03-01 02:55:12 +00:00
import { NativeModules } from 'react-native';
2017-03-01 02:55:12 +00:00
import LANGUAGES_RESOURCES from '../../../../lang/languages.json';
const LANGUAGES = Object.keys(LANGUAGES_RESOURCES);
2017-03-01 02:55:12 +00:00
/**
* The singleton language detector for React Native which uses the system-wide
* locale.
*/
export default {
/**
* Does not support caching.
*
* @returns {void}
*/
cacheUserLanguage: Function.prototype,
detect() {
const { LocaleDetector } = NativeModules;
const [ lang, region ] = LocaleDetector.locale.replace(/_/, '-').split('-');
const locale = `${lang}${region}`;
if (LANGUAGES.includes(locale)) {
return locale;
}
return lang;
2017-03-01 02:55:12 +00:00
},
init: Function.prototype,
type: 'languageDetector'
};