gt-react-native 11.0.0-odysseus.4 → 11.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/commonjs/NativeGtReactNative.js +3 -6
- package/dist/commonjs/NativeGtReactNative.js.map +1 -1
- package/dist/commonjs/condition-store/NativeConditionStore.js +19 -27
- package/dist/commonjs/condition-store/NativeConditionStore.js.map +1 -1
- package/dist/commonjs/hooks/selectors.js.map +1 -1
- package/dist/commonjs/index.js +35 -10
- package/dist/commonjs/plugin-dir/index.js +3 -6
- package/dist/commonjs/plugin-dir/index.js.map +1 -1
- package/dist/commonjs/plugin.js +2 -5
- package/dist/commonjs/provider/GTProvider.js +32 -21
- package/dist/commonjs/provider/GTProvider.js.map +1 -1
- package/dist/commonjs/provider/NativeGTProvider.js +1 -4
- package/dist/commonjs/provider/NativeGTProvider.js.map +1 -1
- package/dist/commonjs/setup/initializeGT.js +6 -11
- package/dist/commonjs/utils/getInitialNativeConditions.js +2 -2
- package/dist/commonjs/utils/getInitialNativeConditions.js.map +1 -1
- package/dist/commonjs/utils/getLocale.js +1 -1
- package/dist/commonjs/utils/getLocale.js.map +1 -1
- package/dist/commonjs/utils/getNativeLocales.js +1 -1
- package/dist/commonjs/utils/getNativeLocales.js.map +1 -1
- package/dist/commonjs/utils/nativeStore.js +4 -4
- package/dist/commonjs/utils/nativeStore.js.map +1 -1
- package/dist/commonjs/utils/resolveLocale.js +1 -2
- package/dist/commonjs/utils/resolveLocale.js.map +1 -1
- package/dist/module/NativeGtReactNative.d.ts +1 -2
- package/dist/module/NativeGtReactNative.d.ts.map +1 -1
- package/dist/module/NativeGtReactNative.js +2 -2
- package/dist/module/NativeGtReactNative.js.map +1 -1
- package/dist/module/condition-store/NativeConditionStore.d.ts +0 -7
- package/dist/module/condition-store/NativeConditionStore.d.ts.map +1 -1
- package/dist/module/condition-store/NativeConditionStore.js +20 -28
- package/dist/module/condition-store/NativeConditionStore.js.map +1 -1
- package/dist/module/hooks/selectors.d.ts +3 -33
- package/dist/module/hooks/selectors.d.ts.map +1 -1
- package/dist/module/hooks/selectors.js.map +1 -1
- package/dist/module/index.d.ts +13 -18
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +3 -4
- package/dist/module/plugin-dir/index.d.ts +1 -1
- package/dist/module/plugin-dir/index.d.ts.map +1 -1
- package/dist/module/plugin-dir/index.js +2 -2
- package/dist/module/plugin-dir/index.js.map +1 -1
- package/dist/module/plugin.d.ts +1 -1
- package/dist/module/plugin.d.ts.map +1 -1
- package/dist/module/plugin.js +2 -2
- package/dist/module/provider/GTProvider.d.ts +1 -1
- package/dist/module/provider/GTProvider.d.ts.map +1 -1
- package/dist/module/provider/GTProvider.js +32 -21
- package/dist/module/provider/GTProvider.js.map +1 -1
- package/dist/module/provider/NativeGTProvider.d.ts.map +1 -1
- package/dist/module/provider/NativeGTProvider.js +1 -4
- package/dist/module/provider/NativeGTProvider.js.map +1 -1
- package/dist/module/setup/initializeGT.d.ts +3 -4
- package/dist/module/setup/initializeGT.d.ts.map +1 -1
- package/dist/module/setup/initializeGT.js +1 -11
- package/dist/module/utils/getInitialNativeConditions.d.ts.map +1 -1
- package/dist/module/utils/getInitialNativeConditions.js +3 -3
- package/dist/module/utils/getInitialNativeConditions.js.map +1 -1
- package/dist/module/utils/getLocale.d.ts.map +1 -1
- package/dist/module/utils/getLocale.js +2 -2
- package/dist/module/utils/getLocale.js.map +1 -1
- package/dist/module/utils/getNativeLocales.js +2 -2
- package/dist/module/utils/getNativeLocales.js.map +1 -1
- package/dist/module/utils/nativeStore.d.ts +1 -1
- package/dist/module/utils/nativeStore.d.ts.map +1 -1
- package/dist/module/utils/nativeStore.js +6 -6
- package/dist/module/utils/nativeStore.js.map +1 -1
- package/dist/module/utils/resolveLocale.d.ts.map +1 -1
- package/dist/module/utils/resolveLocale.js +1 -2
- package/dist/module/utils/resolveLocale.js.map +1 -1
- package/package.json +6 -6
- package/src/NativeGtReactNative.ts +2 -1
- package/src/condition-store/NativeConditionStore.ts +21 -40
- package/src/hooks/selectors.ts +17 -3
- package/src/index.tsx +39 -67
- package/src/plugin-dir/index.ts +1 -1
- package/src/plugin.ts +1 -1
- package/src/provider/GTProvider.tsx +51 -29
- package/src/provider/NativeGTProvider.tsx +1 -9
- package/src/setup/initializeGT.ts +7 -19
- package/src/utils/getInitialNativeConditions.ts +3 -6
- package/src/utils/getLocale.ts +2 -2
- package/src/utils/getNativeLocales.ts +1 -1
- package/src/utils/nativeStore.ts +4 -4
- package/src/utils/resolveLocale.ts +1 -5
- package/dist/commonjs/hooks/utils.js +0 -17
- package/dist/commonjs/hooks/utils.js.map +0 -1
- package/dist/commonjs/setup/initializeGT.js.map +0 -1
- package/dist/commonjs/utils/utils.js +0 -13
- package/dist/commonjs/utils/utils.js.map +0 -1
- package/dist/module/hooks/utils.d.ts +0 -3
- package/dist/module/hooks/utils.d.ts.map +0 -1
- package/dist/module/hooks/utils.js +0 -14
- package/dist/module/hooks/utils.js.map +0 -1
- package/dist/module/setup/initializeGT.js.map +0 -1
- package/dist/module/utils/utils.d.ts +0 -3
- package/dist/module/utils/utils.d.ts.map +0 -1
- package/dist/module/utils/utils.js +0 -12
- package/dist/module/utils/utils.js.map +0 -1
- package/src/hooks/utils.ts +0 -14
- package/src/utils/utils.ts +0 -12
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { nativeStoreGet } from "./nativeStore.js";
|
|
2
|
-
import {
|
|
2
|
+
import { getI18nConfig } from "@generaltranslation/react-core/pure";
|
|
3
3
|
//#region src/utils/getInitialNativeConditions.ts
|
|
4
|
-
function getInitialRegion({ region, regionStoreKey =
|
|
4
|
+
function getInitialRegion({ region, regionStoreKey = getI18nConfig().getRegionCookieName() }) {
|
|
5
5
|
if (region !== void 0) return region;
|
|
6
6
|
return nativeStoreGet(regionStoreKey) || void 0;
|
|
7
7
|
}
|
|
8
|
-
function getInitialEnableI18n({ enableI18n, enableI18nStoreKey =
|
|
8
|
+
function getInitialEnableI18n({ enableI18n, enableI18nStoreKey = getI18nConfig().getEnableI18nCookieName() }) {
|
|
9
9
|
if (enableI18n !== void 0) return enableI18n;
|
|
10
10
|
const storedEnableI18n = nativeStoreGet(enableI18nStoreKey);
|
|
11
11
|
if (storedEnableI18n === null) return true;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInitialNativeConditions.js","names":[
|
|
1
|
+
{"version":3,"file":"getInitialNativeConditions.js","names":[],"sources":["../../../src/utils/getInitialNativeConditions.ts"],"sourcesContent":["import type { WritableConditionStoreParams } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { nativeStoreGet } from './nativeStore';\n\ntype InitialRegionParams = Pick<WritableConditionStoreParams, 'region'> & {\n regionStoreKey?: string;\n};\n\ntype InitialEnableI18nParams = Pick<\n WritableConditionStoreParams,\n 'enableI18n'\n> & {\n enableI18nStoreKey?: string;\n};\n\nexport function getInitialRegion({\n region,\n regionStoreKey = getI18nConfig().getRegionCookieName(),\n}: InitialRegionParams): string | undefined {\n if (region !== undefined) return region;\n return nativeStoreGet(regionStoreKey) || undefined;\n}\n\nexport function getInitialEnableI18n({\n enableI18n,\n enableI18nStoreKey = getI18nConfig().getEnableI18nCookieName(),\n}: InitialEnableI18nParams): boolean {\n if (enableI18n !== undefined) return enableI18n;\n const storedEnableI18n = nativeStoreGet(enableI18nStoreKey);\n if (storedEnableI18n === null) return true;\n return storedEnableI18n === 'true';\n}\n"],"mappings":";;;AAeA,SAAgB,iBAAiB,EAC/B,QACA,iBAAiB,eAAe,CAAC,qBAAqB,IACZ;AAC1C,KAAI,WAAW,KAAA,EAAW,QAAO;AACjC,QAAO,eAAe,eAAe,IAAI,KAAA;;AAG3C,SAAgB,qBAAqB,EACnC,YACA,qBAAqB,eAAe,CAAC,yBAAyB,IAC3B;AACnC,KAAI,eAAe,KAAA,EAAW,QAAO;CACrC,MAAM,mBAAmB,eAAe,mBAAmB;AAC3D,KAAI,qBAAqB,KAAM,QAAO;AACtC,QAAO,qBAAqB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.d.ts","sourceRoot":"","sources":["../../../src/utils/getLocale.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,EACxB,
|
|
1
|
+
{"version":3,"file":"getLocale.d.ts","sourceRoot":"","sources":["../../../src/utils/getLocale.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,EACxB,cAAsD,GACvD,GAAE,eAAoB,GAAG,MAAM,CAM/B"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { getNativeLocales } from "./getNativeLocales.js";
|
|
2
2
|
import { nativeStoreGet } from "./nativeStore.js";
|
|
3
3
|
import { resolveLocale } from "./resolveLocale.js";
|
|
4
|
-
import {
|
|
4
|
+
import { getI18nConfig } from "@generaltranslation/react-core/pure";
|
|
5
5
|
//#region src/utils/getLocale.ts
|
|
6
6
|
/**
|
|
7
7
|
* @internal
|
|
8
8
|
*/
|
|
9
|
-
function getLocale({ localeStoreKey =
|
|
9
|
+
function getLocale({ localeStoreKey = getI18nConfig().getLocaleCookieName() } = {}) {
|
|
10
10
|
const candidates = [];
|
|
11
11
|
pushLocaleCandidates(candidates, nativeStoreGet(localeStoreKey));
|
|
12
12
|
candidates.push(...getNativeLocales());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getLocale.js","names":[
|
|
1
|
+
{"version":3,"file":"getLocale.js","names":[],"sources":["../../../src/utils/getLocale.ts"],"sourcesContent":["import type { LocaleCandidates } from 'gt-i18n/internal/types';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { getNativeLocales } from './getNativeLocales';\nimport { nativeStoreGet } from './nativeStore';\nimport { resolveLocale } from './resolveLocale';\n\nexport type GetLocaleParams = {\n localeStoreKey?: string;\n};\n\n/**\n * @internal\n */\nexport function getLocale({\n localeStoreKey = getI18nConfig().getLocaleCookieName(),\n}: GetLocaleParams = {}): string {\n const candidates: string[] = [];\n pushLocaleCandidates(candidates, nativeStoreGet(localeStoreKey));\n candidates.push(...getNativeLocales());\n\n return resolveLocale(candidates);\n}\n\nfunction pushLocaleCandidates(\n target: string[],\n locale: LocaleCandidates | null\n) {\n if (!locale) return;\n if (Array.isArray(locale)) {\n target.push(...locale);\n return;\n }\n target.push(locale);\n}\n"],"mappings":";;;;;;;;AAaA,SAAgB,UAAU,EACxB,iBAAiB,eAAe,CAAC,qBAAqB,KACnC,EAAE,EAAU;CAC/B,MAAM,aAAuB,EAAE;AAC/B,sBAAqB,YAAY,eAAe,eAAe,CAAC;AAChE,YAAW,KAAK,GAAG,kBAAkB,CAAC;AAEtC,QAAO,cAAc,WAAW;;AAGlC,SAAS,qBACP,QACA,QACA;AACA,KAAI,CAAC,OAAQ;AACb,KAAI,MAAM,QAAQ,OAAO,EAAE;AACzB,SAAO,KAAK,GAAG,OAAO;AACtB;;AAEF,QAAO,KAAK,OAAO"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { GtReactNative } from "../NativeGtReactNative.js";
|
|
2
2
|
import { Platform } from "react-native";
|
|
3
3
|
//#region src/utils/getNativeLocales.ts
|
|
4
4
|
/**
|
|
@@ -12,7 +12,7 @@ import { Platform } from "react-native";
|
|
|
12
12
|
function getNativeLocales() {
|
|
13
13
|
try {
|
|
14
14
|
if (Platform.OS === "web") return getWebLocales();
|
|
15
|
-
return
|
|
15
|
+
return GtReactNative.getNativeLocales() || [];
|
|
16
16
|
} catch {
|
|
17
17
|
return [];
|
|
18
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNativeLocales.js","names":[
|
|
1
|
+
{"version":3,"file":"getNativeLocales.js","names":[],"sources":["../../../src/utils/getNativeLocales.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { GtReactNative } from '../NativeGtReactNative';\n\n/**\n * Get native device locales in preference order\n * Returns an empty array if detection fails or is not supported\n *\n * iOS: Returns current locale first, followed by preferred languages\n * Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)\n * Web: Returns browser language preferences from navigator\n */\nexport function getNativeLocales(): string[] {\n try {\n // Web platform - use browser locale detection\n if (Platform.OS === 'web') {\n return getWebLocales();\n }\n\n // Try to get locales from native module\n return GtReactNative.getNativeLocales() || [];\n } catch {\n // Return empty array on any error (native module not available, etc.)\n return [];\n }\n}\n\n/**\n * Get browser locales for web platform\n */\nfunction getWebLocales(): string[] {\n try {\n if (typeof navigator === 'undefined') {\n return [];\n }\n\n const locales: string[] = [];\n\n // Use navigator.languages if available (most browsers)\n if (navigator.languages && Array.isArray(navigator.languages)) {\n locales.push(...navigator.languages);\n } else if (navigator.language) {\n // Fallback to single language\n locales.push(navigator.language);\n } else {\n // IE fallback\n const legacyNavigator = navigator as Navigator & {\n userLanguage?: string;\n };\n if (legacyNavigator.userLanguage) {\n locales.push(legacyNavigator.userLanguage);\n }\n }\n\n return locales;\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,mBAA6B;AAC3C,KAAI;AAEF,MAAI,SAAS,OAAO,MAClB,QAAO,eAAe;AAIxB,SAAO,cAAc,kBAAkB,IAAI,EAAE;SACvC;AAEN,SAAO,EAAE;;;;;;AAOb,SAAS,gBAA0B;AACjC,KAAI;AACF,MAAI,OAAO,cAAc,YACvB,QAAO,EAAE;EAGX,MAAM,UAAoB,EAAE;AAG5B,MAAI,UAAU,aAAa,MAAM,QAAQ,UAAU,UAAU,CAC3D,SAAQ,KAAK,GAAG,UAAU,UAAU;WAC3B,UAAU,SAEnB,SAAQ,KAAK,UAAU,SAAS;OAC3B;GAEL,MAAM,kBAAkB;AAGxB,OAAI,gBAAgB,aAClB,SAAQ,KAAK,gBAAgB,aAAa;;AAI9C,SAAO;SACD;AACN,SAAO,EAAE"}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This reads persisted native storage directly, so it can temporarily be out of
|
|
5
5
|
* sync with React state while a locale change is in progress.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
7
|
+
* Defaults to the store key configured through initializeGT().
|
|
8
8
|
*
|
|
9
9
|
* @param key - The key to get the locale from
|
|
10
10
|
* @returns The locale from the native store
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/nativeStore.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,
|
|
1
|
+
{"version":3,"file":"nativeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/nativeStore.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,SAAwC,GAC1C,MAAM,GAAG,IAAI,CAEf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW/D"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { GtReactNative } from "../NativeGtReactNative.js";
|
|
2
2
|
import { ssrUnsupportedWarning } from "../errors-dir/warnings.js";
|
|
3
3
|
import { Platform } from "react-native";
|
|
4
|
-
import {
|
|
4
|
+
import { getI18nConfig } from "@generaltranslation/react-core/pure";
|
|
5
5
|
//#region src/utils/nativeStore.ts
|
|
6
6
|
/**
|
|
7
7
|
* Get the locale from the native store.
|
|
@@ -9,12 +9,12 @@ import { defaultLocaleCookieName } from "@generaltranslation/react-core/pure";
|
|
|
9
9
|
* This reads persisted native storage directly, so it can temporarily be out of
|
|
10
10
|
* sync with React state while a locale change is in progress.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* Defaults to the store key configured through initializeGT().
|
|
13
13
|
*
|
|
14
14
|
* @param key - The key to get the locale from
|
|
15
15
|
* @returns The locale from the native store
|
|
16
16
|
*/
|
|
17
|
-
function getLocaleFromNativeStore(key =
|
|
17
|
+
function getLocaleFromNativeStore(key = getI18nConfig().getLocaleCookieName()) {
|
|
18
18
|
return nativeStoreGet(key);
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
@@ -30,7 +30,7 @@ function nativeStoreGet(key) {
|
|
|
30
30
|
}
|
|
31
31
|
return localStorage.getItem(key);
|
|
32
32
|
}
|
|
33
|
-
return
|
|
33
|
+
return GtReactNative.nativeStoreGet(key);
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Set a value in the native store
|
|
@@ -46,7 +46,7 @@ function nativeStoreSet(key, value) {
|
|
|
46
46
|
localStorage.setItem(key, value);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
|
|
49
|
+
GtReactNative.nativeStoreSet(key, value);
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
export { getLocaleFromNativeStore, nativeStoreGet, nativeStoreSet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeStore.js","names":[
|
|
1
|
+
{"version":3,"file":"nativeStore.js","names":[],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { GtReactNative } from '../NativeGtReactNative';\nimport { ssrUnsupportedWarning } from '../errors-dir/warnings';\n\n/**\n * Get the locale from the native store.\n *\n * This reads persisted native storage directly, so it can temporarily be out of\n * sync with React state while a locale change is in progress.\n *\n * Defaults to the store key configured through initializeGT().\n *\n * @param key - The key to get the locale from\n * @returns The locale from the native store\n */\nexport function getLocaleFromNativeStore(\n key = getI18nConfig().getLocaleCookieName()\n): string | null {\n return nativeStoreGet(key);\n}\n\n/**\n * Get a value from the native store\n * @param key - The key to get the value for\n * @returns The value for the key\n */\nexport function nativeStoreGet(key: string): string | null {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return null;\n }\n return localStorage.getItem(key);\n }\n return GtReactNative.nativeStoreGet(key);\n}\n\n/**\n * Set a value in the native store\n * @param key - The key to set the value for\n * @param value - The value to set\n */\nexport function nativeStoreSet(key: string, value: string): void {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return;\n }\n localStorage.setItem(key, value);\n return;\n }\n GtReactNative.nativeStoreSet(key, value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,yBACd,MAAM,eAAe,CAAC,qBAAqB,EAC5B;AACf,QAAO,eAAe,IAAI;;;;;;;AAQ5B,SAAgB,eAAe,KAA4B;AACzD,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC,UAAO;;AAET,SAAO,aAAa,QAAQ,IAAI;;AAElC,QAAO,cAAc,eAAe,IAAI;;;;;;;AAQ1C,SAAgB,eAAe,KAAa,OAAqB;AAC/D,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC;;AAEF,eAAa,QAAQ,KAAK,MAAM;AAChC;;AAEF,eAAc,eAAe,KAAK,MAAM"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveLocale.d.ts","sourceRoot":"","sources":["../../../src/utils/resolveLocale.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"resolveLocale.d.ts","sourceRoot":"","sources":["../../../src/utils/resolveLocale.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAAG,MAAM,CAE1E"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { getI18nConfig } from "gt-i18n/internal";
|
|
2
2
|
//#region src/utils/resolveLocale.ts
|
|
3
3
|
function resolveLocale(candidates) {
|
|
4
|
-
|
|
5
|
-
return i18nConfig.determineLocale(candidates ?? void 0) || i18nConfig.getDefaultLocale();
|
|
4
|
+
return getI18nConfig().resolveSupportedLocale(candidates ?? void 0);
|
|
6
5
|
}
|
|
7
6
|
//#endregion
|
|
8
7
|
export { resolveLocale };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolveLocale.js","names":[],"sources":["../../../src/utils/resolveLocale.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport type { LocaleCandidates } from 'gt-i18n/internal/types';\n\nexport function resolveLocale(candidates?: LocaleCandidates | null): string {\n
|
|
1
|
+
{"version":3,"file":"resolveLocale.js","names":[],"sources":["../../../src/utils/resolveLocale.ts"],"sourcesContent":["import { getI18nConfig } from 'gt-i18n/internal';\nimport type { LocaleCandidates } from 'gt-i18n/internal/types';\n\nexport function resolveLocale(candidates?: LocaleCandidates | null): string {\n return getI18nConfig().resolveSupportedLocale(candidates ?? undefined);\n}\n"],"mappings":";;AAGA,SAAgB,cAAc,YAA8C;AAC1E,QAAO,eAAe,CAAC,uBAAuB,cAAc,KAAA,EAAU"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-react-native",
|
|
3
|
-
"version": "11.0.0
|
|
3
|
+
"version": "11.0.0",
|
|
4
4
|
"description": "An i18n package for React Native",
|
|
5
5
|
"main": "./dist/commonjs/index.js",
|
|
6
6
|
"module": "./dist/module/index.js",
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"@formatjs/intl-numberformat": "^8.15.6",
|
|
93
93
|
"@formatjs/intl-pluralrules": "^5.4.6",
|
|
94
94
|
"@formatjs/intl-relativetimeformat": "^11.4.13",
|
|
95
|
-
"@generaltranslation/format": "0.1.2
|
|
96
|
-
"@generaltranslation/react-core": "11.0.0
|
|
97
|
-
"@generaltranslation/supported-locales": "2.1.2
|
|
98
|
-
"generaltranslation": "9.0.0
|
|
99
|
-
"gt-i18n": "1.0.0
|
|
95
|
+
"@generaltranslation/format": "0.1.2",
|
|
96
|
+
"@generaltranslation/react-core": "11.0.0",
|
|
97
|
+
"@generaltranslation/supported-locales": "2.1.2",
|
|
98
|
+
"generaltranslation": "9.0.0",
|
|
99
|
+
"gt-i18n": "1.0.0"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@babel/core": "^7.28.4",
|
|
@@ -3,11 +3,7 @@ import type {
|
|
|
3
3
|
WritableConditionStoreInterface,
|
|
4
4
|
WritableConditionStoreParams,
|
|
5
5
|
} from 'gt-i18n/internal/types';
|
|
6
|
-
import {
|
|
7
|
-
defaultEnableI18nCookieName as defaultEnableI18nStoreKey,
|
|
8
|
-
defaultLocaleCookieName as defaultLocaleStoreKey,
|
|
9
|
-
defaultRegionCookieName as defaultRegionStoreKey,
|
|
10
|
-
} from '@generaltranslation/react-core/pure';
|
|
6
|
+
import { getI18nConfig } from '@generaltranslation/react-core/pure';
|
|
11
7
|
import { getLocale } from '../utils/getLocale';
|
|
12
8
|
import {
|
|
13
9
|
getInitialEnableI18n,
|
|
@@ -17,9 +13,6 @@ import { nativeStoreGet, nativeStoreSet } from '../utils/nativeStore';
|
|
|
17
13
|
import { resolveLocale } from '../utils/resolveLocale';
|
|
18
14
|
|
|
19
15
|
export type NativeConditionStoreParams = WritableConditionStoreParams & {
|
|
20
|
-
localeStoreKey?: string;
|
|
21
|
-
regionStoreKey?: string;
|
|
22
|
-
enableI18nStoreKey?: string;
|
|
23
16
|
_reload?: ReloadType;
|
|
24
17
|
};
|
|
25
18
|
|
|
@@ -35,24 +28,14 @@ export type ReloadType = (state: NativeConditionStoreState) => void;
|
|
|
35
28
|
* Condition store implementation for React Native.
|
|
36
29
|
*/
|
|
37
30
|
export class NativeConditionStore implements WritableConditionStoreInterface {
|
|
38
|
-
private localeStoreKey: string;
|
|
39
|
-
private regionStoreKey: string;
|
|
40
|
-
private enableI18nStoreKey: string;
|
|
41
31
|
private customReload: ReloadType;
|
|
42
32
|
|
|
43
33
|
constructor(config: NativeConditionStoreParams) {
|
|
44
34
|
this.customReload = config._reload ?? (() => undefined);
|
|
45
|
-
this.localeStoreKey = config.localeStoreKey ?? defaultLocaleStoreKey;
|
|
46
|
-
this.regionStoreKey = config.regionStoreKey ?? defaultRegionStoreKey;
|
|
47
|
-
this.enableI18nStoreKey =
|
|
48
|
-
config.enableI18nStoreKey ?? defaultEnableI18nStoreKey;
|
|
49
35
|
|
|
50
|
-
this.updateLocale(
|
|
51
|
-
config.locale ?? getLocale({ localeStoreKey: this.localeStoreKey })
|
|
52
|
-
);
|
|
36
|
+
this.updateLocale(config.locale ?? getLocale());
|
|
53
37
|
const region = getInitialRegion({
|
|
54
38
|
region: config.region,
|
|
55
|
-
regionStoreKey: this.regionStoreKey,
|
|
56
39
|
});
|
|
57
40
|
if (region !== undefined) {
|
|
58
41
|
this.updateRegion(region);
|
|
@@ -60,36 +43,22 @@ export class NativeConditionStore implements WritableConditionStoreInterface {
|
|
|
60
43
|
this.updateEnableI18n(
|
|
61
44
|
getInitialEnableI18n({
|
|
62
45
|
enableI18n: config.enableI18n,
|
|
63
|
-
enableI18nStoreKey: this.enableI18nStoreKey,
|
|
64
46
|
})
|
|
65
47
|
);
|
|
66
48
|
}
|
|
67
49
|
|
|
68
|
-
updateConfig = ({
|
|
69
|
-
localeStoreKey,
|
|
70
|
-
regionStoreKey,
|
|
71
|
-
enableI18nStoreKey,
|
|
72
|
-
}: Pick<
|
|
73
|
-
NativeConditionStoreParams,
|
|
74
|
-
'localeStoreKey' | 'regionStoreKey' | 'enableI18nStoreKey'
|
|
75
|
-
>): void => {
|
|
76
|
-
this.localeStoreKey = localeStoreKey ?? defaultLocaleStoreKey;
|
|
77
|
-
this.regionStoreKey = regionStoreKey ?? defaultRegionStoreKey;
|
|
78
|
-
this.enableI18nStoreKey = enableI18nStoreKey ?? defaultEnableI18nStoreKey;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
50
|
getLocale = (): string => {
|
|
82
|
-
return getLocale(
|
|
51
|
+
return getLocale();
|
|
83
52
|
};
|
|
84
53
|
|
|
85
54
|
setLocale = (locale: LocaleCandidates): void => {
|
|
86
55
|
const nextLocale = resolveLocale(locale);
|
|
87
|
-
nativeStoreSet(
|
|
56
|
+
nativeStoreSet(getLocaleStoreKey(), nextLocale);
|
|
88
57
|
this.reload({ locale: nextLocale });
|
|
89
58
|
};
|
|
90
59
|
|
|
91
60
|
getRegion = (): string | undefined => {
|
|
92
|
-
return nativeStoreGet(
|
|
61
|
+
return nativeStoreGet(getRegionStoreKey()) || undefined;
|
|
93
62
|
};
|
|
94
63
|
|
|
95
64
|
setRegion = (region: string | undefined): void => {
|
|
@@ -98,7 +67,7 @@ export class NativeConditionStore implements WritableConditionStoreInterface {
|
|
|
98
67
|
};
|
|
99
68
|
|
|
100
69
|
getEnableI18n = (): boolean => {
|
|
101
|
-
return nativeStoreGet(
|
|
70
|
+
return nativeStoreGet(getEnableI18nStoreKey()) !== 'false';
|
|
102
71
|
};
|
|
103
72
|
|
|
104
73
|
setEnableI18n = (enableI18n: boolean): void => {
|
|
@@ -107,15 +76,15 @@ export class NativeConditionStore implements WritableConditionStoreInterface {
|
|
|
107
76
|
};
|
|
108
77
|
|
|
109
78
|
updateLocale = (locale: LocaleCandidates): void => {
|
|
110
|
-
nativeStoreSet(
|
|
79
|
+
nativeStoreSet(getLocaleStoreKey(), resolveLocale(locale));
|
|
111
80
|
};
|
|
112
81
|
|
|
113
82
|
updateRegion = (region: string | undefined): void => {
|
|
114
|
-
nativeStoreSet(
|
|
83
|
+
nativeStoreSet(getRegionStoreKey(), region ?? '');
|
|
115
84
|
};
|
|
116
85
|
|
|
117
86
|
updateEnableI18n = (enableI18n: boolean): void => {
|
|
118
|
-
nativeStoreSet(
|
|
87
|
+
nativeStoreSet(getEnableI18nStoreKey(), enableI18n ? 'true' : 'false');
|
|
119
88
|
};
|
|
120
89
|
|
|
121
90
|
reload = (state: Partial<NativeConditionStoreState> = {}): void => {
|
|
@@ -126,3 +95,15 @@ export class NativeConditionStore implements WritableConditionStoreInterface {
|
|
|
126
95
|
});
|
|
127
96
|
};
|
|
128
97
|
}
|
|
98
|
+
|
|
99
|
+
function getLocaleStoreKey(): string {
|
|
100
|
+
return getI18nConfig().getLocaleCookieName();
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function getRegionStoreKey(): string {
|
|
104
|
+
return getI18nConfig().getRegionCookieName();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function getEnableI18nStoreKey(): string {
|
|
108
|
+
return getI18nConfig().getEnableI18nCookieName();
|
|
109
|
+
}
|
package/src/hooks/selectors.ts
CHANGED
|
@@ -3,14 +3,28 @@ import {
|
|
|
3
3
|
useInternalLocaleSelector,
|
|
4
4
|
useInternalRegionSelector,
|
|
5
5
|
} from '@generaltranslation/react-core/hooks';
|
|
6
|
-
import type {
|
|
6
|
+
import type {
|
|
7
|
+
InternalLocaleSelectorResult,
|
|
8
|
+
InternalRegionSelectorOptions,
|
|
9
|
+
InternalRegionSelectorResult,
|
|
10
|
+
} from '@generaltranslation/react-core/hooks';
|
|
7
11
|
|
|
8
|
-
|
|
12
|
+
// Explicit return types are required: project references make TypeScript try to
|
|
13
|
+
// name the inferred selector types, which otherwise reach into
|
|
14
|
+
// generaltranslation's non-portable bundled declarations (TS2742).
|
|
15
|
+
export function useLocaleSelector(
|
|
16
|
+
locales?: string[]
|
|
17
|
+
): InternalLocaleSelectorResult & { setLocale: (locale: string) => void } {
|
|
9
18
|
const setLocale = useSetLocale();
|
|
10
19
|
return { setLocale, ...useInternalLocaleSelector(locales) };
|
|
11
20
|
}
|
|
12
21
|
|
|
13
|
-
export function useRegionSelector(
|
|
22
|
+
export function useRegionSelector(
|
|
23
|
+
options?: InternalRegionSelectorOptions
|
|
24
|
+
): InternalRegionSelectorResult & {
|
|
25
|
+
setLocale: (locale: string) => void;
|
|
26
|
+
setRegion: (region: string | undefined) => void;
|
|
27
|
+
} {
|
|
14
28
|
const setLocale = useSetLocale();
|
|
15
29
|
const setRegion = useSetRegion();
|
|
16
30
|
return { setLocale, setRegion, ...useInternalRegionSelector(options) };
|
package/src/index.tsx
CHANGED
|
@@ -1,98 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
useSetLocale,
|
|
4
|
-
useSetRegion,
|
|
5
|
-
useSetEnableI18n,
|
|
6
|
-
} from './hooks/condition-store';
|
|
7
|
-
import { useLocaleSelector, useRegionSelector } from './hooks/selectors';
|
|
8
|
-
import { useLocaleDirection, useVersionId } from './hooks/utils';
|
|
9
|
-
import { getLocaleFromNativeStore } from './utils/nativeStore';
|
|
10
|
-
import { getLocale } from './utils/getLocale';
|
|
11
|
-
import { initializeGT } from './setup/initializeGT';
|
|
12
|
-
import type { GTProviderProps } from './provider/GTProvider';
|
|
13
|
-
import type { GetLocaleParams } from './utils/getLocale';
|
|
14
|
-
import type { InitializeGTParams } from './setup/initializeGT';
|
|
15
|
-
|
|
16
|
-
import type {
|
|
17
|
-
DictionaryTranslationOptions,
|
|
18
|
-
InlineTranslationOptions,
|
|
19
|
-
RuntimeTranslationOptions,
|
|
20
|
-
} from '@generaltranslation/react-core/pure';
|
|
21
|
-
import type {
|
|
22
|
-
RenderPipeline,
|
|
23
|
-
RenderPreparedT,
|
|
24
|
-
} from '@generaltranslation/react-core/pure';
|
|
25
|
-
|
|
1
|
+
// ===== Components ===== //
|
|
26
2
|
export {
|
|
27
|
-
// ===== Components ===== //
|
|
28
3
|
Branch,
|
|
29
|
-
Plural,
|
|
30
|
-
Derive,
|
|
31
|
-
T,
|
|
32
4
|
Currency,
|
|
33
5
|
DateTime,
|
|
6
|
+
Derive,
|
|
7
|
+
Num,
|
|
8
|
+
Plural,
|
|
34
9
|
RelativeTime,
|
|
10
|
+
T,
|
|
35
11
|
Var,
|
|
36
|
-
Num,
|
|
37
12
|
} from '@generaltranslation/react-core/components';
|
|
13
|
+
export { GTProvider } from './provider/GTProvider';
|
|
38
14
|
|
|
15
|
+
// ===== Hooks ===== //
|
|
39
16
|
export {
|
|
40
|
-
// ===== Hooks ===== //
|
|
41
|
-
useLocale,
|
|
42
17
|
useCustomMapping,
|
|
43
18
|
useDefaultLocale,
|
|
44
19
|
useEnableI18n,
|
|
45
|
-
useLocales,
|
|
46
20
|
useFormatLocales,
|
|
47
21
|
useGT,
|
|
22
|
+
useLocale,
|
|
23
|
+
useLocaleDirection,
|
|
24
|
+
useLocaleProperties,
|
|
25
|
+
useLocales,
|
|
48
26
|
useMessages,
|
|
27
|
+
useRegion,
|
|
49
28
|
useTranslations,
|
|
50
29
|
} from '@generaltranslation/react-core/hooks';
|
|
30
|
+
export {
|
|
31
|
+
useSetLocale,
|
|
32
|
+
useSetRegion,
|
|
33
|
+
useSetEnableI18n,
|
|
34
|
+
} from './hooks/condition-store';
|
|
35
|
+
export { useLocaleSelector, useRegionSelector } from './hooks/selectors';
|
|
51
36
|
|
|
37
|
+
// ===== Functions ===== //
|
|
52
38
|
export {
|
|
53
|
-
|
|
54
|
-
msg,
|
|
39
|
+
createRenderPipeline,
|
|
55
40
|
decodeMsg,
|
|
56
41
|
decodeOptions,
|
|
57
|
-
derive,
|
|
58
|
-
declareVar,
|
|
59
42
|
decodeVars,
|
|
60
|
-
|
|
61
|
-
|
|
43
|
+
declareVar,
|
|
44
|
+
derive,
|
|
45
|
+
getDefaultLocale,
|
|
62
46
|
getFormatLocales,
|
|
63
|
-
|
|
47
|
+
getLocales,
|
|
48
|
+
resolveCanonicalLocale,
|
|
64
49
|
getReactI18nCache,
|
|
50
|
+
getTranslationsSnapshot,
|
|
51
|
+
getVersionId,
|
|
52
|
+
gtFallback,
|
|
53
|
+
mFallback,
|
|
54
|
+
msg,
|
|
65
55
|
setReactI18nCache,
|
|
66
|
-
createRenderPipeline,
|
|
67
56
|
} from '@generaltranslation/react-core/pure';
|
|
57
|
+
export { getLocaleFromNativeStore } from './utils/nativeStore';
|
|
58
|
+
export { getLocale } from './utils/getLocale';
|
|
59
|
+
export { initializeGT } from './setup/initializeGT';
|
|
68
60
|
|
|
69
|
-
|
|
70
|
-
useRegion,
|
|
71
|
-
useGTClass,
|
|
72
|
-
useLocaleProperties,
|
|
73
|
-
} from '@generaltranslation/react-core/hooks';
|
|
74
|
-
|
|
75
|
-
export {
|
|
76
|
-
GTProvider,
|
|
77
|
-
useSetLocale,
|
|
78
|
-
useSetRegion,
|
|
79
|
-
useSetEnableI18n,
|
|
80
|
-
useLocaleSelector,
|
|
81
|
-
useRegionSelector,
|
|
82
|
-
useLocaleDirection,
|
|
83
|
-
useVersionId,
|
|
84
|
-
getLocaleFromNativeStore,
|
|
85
|
-
getLocale,
|
|
86
|
-
initializeGT,
|
|
87
|
-
};
|
|
88
|
-
|
|
61
|
+
// ===== Types ===== //
|
|
89
62
|
export type {
|
|
90
|
-
|
|
91
|
-
InlineTranslationOptions,
|
|
63
|
+
GTTranslationOptions,
|
|
92
64
|
RuntimeTranslationOptions,
|
|
93
65
|
RenderPipeline,
|
|
94
66
|
RenderPreparedT,
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
};
|
|
67
|
+
} from '@generaltranslation/react-core/pure';
|
|
68
|
+
export type { GTProviderProps } from './provider/GTProvider';
|
|
69
|
+
export type { GetLocaleParams } from './utils/getLocale';
|
|
70
|
+
export type { InitializeGTParams } from './setup/initializeGT';
|
package/src/plugin-dir/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { PluginObj, types } from '@babel/core';
|
|
|
3
3
|
import { LOCALE_POLYFILLS, POLYFILLS, type PluginOptions } from './types';
|
|
4
4
|
import { resolveLocales } from './utils/resolveLocales';
|
|
5
5
|
|
|
6
|
-
export
|
|
6
|
+
export function plugin(
|
|
7
7
|
babel: { types: typeof types },
|
|
8
8
|
{
|
|
9
9
|
locales,
|
package/src/plugin.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { plugin } from './plugin-dir';
|