UNPKG

1.53 kBJavaScriptView Raw
1import * as rtlDetect from 'rtl-detect';
2export default {
3 get isRTL() {
4 return rtlDetect.isRtlLang(this.locale);
5 },
6 get locale() {
7 const locale = navigator.language ||
8 navigator['systemLanguage'] ||
9 navigator['browserLanguage'] ||
10 navigator['userLanguage'] ||
11 this.locales[0];
12 // The native format is en-US
13 return locale.replace('_', '-');
14 },
15 get locales() {
16 const { languages = [] } = navigator;
17 return Array.from(languages);
18 },
19 get timezone() {
20 const defaultTimeZone = 'Etc/UTC';
21 if (typeof Intl === 'undefined') {
22 return defaultTimeZone;
23 }
24 return Intl.DateTimeFormat().resolvedOptions().timeZone || defaultTimeZone;
25 },
26 get isoCurrencyCodes() {
27 // TODO: Bacon: Add this - very low priority
28 return [];
29 },
30 get country() {
31 const { locale } = this;
32 if (typeof locale === 'string' && locale.length) {
33 const isoCountryCode = locale.substring(locale.lastIndexOf('-') + 1);
34 return isoCountryCode.toUpperCase();
35 }
36 return undefined;
37 },
38 async getLocalizationAsync() {
39 const { country, isoCurrencyCodes, timezone, locales, locale, isRTL } = this;
40 return {
41 country,
42 isoCurrencyCodes,
43 timezone,
44 locales,
45 locale,
46 isRTL,
47 };
48 },
49};
50//# sourceMappingURL=ExpoLocalization.web.js.map
\No newline at end of file