UNPKG

1.46 kBJavaScriptView Raw
1/* global tizen */
2import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
3import * as R from "ramda";
4import { QuickBrickCommunicationModule } from "../../Polyfills/QuickBrickCommunicationModule";
5
6type Locale = {
7 language: string,
8 country: string,
9};
10
11/**
12 * Supported platforms: [Samsung] TODO: LG
13 * This function is adding languageLocale and countryLocale to the QuickBrickCommunicationModule
14 * @return Promise
15 * Warning! This function mutates QuickBrickCommunicationModule
16 */
17export function loadLocale() {
18 const getDefault = () => Promise.resolve();
19 const getSamsungLocale = () =>
20 new Promise((resolve, reject) => {
21 if (typeof tizen === "undefined") resolve();
22 try {
23 tizen.systeminfo.getPropertyValue(
24 "LOCALE",
25 (locale: Locale) => {
26 const { language } = locale;
27 const [languageLocale, countryLocale] = R.compose(
28 R.map(R.toLower),
29 R.split("_")
30 )(language);
31
32 QuickBrickCommunicationModule.languageLocale = languageLocale;
33 QuickBrickCommunicationModule.countryLocale = countryLocale;
34 resolve();
35 },
36 err => {
37 reject(new Error(err));
38 }
39 );
40 } catch (err) {
41 reject(new Error(err));
42 }
43 });
44
45 return platformSelect({
46 samsung_tv: getSamsungLocale,
47 lg_tv: getDefault,
48 default: getDefault,
49 })();
50}