gt-react-native 10.20.0 → 11.0.0-odysseus.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/README.md +26 -3
- package/dist/commonjs/condition-store/NativeConditionStore.js +80 -0
- package/dist/commonjs/condition-store/NativeConditionStore.js.map +1 -0
- package/dist/commonjs/hooks/condition-store.js +38 -0
- package/dist/commonjs/hooks/condition-store.js.map +1 -0
- package/dist/commonjs/hooks/selectors.js +23 -0
- package/dist/commonjs/hooks/selectors.js.map +1 -0
- package/dist/commonjs/hooks/utils.js +17 -0
- package/dist/commonjs/hooks/utils.js.map +1 -0
- package/dist/commonjs/index.js +221 -31
- package/dist/commonjs/provider/GTProvider.js +64 -15
- package/dist/commonjs/provider/GTProvider.js.map +1 -1
- package/dist/commonjs/provider/NativeGTProvider.js +31 -0
- package/dist/commonjs/provider/NativeGTProvider.js.map +1 -0
- package/dist/commonjs/provider/loadTranslations.js +27 -0
- package/dist/commonjs/provider/loadTranslations.js.map +1 -0
- package/dist/commonjs/setup/initializeGT.js +14 -0
- package/dist/commonjs/setup/initializeGT.js.map +1 -0
- package/dist/commonjs/utils/getInitialNativeConditions.js +20 -0
- package/dist/commonjs/utils/getInitialNativeConditions.js.map +1 -0
- package/dist/commonjs/utils/getLocale.js +28 -0
- package/dist/commonjs/utils/getLocale.js.map +1 -0
- package/dist/commonjs/utils/nativeStore.js +3 -3
- package/dist/commonjs/utils/nativeStore.js.map +1 -1
- package/dist/commonjs/utils/resolveLocale.js +12 -0
- package/dist/commonjs/utils/resolveLocale.js.map +1 -0
- package/dist/commonjs/utils/utils.js.map +1 -1
- package/dist/module/condition-store/NativeConditionStore.d.ts +35 -0
- package/dist/module/condition-store/NativeConditionStore.d.ts.map +1 -0
- package/dist/module/condition-store/NativeConditionStore.js +78 -0
- package/dist/module/condition-store/NativeConditionStore.js.map +1 -0
- package/dist/module/hooks/condition-store.d.ts +13 -0
- package/dist/module/hooks/condition-store.d.ts.map +1 -0
- package/dist/module/hooks/condition-store.js +34 -0
- package/dist/module/hooks/condition-store.js.map +1 -0
- package/dist/module/hooks/selectors.d.ts +39 -0
- package/dist/module/hooks/selectors.d.ts.map +1 -0
- package/dist/module/hooks/selectors.js +20 -0
- package/dist/module/hooks/selectors.js.map +1 -0
- package/dist/module/hooks/utils.d.ts +3 -0
- package/dist/module/hooks/utils.d.ts.map +1 -0
- package/dist/module/hooks/utils.js +14 -0
- package/dist/module/hooks/utils.js.map +1 -0
- package/dist/module/index.d.ts +16 -3
- package/dist/module/index.d.ts.map +1 -1
- package/dist/module/index.js +9 -2
- package/dist/module/provider/GTProvider.d.ts +10 -3
- package/dist/module/provider/GTProvider.d.ts.map +1 -1
- package/dist/module/provider/GTProvider.js +64 -11
- package/dist/module/provider/GTProvider.js.map +1 -1
- package/dist/module/provider/NativeGTProvider.d.ts +8 -0
- package/dist/module/provider/NativeGTProvider.d.ts.map +1 -0
- package/dist/module/provider/NativeGTProvider.js +29 -0
- package/dist/module/provider/NativeGTProvider.js.map +1 -0
- package/dist/module/provider/loadTranslations.d.ts +5 -0
- package/dist/module/provider/loadTranslations.d.ts.map +1 -0
- package/dist/module/provider/loadTranslations.js +25 -0
- package/dist/module/provider/loadTranslations.js.map +1 -0
- package/dist/module/setup/initializeGT.d.ts +5 -0
- package/dist/module/setup/initializeGT.d.ts.map +1 -0
- package/dist/module/setup/initializeGT.js +12 -0
- package/dist/module/setup/initializeGT.js.map +1 -0
- package/dist/module/utils/getInitialNativeConditions.d.ts +11 -0
- package/dist/module/utils/getInitialNativeConditions.d.ts.map +1 -0
- package/dist/module/utils/getInitialNativeConditions.js +17 -0
- package/dist/module/utils/getInitialNativeConditions.js.map +1 -0
- package/dist/module/utils/getLocale.d.ts +8 -0
- package/dist/module/utils/getLocale.d.ts.map +1 -0
- package/dist/module/utils/getLocale.js +26 -0
- package/dist/module/utils/getLocale.js.map +1 -0
- 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 +2 -2
- package/dist/module/utils/nativeStore.js.map +1 -1
- package/dist/module/utils/resolveLocale.d.ts +3 -0
- package/dist/module/utils/resolveLocale.d.ts.map +1 -0
- package/dist/module/utils/resolveLocale.js +10 -0
- package/dist/module/utils/resolveLocale.js.map +1 -0
- package/dist/module/utils/utils.d.ts +1 -1
- package/dist/module/utils/utils.d.ts.map +1 -1
- package/dist/module/utils/utils.js.map +1 -1
- package/package.json +8 -7
- package/src/condition-store/NativeConditionStore.ts +128 -0
- package/src/hooks/condition-store.ts +41 -0
- package/src/hooks/selectors.ts +17 -0
- package/src/hooks/utils.ts +14 -0
- package/src/index.tsx +75 -55
- package/src/provider/GTProvider.tsx +103 -13
- package/src/provider/NativeGTProvider.tsx +44 -0
- package/src/provider/loadTranslations.ts +34 -0
- package/src/setup/initializeGT.ts +23 -0
- package/src/utils/getInitialNativeConditions.ts +35 -0
- package/src/utils/getLocale.ts +34 -0
- package/src/utils/nativeStore.ts +3 -3
- package/src/utils/resolveLocale.ts +10 -0
- package/src/utils/utils.ts +1 -1
- package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js +0 -102
- package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js.map +0 -1
- package/dist/commonjs/provider/hooks/useRegionState.js +0 -35
- package/dist/commonjs/provider/hooks/useRegionState.js.map +0 -1
- package/dist/commonjs/types/config.js +0 -1
- package/dist/module/provider/hooks/locale/useDetermineLocale.d.ts +0 -4
- package/dist/module/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
- package/dist/module/provider/hooks/locale/useDetermineLocale.js +0 -100
- package/dist/module/provider/hooks/locale/useDetermineLocale.js.map +0 -1
- package/dist/module/provider/hooks/useRegionState.d.ts +0 -3
- package/dist/module/provider/hooks/useRegionState.d.ts.map +0 -1
- package/dist/module/provider/hooks/useRegionState.js +0 -33
- package/dist/module/provider/hooks/useRegionState.js.map +0 -1
- package/dist/module/types/config.d.ts +0 -30
- package/dist/module/types/config.d.ts.map +0 -1
- package/dist/module/types/config.js +0 -1
- package/src/provider/hooks/locale/useDetermineLocale.ts +0 -220
- package/src/provider/hooks/useRegionState.ts +0 -51
- package/src/types/config.ts +0 -36
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
4
|
+
//#region src/provider/loadTranslations.ts
|
|
5
|
+
const translationPromises = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
function loadTranslations(locale) {
|
|
7
|
+
const i18nCache = (0, _generaltranslation_react_core_pure.getReactI18nCache)();
|
|
8
|
+
let i18nCacheTranslationPromises = translationPromises.get(i18nCache);
|
|
9
|
+
if (i18nCacheTranslationPromises == null) {
|
|
10
|
+
i18nCacheTranslationPromises = /* @__PURE__ */ new Map();
|
|
11
|
+
translationPromises.set(i18nCache, i18nCacheTranslationPromises);
|
|
12
|
+
}
|
|
13
|
+
let promise = i18nCacheTranslationPromises.get(locale);
|
|
14
|
+
if (promise == null) {
|
|
15
|
+
promise = i18nCache.loadTranslations(locale).catch((error) => {
|
|
16
|
+
i18nCacheTranslationPromises.delete(locale);
|
|
17
|
+
console.warn(`Failed to load translations for locale "${locale}". Falling back to an empty translation snapshot.`, error);
|
|
18
|
+
return {};
|
|
19
|
+
});
|
|
20
|
+
i18nCacheTranslationPromises.set(locale, promise);
|
|
21
|
+
}
|
|
22
|
+
return promise;
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
exports.loadTranslations = loadTranslations;
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=loadTranslations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loadTranslations.js","names":[],"sources":["../../../src/provider/loadTranslations.ts"],"sourcesContent":["import { getReactI18nCache } from '@generaltranslation/react-core/pure';\nimport type { Hash } from 'gt-i18n/internal/types';\nimport type { Translation } from 'gt-i18n/types';\n\nexport type LocaleTranslations = Record<Hash, Translation>;\n\nconst translationPromises = new WeakMap<\n object,\n Map<string, Promise<LocaleTranslations>>\n>();\n\nexport function loadTranslations(locale: string): Promise<LocaleTranslations> {\n const i18nCache = getReactI18nCache();\n let i18nCacheTranslationPromises = translationPromises.get(i18nCache);\n if (i18nCacheTranslationPromises == null) {\n i18nCacheTranslationPromises = new Map();\n translationPromises.set(i18nCache, i18nCacheTranslationPromises);\n }\n\n let promise = i18nCacheTranslationPromises.get(locale);\n if (promise == null) {\n // TODO: Support promise caching in i18nCache in a separate PR.\n promise = i18nCache.loadTranslations(locale).catch((error: unknown) => {\n i18nCacheTranslationPromises.delete(locale);\n console.warn(\n `Failed to load translations for locale \"${locale}\". Falling back to an empty translation snapshot.`,\n error\n );\n return {};\n });\n i18nCacheTranslationPromises.set(locale, promise);\n }\n return promise;\n}\n"],"mappings":";;;;AAMA,MAAM,sCAAsB,IAAI,SAG7B;AAEH,SAAgB,iBAAiB,QAA6C;CAC5E,MAAM,aAAA,GAAA,oCAAA,oBAA+B;CACrC,IAAI,+BAA+B,oBAAoB,IAAI,UAAU;AACrE,KAAI,gCAAgC,MAAM;AACxC,iDAA+B,IAAI,KAAK;AACxC,sBAAoB,IAAI,WAAW,6BAA6B;;CAGlE,IAAI,UAAU,6BAA6B,IAAI,OAAO;AACtD,KAAI,WAAW,MAAM;AAEnB,YAAU,UAAU,iBAAiB,OAAO,CAAC,OAAO,UAAmB;AACrE,gCAA6B,OAAO,OAAO;AAC3C,WAAQ,KACN,2CAA2C,OAAO,oDAClD,MACD;AACD,UAAO,EAAE;IACT;AACF,+BAA6B,IAAI,QAAQ,QAAQ;;AAEnD,QAAO"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
4
|
+
let gt_i18n_internal = require("gt-i18n/internal");
|
|
5
|
+
//#region src/setup/initializeGT.ts
|
|
6
|
+
function initializeGT(config) {
|
|
7
|
+
(0, gt_i18n_internal.setupGTServicesEnabled)(config);
|
|
8
|
+
(0, _generaltranslation_react_core_pure.initializeI18nConfig)(config, "server-render");
|
|
9
|
+
(0, _generaltranslation_react_core_pure.setReactI18nCache)(new _generaltranslation_react_core_pure.ReactI18nCache(config));
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.initializeGT = initializeGT;
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=initializeGT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initializeGT.js","names":["ReactI18nCache"],"sources":["../../../src/setup/initializeGT.ts"],"sourcesContent":["import {\n initializeI18nConfig,\n setReactI18nCache,\n} from '@generaltranslation/react-core/pure';\nimport { ReactI18nCache } from '@generaltranslation/react-core/pure';\nimport type { ReactI18nCacheParams } from '@generaltranslation/react-core/pure';\nimport { setupGTServicesEnabled } from 'gt-i18n/internal';\nimport type {\n GTServicesEnabledParams,\n I18nConfigParams,\n} from 'gt-i18n/internal/types';\n\nexport type InitializeGTParams = I18nConfigParams &\n GTServicesEnabledParams &\n ReactI18nCacheParams;\n\nexport function initializeGT(config: InitializeGTParams): void {\n setupGTServicesEnabled(config);\n initializeI18nConfig(config, 'server-render');\n\n const i18nCache = new ReactI18nCache(config);\n setReactI18nCache(i18nCache);\n}\n"],"mappings":";;;;;AAgBA,SAAgB,aAAa,QAAkC;AAC7D,EAAA,GAAA,iBAAA,wBAAuB,OAAO;AAC9B,EAAA,GAAA,oCAAA,sBAAqB,QAAQ,gBAAgB;AAG7C,EAAA,GAAA,oCAAA,mBAAkB,IADIA,oCAAAA,eAAe,OACV,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_utils_nativeStore = require("./nativeStore.js");
|
|
4
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
5
|
+
//#region src/utils/getInitialNativeConditions.ts
|
|
6
|
+
function getInitialRegion({ region, regionStoreKey = _generaltranslation_react_core_pure.defaultRegionCookieName }) {
|
|
7
|
+
if (region !== void 0) return region;
|
|
8
|
+
return require_utils_nativeStore.nativeStoreGet(regionStoreKey) || void 0;
|
|
9
|
+
}
|
|
10
|
+
function getInitialEnableI18n({ enableI18n, enableI18nStoreKey = _generaltranslation_react_core_pure.defaultEnableI18nCookieName }) {
|
|
11
|
+
if (enableI18n !== void 0) return enableI18n;
|
|
12
|
+
const storedEnableI18n = require_utils_nativeStore.nativeStoreGet(enableI18nStoreKey);
|
|
13
|
+
if (storedEnableI18n === null) return true;
|
|
14
|
+
return storedEnableI18n === "true";
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
exports.getInitialEnableI18n = getInitialEnableI18n;
|
|
18
|
+
exports.getInitialRegion = getInitialRegion;
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=getInitialNativeConditions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInitialNativeConditions.js","names":["defaultRegionStoreKey","nativeStoreGet","defaultEnableI18nStoreKey"],"sources":["../../../src/utils/getInitialNativeConditions.ts"],"sourcesContent":["import type { WritableConditionStoreParams } from 'gt-i18n/internal/types';\nimport {\n defaultEnableI18nCookieName as defaultEnableI18nStoreKey,\n defaultRegionCookieName as defaultRegionStoreKey,\n} 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 = defaultRegionStoreKey,\n}: InitialRegionParams): string | undefined {\n if (region !== undefined) return region;\n return nativeStoreGet(regionStoreKey) || undefined;\n}\n\nexport function getInitialEnableI18n({\n enableI18n,\n enableI18nStoreKey = defaultEnableI18nStoreKey,\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":";;;;;AAkBA,SAAgB,iBAAiB,EAC/B,QACA,iBAAiBA,oCAAAA,2BACyB;AAC1C,KAAI,WAAW,KAAA,EAAW,QAAO;AACjC,QAAOC,0BAAAA,eAAe,eAAe,IAAI,KAAA;;AAG3C,SAAgB,qBAAqB,EACnC,YACA,qBAAqBC,oCAAAA,+BACc;AACnC,KAAI,eAAe,KAAA,EAAW,QAAO;CACrC,MAAM,mBAAmBD,0BAAAA,eAAe,mBAAmB;AAC3D,KAAI,qBAAqB,KAAM,QAAO;AACtC,QAAO,qBAAqB"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_utils_getNativeLocales = require("./getNativeLocales.js");
|
|
4
|
+
const require_utils_nativeStore = require("./nativeStore.js");
|
|
5
|
+
const require_utils_resolveLocale = require("./resolveLocale.js");
|
|
6
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
7
|
+
//#region src/utils/getLocale.ts
|
|
8
|
+
/**
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
function getLocale({ localeStoreKey = _generaltranslation_react_core_pure.defaultLocaleCookieName } = {}) {
|
|
12
|
+
const candidates = [];
|
|
13
|
+
pushLocaleCandidates(candidates, require_utils_nativeStore.nativeStoreGet(localeStoreKey));
|
|
14
|
+
candidates.push(...require_utils_getNativeLocales.getNativeLocales());
|
|
15
|
+
return require_utils_resolveLocale.resolveLocale(candidates);
|
|
16
|
+
}
|
|
17
|
+
function pushLocaleCandidates(target, locale) {
|
|
18
|
+
if (!locale) return;
|
|
19
|
+
if (Array.isArray(locale)) {
|
|
20
|
+
target.push(...locale);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
target.push(locale);
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
exports.getLocale = getLocale;
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=getLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getLocale.js","names":["defaultLocaleStoreKey","nativeStoreGet","getNativeLocales","resolveLocale"],"sources":["../../../src/utils/getLocale.ts"],"sourcesContent":["import type { LocaleCandidates } from 'gt-i18n/internal/types';\nimport { defaultLocaleCookieName as defaultLocaleStoreKey } 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 = defaultLocaleStoreKey,\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,iBAAiBA,oCAAAA,4BACE,EAAE,EAAU;CAC/B,MAAM,aAAuB,EAAE;AAC/B,sBAAqB,YAAYC,0BAAAA,eAAe,eAAe,CAAC;AAChE,YAAW,KAAK,GAAGC,+BAAAA,kBAAkB,CAAC;AAEtC,QAAOC,4BAAAA,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"}
|
|
@@ -3,7 +3,7 @@ require("../_virtual/_rolldown/runtime.js");
|
|
|
3
3
|
const require_NativeGtReactNative = require("../NativeGtReactNative.js");
|
|
4
4
|
const require_errors_dir_warnings = require("../errors-dir/warnings.js");
|
|
5
5
|
let react_native = require("react-native");
|
|
6
|
-
let
|
|
6
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
7
7
|
//#region src/utils/nativeStore.ts
|
|
8
8
|
/**
|
|
9
9
|
* Get the locale from the native store.
|
|
@@ -11,12 +11,12 @@ let _generaltranslation_react_core_internal = require("@generaltranslation/react
|
|
|
11
11
|
* This reads persisted native storage directly, so it can temporarily be out of
|
|
12
12
|
* sync with React state while a locale change is in progress.
|
|
13
13
|
*
|
|
14
|
-
* If GTProvider uses a custom
|
|
14
|
+
* If GTProvider uses a custom localeStoreKey, pass that same value as the key.
|
|
15
15
|
*
|
|
16
16
|
* @param key - The key to get the locale from
|
|
17
17
|
* @returns The locale from the native store
|
|
18
18
|
*/
|
|
19
|
-
function getLocaleFromNativeStore(key =
|
|
19
|
+
function getLocaleFromNativeStore(key = _generaltranslation_react_core_pure.defaultLocaleCookieName) {
|
|
20
20
|
return nativeStoreGet(key);
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeStore.js","names":["
|
|
1
|
+
{"version":3,"file":"nativeStore.js","names":["defaultLocaleStoreKey","Platform","ssrUnsupportedWarning","GtReactNative"],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { defaultLocaleCookieName as defaultLocaleStoreKey } from '@generaltranslation/react-core/pure';\nimport { Platform } from 'react-native';\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 * If GTProvider uses a custom localeStoreKey, pass that same value as the key.\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 = defaultLocaleStoreKey\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,MAAMA,oCAAAA,yBACS;AACf,QAAO,eAAe,IAAI;;;;;;;AAQ5B,SAAgB,eAAe,KAA4B;AACzD,KAAIC,aAAAA,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAKC,4BAAAA,sBAAsB;AACnC,UAAO;;AAET,SAAO,aAAa,QAAQ,IAAI;;AAElC,QAAOC,4BAAAA,QAAc,eAAe,IAAI;;;;;;;AAQ1C,SAAgB,eAAe,KAAa,OAAqB;AAC/D,KAAIF,aAAAA,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAKC,4BAAAA,sBAAsB;AACnC;;AAEF,eAAa,QAAQ,KAAK,MAAM;AAChC;;AAEF,6BAAA,QAAc,eAAe,KAAK,MAAM"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let gt_i18n_internal = require("gt-i18n/internal");
|
|
4
|
+
//#region src/utils/resolveLocale.ts
|
|
5
|
+
function resolveLocale(candidates) {
|
|
6
|
+
const i18nConfig = (0, gt_i18n_internal.getI18nConfig)();
|
|
7
|
+
return i18nConfig.determineLocale(candidates ?? void 0) || i18nConfig.getDefaultLocale();
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
exports.resolveLocale = resolveLocale;
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=resolveLocale.js.map
|
|
@@ -0,0 +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 const i18nConfig = getI18nConfig();\n return (\n i18nConfig.determineLocale(candidates ?? undefined) ||\n i18nConfig.getDefaultLocale()\n );\n}\n"],"mappings":";;;;AAGA,SAAgB,cAAc,YAA8C;CAC1E,MAAM,cAAA,GAAA,iBAAA,gBAA4B;AAClC,QACE,WAAW,gBAAgB,cAAc,KAAA,EAAU,IACnD,WAAW,kBAAkB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/utils/utils.ts"],"sourcesContent":["import type {\n AuthFromEnvParams,\n AuthFromEnvReturn,\n} from '@generaltranslation/react-core/
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"sources":["../../../src/utils/utils.ts"],"sourcesContent":["import type {\n AuthFromEnvParams,\n AuthFromEnvReturn,\n} from '@generaltranslation/react-core/pure';\n\nexport function readAuthFromEnv(params: AuthFromEnvParams): AuthFromEnvReturn {\n const { projectId, devApiKey } = params;\n return {\n projectId: projectId || '',\n devApiKey: devApiKey,\n };\n}\n"],"mappings":";;AAKA,SAAgB,gBAAgB,QAA8C;CAC5E,MAAM,EAAE,WAAW,cAAc;AACjC,QAAO;EACL,WAAW,aAAa;EACb;EACZ"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { LocaleCandidates, WritableConditionStoreInterface, WritableConditionStoreParams } from 'gt-i18n/internal/types';
|
|
2
|
+
export type NativeConditionStoreParams = WritableConditionStoreParams & {
|
|
3
|
+
localeStoreKey?: string;
|
|
4
|
+
regionStoreKey?: string;
|
|
5
|
+
enableI18nStoreKey?: string;
|
|
6
|
+
_reload?: ReloadType;
|
|
7
|
+
};
|
|
8
|
+
export type NativeConditionStoreState = {
|
|
9
|
+
locale: string;
|
|
10
|
+
region: string | undefined;
|
|
11
|
+
enableI18n: boolean;
|
|
12
|
+
};
|
|
13
|
+
export type ReloadType = (state: NativeConditionStoreState) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Condition store implementation for React Native.
|
|
16
|
+
*/
|
|
17
|
+
export declare class NativeConditionStore implements WritableConditionStoreInterface {
|
|
18
|
+
private localeStoreKey;
|
|
19
|
+
private regionStoreKey;
|
|
20
|
+
private enableI18nStoreKey;
|
|
21
|
+
private customReload;
|
|
22
|
+
constructor(config: NativeConditionStoreParams);
|
|
23
|
+
updateConfig: ({ localeStoreKey, regionStoreKey, enableI18nStoreKey, }: Pick<NativeConditionStoreParams, "localeStoreKey" | "regionStoreKey" | "enableI18nStoreKey">) => void;
|
|
24
|
+
getLocale: () => string;
|
|
25
|
+
setLocale: (locale: LocaleCandidates) => void;
|
|
26
|
+
getRegion: () => string | undefined;
|
|
27
|
+
setRegion: (region: string | undefined) => void;
|
|
28
|
+
getEnableI18n: () => boolean;
|
|
29
|
+
setEnableI18n: (enableI18n: boolean) => void;
|
|
30
|
+
updateLocale: (locale: LocaleCandidates) => void;
|
|
31
|
+
updateRegion: (region: string | undefined) => void;
|
|
32
|
+
updateEnableI18n: (enableI18n: boolean) => void;
|
|
33
|
+
reload: (state?: Partial<NativeConditionStoreState>) => void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=NativeConditionStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeConditionStore.d.ts","sourceRoot":"","sources":["../../../src/condition-store/NativeConditionStore.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,+BAA+B,EAC/B,4BAA4B,EAC7B,MAAM,wBAAwB,CAAC;AAchC,MAAM,MAAM,0BAA0B,GAAG,4BAA4B,GAAG;IACtE,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,OAAO,CAAC,EAAE,UAAU,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,yBAAyB,GAAG;IACtC,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,CAAC,KAAK,EAAE,yBAAyB,KAAK,IAAI,CAAC;AAEpE;;GAEG;AACH,qBAAa,oBAAqB,YAAW,+BAA+B;IAC1E,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,cAAc,CAAS;IAC/B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,YAAY,CAAa;gBAErB,MAAM,EAAE,0BAA0B;IAyB9C,YAAY,GAAI,yDAIb,IAAI,CACL,0BAA0B,EAC1B,gBAAgB,GAAG,gBAAgB,GAAG,oBAAoB,CAC3D,KAAG,IAAI,CAIN;IAEF,SAAS,QAAO,MAAM,CAEpB;IAEF,SAAS,GAAI,QAAQ,gBAAgB,KAAG,IAAI,CAI1C;IAEF,SAAS,QAAO,MAAM,GAAG,SAAS,CAEhC;IAEF,SAAS,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,IAAI,CAG5C;IAEF,aAAa,QAAO,OAAO,CAEzB;IAEF,aAAa,GAAI,YAAY,OAAO,KAAG,IAAI,CAGzC;IAEF,YAAY,GAAI,QAAQ,gBAAgB,KAAG,IAAI,CAE7C;IAEF,YAAY,GAAI,QAAQ,MAAM,GAAG,SAAS,KAAG,IAAI,CAE/C;IAEF,gBAAgB,GAAI,YAAY,OAAO,KAAG,IAAI,CAE5C;IAEF,MAAM,GAAI,QAAO,OAAO,CAAC,yBAAyB,CAAM,KAAG,IAAI,CAM7D;CACH"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { nativeStoreGet, nativeStoreSet } from "../utils/nativeStore.js";
|
|
2
|
+
import { resolveLocale } from "../utils/resolveLocale.js";
|
|
3
|
+
import { getLocale } from "../utils/getLocale.js";
|
|
4
|
+
import { getInitialEnableI18n, getInitialRegion } from "../utils/getInitialNativeConditions.js";
|
|
5
|
+
import { defaultEnableI18nCookieName, defaultLocaleCookieName, defaultRegionCookieName } from "@generaltranslation/react-core/pure";
|
|
6
|
+
//#region src/condition-store/NativeConditionStore.ts
|
|
7
|
+
/**
|
|
8
|
+
* Condition store implementation for React Native.
|
|
9
|
+
*/
|
|
10
|
+
var NativeConditionStore = class {
|
|
11
|
+
localeStoreKey;
|
|
12
|
+
regionStoreKey;
|
|
13
|
+
enableI18nStoreKey;
|
|
14
|
+
customReload;
|
|
15
|
+
constructor(config) {
|
|
16
|
+
this.customReload = config._reload ?? (() => void 0);
|
|
17
|
+
this.localeStoreKey = config.localeStoreKey ?? defaultLocaleCookieName;
|
|
18
|
+
this.regionStoreKey = config.regionStoreKey ?? defaultRegionCookieName;
|
|
19
|
+
this.enableI18nStoreKey = config.enableI18nStoreKey ?? defaultEnableI18nCookieName;
|
|
20
|
+
this.updateLocale(config.locale ?? getLocale({ localeStoreKey: this.localeStoreKey }));
|
|
21
|
+
const region = getInitialRegion({
|
|
22
|
+
region: config.region,
|
|
23
|
+
regionStoreKey: this.regionStoreKey
|
|
24
|
+
});
|
|
25
|
+
if (region !== void 0) this.updateRegion(region);
|
|
26
|
+
this.updateEnableI18n(getInitialEnableI18n({
|
|
27
|
+
enableI18n: config.enableI18n,
|
|
28
|
+
enableI18nStoreKey: this.enableI18nStoreKey
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
updateConfig = ({ localeStoreKey, regionStoreKey, enableI18nStoreKey }) => {
|
|
32
|
+
this.localeStoreKey = localeStoreKey ?? defaultLocaleCookieName;
|
|
33
|
+
this.regionStoreKey = regionStoreKey ?? defaultRegionCookieName;
|
|
34
|
+
this.enableI18nStoreKey = enableI18nStoreKey ?? defaultEnableI18nCookieName;
|
|
35
|
+
};
|
|
36
|
+
getLocale = () => {
|
|
37
|
+
return getLocale({ localeStoreKey: this.localeStoreKey });
|
|
38
|
+
};
|
|
39
|
+
setLocale = (locale) => {
|
|
40
|
+
const nextLocale = resolveLocale(locale);
|
|
41
|
+
nativeStoreSet(this.localeStoreKey, nextLocale);
|
|
42
|
+
this.reload({ locale: nextLocale });
|
|
43
|
+
};
|
|
44
|
+
getRegion = () => {
|
|
45
|
+
return nativeStoreGet(this.regionStoreKey) || void 0;
|
|
46
|
+
};
|
|
47
|
+
setRegion = (region) => {
|
|
48
|
+
this.updateRegion(region);
|
|
49
|
+
this.reload({ region });
|
|
50
|
+
};
|
|
51
|
+
getEnableI18n = () => {
|
|
52
|
+
return nativeStoreGet(this.enableI18nStoreKey) !== "false";
|
|
53
|
+
};
|
|
54
|
+
setEnableI18n = (enableI18n) => {
|
|
55
|
+
this.updateEnableI18n(enableI18n);
|
|
56
|
+
this.reload({ enableI18n });
|
|
57
|
+
};
|
|
58
|
+
updateLocale = (locale) => {
|
|
59
|
+
nativeStoreSet(this.localeStoreKey, resolveLocale(locale));
|
|
60
|
+
};
|
|
61
|
+
updateRegion = (region) => {
|
|
62
|
+
nativeStoreSet(this.regionStoreKey, region ?? "");
|
|
63
|
+
};
|
|
64
|
+
updateEnableI18n = (enableI18n) => {
|
|
65
|
+
nativeStoreSet(this.enableI18nStoreKey, enableI18n ? "true" : "false");
|
|
66
|
+
};
|
|
67
|
+
reload = (state = {}) => {
|
|
68
|
+
this.customReload({
|
|
69
|
+
locale: state.locale ?? this.getLocale(),
|
|
70
|
+
region: "region" in state ? state.region : this.getRegion(),
|
|
71
|
+
enableI18n: state.enableI18n ?? this.getEnableI18n()
|
|
72
|
+
});
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
//#endregion
|
|
76
|
+
export { NativeConditionStore };
|
|
77
|
+
|
|
78
|
+
//# sourceMappingURL=NativeConditionStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeConditionStore.js","names":["defaultLocaleStoreKey","defaultRegionStoreKey","defaultEnableI18nStoreKey"],"sources":["../../../src/condition-store/NativeConditionStore.ts"],"sourcesContent":["import type {\n LocaleCandidates,\n WritableConditionStoreInterface,\n WritableConditionStoreParams,\n} from 'gt-i18n/internal/types';\nimport {\n defaultEnableI18nCookieName as defaultEnableI18nStoreKey,\n defaultLocaleCookieName as defaultLocaleStoreKey,\n defaultRegionCookieName as defaultRegionStoreKey,\n} from '@generaltranslation/react-core/pure';\nimport { getLocale } from '../utils/getLocale';\nimport {\n getInitialEnableI18n,\n getInitialRegion,\n} from '../utils/getInitialNativeConditions';\nimport { nativeStoreGet, nativeStoreSet } from '../utils/nativeStore';\nimport { resolveLocale } from '../utils/resolveLocale';\n\nexport type NativeConditionStoreParams = WritableConditionStoreParams & {\n localeStoreKey?: string;\n regionStoreKey?: string;\n enableI18nStoreKey?: string;\n _reload?: ReloadType;\n};\n\nexport type NativeConditionStoreState = {\n locale: string;\n region: string | undefined;\n enableI18n: boolean;\n};\n\nexport type ReloadType = (state: NativeConditionStoreState) => void;\n\n/**\n * Condition store implementation for React Native.\n */\nexport class NativeConditionStore implements WritableConditionStoreInterface {\n private localeStoreKey: string;\n private regionStoreKey: string;\n private enableI18nStoreKey: string;\n private customReload: ReloadType;\n\n constructor(config: NativeConditionStoreParams) {\n this.customReload = config._reload ?? (() => undefined);\n this.localeStoreKey = config.localeStoreKey ?? defaultLocaleStoreKey;\n this.regionStoreKey = config.regionStoreKey ?? defaultRegionStoreKey;\n this.enableI18nStoreKey =\n config.enableI18nStoreKey ?? defaultEnableI18nStoreKey;\n\n this.updateLocale(\n config.locale ?? getLocale({ localeStoreKey: this.localeStoreKey })\n );\n const region = getInitialRegion({\n region: config.region,\n regionStoreKey: this.regionStoreKey,\n });\n if (region !== undefined) {\n this.updateRegion(region);\n }\n this.updateEnableI18n(\n getInitialEnableI18n({\n enableI18n: config.enableI18n,\n enableI18nStoreKey: this.enableI18nStoreKey,\n })\n );\n }\n\n updateConfig = ({\n localeStoreKey,\n regionStoreKey,\n enableI18nStoreKey,\n }: Pick<\n NativeConditionStoreParams,\n 'localeStoreKey' | 'regionStoreKey' | 'enableI18nStoreKey'\n >): void => {\n this.localeStoreKey = localeStoreKey ?? defaultLocaleStoreKey;\n this.regionStoreKey = regionStoreKey ?? defaultRegionStoreKey;\n this.enableI18nStoreKey = enableI18nStoreKey ?? defaultEnableI18nStoreKey;\n };\n\n getLocale = (): string => {\n return getLocale({ localeStoreKey: this.localeStoreKey });\n };\n\n setLocale = (locale: LocaleCandidates): void => {\n const nextLocale = resolveLocale(locale);\n nativeStoreSet(this.localeStoreKey, nextLocale);\n this.reload({ locale: nextLocale });\n };\n\n getRegion = (): string | undefined => {\n return nativeStoreGet(this.regionStoreKey) || undefined;\n };\n\n setRegion = (region: string | undefined): void => {\n this.updateRegion(region);\n this.reload({ region });\n };\n\n getEnableI18n = (): boolean => {\n return nativeStoreGet(this.enableI18nStoreKey) !== 'false';\n };\n\n setEnableI18n = (enableI18n: boolean): void => {\n this.updateEnableI18n(enableI18n);\n this.reload({ enableI18n });\n };\n\n updateLocale = (locale: LocaleCandidates): void => {\n nativeStoreSet(this.localeStoreKey, resolveLocale(locale));\n };\n\n updateRegion = (region: string | undefined): void => {\n nativeStoreSet(this.regionStoreKey, region ?? '');\n };\n\n updateEnableI18n = (enableI18n: boolean): void => {\n nativeStoreSet(this.enableI18nStoreKey, enableI18n ? 'true' : 'false');\n };\n\n reload = (state: Partial<NativeConditionStoreState> = {}): void => {\n this.customReload({\n locale: state.locale ?? this.getLocale(),\n region: 'region' in state ? state.region : this.getRegion(),\n enableI18n: state.enableI18n ?? this.getEnableI18n(),\n });\n };\n}\n"],"mappings":";;;;;;;;;AAoCA,IAAa,uBAAb,MAA6E;CAC3E;CACA;CACA;CACA;CAEA,YAAY,QAAoC;AAC9C,OAAK,eAAe,OAAO,kBAAkB,KAAA;AAC7C,OAAK,iBAAiB,OAAO,kBAAkBA;AAC/C,OAAK,iBAAiB,OAAO,kBAAkBC;AAC/C,OAAK,qBACH,OAAO,sBAAsBC;AAE/B,OAAK,aACH,OAAO,UAAU,UAAU,EAAE,gBAAgB,KAAK,gBAAgB,CAAC,CACpE;EACD,MAAM,SAAS,iBAAiB;GAC9B,QAAQ,OAAO;GACf,gBAAgB,KAAK;GACtB,CAAC;AACF,MAAI,WAAW,KAAA,EACb,MAAK,aAAa,OAAO;AAE3B,OAAK,iBACH,qBAAqB;GACnB,YAAY,OAAO;GACnB,oBAAoB,KAAK;GAC1B,CAAC,CACH;;CAGH,gBAAgB,EACd,gBACA,gBACA,yBAIU;AACV,OAAK,iBAAiB,kBAAkBF;AACxC,OAAK,iBAAiB,kBAAkBC;AACxC,OAAK,qBAAqB,sBAAsBC;;CAGlD,kBAA0B;AACxB,SAAO,UAAU,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;;CAG3D,aAAa,WAAmC;EAC9C,MAAM,aAAa,cAAc,OAAO;AACxC,iBAAe,KAAK,gBAAgB,WAAW;AAC/C,OAAK,OAAO,EAAE,QAAQ,YAAY,CAAC;;CAGrC,kBAAsC;AACpC,SAAO,eAAe,KAAK,eAAe,IAAI,KAAA;;CAGhD,aAAa,WAAqC;AAChD,OAAK,aAAa,OAAO;AACzB,OAAK,OAAO,EAAE,QAAQ,CAAC;;CAGzB,sBAA+B;AAC7B,SAAO,eAAe,KAAK,mBAAmB,KAAK;;CAGrD,iBAAiB,eAA8B;AAC7C,OAAK,iBAAiB,WAAW;AACjC,OAAK,OAAO,EAAE,YAAY,CAAC;;CAG7B,gBAAgB,WAAmC;AACjD,iBAAe,KAAK,gBAAgB,cAAc,OAAO,CAAC;;CAG5D,gBAAgB,WAAqC;AACnD,iBAAe,KAAK,gBAAgB,UAAU,GAAG;;CAGnD,oBAAoB,eAA8B;AAChD,iBAAe,KAAK,oBAAoB,aAAa,SAAS,QAAQ;;CAGxE,UAAU,QAA4C,EAAE,KAAW;AACjE,OAAK,aAAa;GAChB,QAAQ,MAAM,UAAU,KAAK,WAAW;GACxC,QAAQ,YAAY,QAAQ,MAAM,SAAS,KAAK,WAAW;GAC3D,YAAY,MAAM,cAAc,KAAK,eAAe;GACrD,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns a function that sets the locale.
|
|
3
|
+
*/
|
|
4
|
+
export declare function useSetLocale(): (locale: string) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Returns a function that sets the region.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useSetRegion(): (region: string | undefined) => void;
|
|
9
|
+
/**
|
|
10
|
+
* Returns a function that sets the enableI18n flag.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useSetEnableI18n(): (enableI18n: boolean) => void;
|
|
13
|
+
//# sourceMappingURL=condition-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-store.d.ts","sourceRoot":"","sources":["../../../src/hooks/condition-store.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,wBAAgB,YAAY,aAGf,MAAM,UAKlB;AAED;;GAEG;AACH,wBAAgB,YAAY,aAGf,MAAM,GAAG,SAAS,UAK9B;AAED;;GAEG;AACH,wBAAgB,gBAAgB,iBAGf,OAAO,UAKvB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { useCallback } from "react";
|
|
2
|
+
import { useConditionStore } from "@generaltranslation/react-core/hooks";
|
|
3
|
+
//#region src/hooks/condition-store.ts
|
|
4
|
+
/**
|
|
5
|
+
* Returns a function that sets the locale.
|
|
6
|
+
*/
|
|
7
|
+
function useSetLocale() {
|
|
8
|
+
const conditionStore = useConditionStore();
|
|
9
|
+
return useCallback((locale) => {
|
|
10
|
+
conditionStore.setLocale(locale);
|
|
11
|
+
}, [conditionStore]);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Returns a function that sets the region.
|
|
15
|
+
*/
|
|
16
|
+
function useSetRegion() {
|
|
17
|
+
const conditionStore = useConditionStore();
|
|
18
|
+
return useCallback((region) => {
|
|
19
|
+
conditionStore.setRegion(region);
|
|
20
|
+
}, [conditionStore]);
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Returns a function that sets the enableI18n flag.
|
|
24
|
+
*/
|
|
25
|
+
function useSetEnableI18n() {
|
|
26
|
+
const conditionStore = useConditionStore();
|
|
27
|
+
return useCallback((enableI18n) => {
|
|
28
|
+
conditionStore.setEnableI18n(enableI18n);
|
|
29
|
+
}, [conditionStore]);
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { useSetEnableI18n, useSetLocale, useSetRegion };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=condition-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"condition-store.js","names":[],"sources":["../../../src/hooks/condition-store.ts"],"sourcesContent":["import { useCallback } from 'react';\nimport { useConditionStore } from '@generaltranslation/react-core/hooks';\n\n/**\n * Returns a function that sets the locale.\n */\nexport function useSetLocale() {\n const conditionStore = useConditionStore();\n return useCallback(\n (locale: string) => {\n conditionStore.setLocale(locale);\n },\n [conditionStore]\n );\n}\n\n/**\n * Returns a function that sets the region.\n */\nexport function useSetRegion() {\n const conditionStore = useConditionStore();\n return useCallback(\n (region: string | undefined) => {\n conditionStore.setRegion(region);\n },\n [conditionStore]\n );\n}\n\n/**\n * Returns a function that sets the enableI18n flag.\n */\nexport function useSetEnableI18n() {\n const conditionStore = useConditionStore();\n return useCallback(\n (enableI18n: boolean) => {\n conditionStore.setEnableI18n(enableI18n);\n },\n [conditionStore]\n );\n}\n"],"mappings":";;;;;;AAMA,SAAgB,eAAe;CAC7B,MAAM,iBAAiB,mBAAmB;AAC1C,QAAO,aACJ,WAAmB;AAClB,iBAAe,UAAU,OAAO;IAElC,CAAC,eAAe,CACjB;;;;;AAMH,SAAgB,eAAe;CAC7B,MAAM,iBAAiB,mBAAmB;AAC1C,QAAO,aACJ,WAA+B;AAC9B,iBAAe,UAAU,OAAO;IAElC,CAAC,eAAe,CACjB;;;;;AAMH,SAAgB,mBAAmB;CACjC,MAAM,iBAAiB,mBAAmB;AAC1C,QAAO,aACJ,eAAwB;AACvB,iBAAe,cAAc,WAAW;IAE1C,CAAC,eAAe,CACjB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { InternalRegionSelectorOptions } from '@generaltranslation/react-core/hooks';
|
|
2
|
+
export declare function useLocaleSelector(locales?: string[]): {
|
|
3
|
+
locale: string;
|
|
4
|
+
locales: string[];
|
|
5
|
+
getLocaleProperties: (locale: string) => {
|
|
6
|
+
code: string;
|
|
7
|
+
name: string;
|
|
8
|
+
nativeName: string;
|
|
9
|
+
languageCode: string;
|
|
10
|
+
languageName: string;
|
|
11
|
+
nativeLanguageName: string;
|
|
12
|
+
nameWithRegionCode: string;
|
|
13
|
+
nativeNameWithRegionCode: string;
|
|
14
|
+
regionCode: string;
|
|
15
|
+
regionName: string;
|
|
16
|
+
nativeRegionName: string;
|
|
17
|
+
scriptCode: string;
|
|
18
|
+
scriptName: string;
|
|
19
|
+
nativeScriptName: string;
|
|
20
|
+
maximizedCode: string;
|
|
21
|
+
maximizedName: string;
|
|
22
|
+
nativeMaximizedName: string;
|
|
23
|
+
minimizedCode: string;
|
|
24
|
+
minimizedName: string;
|
|
25
|
+
nativeMinimizedName: string;
|
|
26
|
+
emoji: string;
|
|
27
|
+
};
|
|
28
|
+
setLocale: (locale: string) => void;
|
|
29
|
+
};
|
|
30
|
+
export declare function useRegionSelector(options?: InternalRegionSelectorOptions): {
|
|
31
|
+
region: string | undefined;
|
|
32
|
+
regions: string[];
|
|
33
|
+
regionData: Map<string, import("@generaltranslation/react-core/hooks").RegionData>;
|
|
34
|
+
locale: string;
|
|
35
|
+
localeRegion: string;
|
|
36
|
+
setLocale: (locale: string) => void;
|
|
37
|
+
setRegion: (region: string | undefined) => void;
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=selectors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../../src/hooks/selectors.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,sCAAsC,CAAC;AAE1F,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGnD;AAED,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,6BAA6B;;;;;;;;EAIxE"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useSetLocale, useSetRegion } from "./condition-store.js";
|
|
2
|
+
import { useInternalLocaleSelector, useInternalRegionSelector } from "@generaltranslation/react-core/hooks";
|
|
3
|
+
//#region src/hooks/selectors.ts
|
|
4
|
+
function useLocaleSelector(locales) {
|
|
5
|
+
return {
|
|
6
|
+
setLocale: useSetLocale(),
|
|
7
|
+
...useInternalLocaleSelector(locales)
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
function useRegionSelector(options) {
|
|
11
|
+
return {
|
|
12
|
+
setLocale: useSetLocale(),
|
|
13
|
+
setRegion: useSetRegion(),
|
|
14
|
+
...useInternalRegionSelector(options)
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useLocaleSelector, useRegionSelector };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.js","names":[],"sources":["../../../src/hooks/selectors.ts"],"sourcesContent":["import { useSetLocale, useSetRegion } from './condition-store';\nimport {\n useInternalLocaleSelector,\n useInternalRegionSelector,\n} from '@generaltranslation/react-core/hooks';\nimport type { InternalRegionSelectorOptions } from '@generaltranslation/react-core/hooks';\n\nexport function useLocaleSelector(locales?: string[]) {\n const setLocale = useSetLocale();\n return { setLocale, ...useInternalLocaleSelector(locales) };\n}\n\nexport function useRegionSelector(options?: InternalRegionSelectorOptions) {\n const setLocale = useSetLocale();\n const setRegion = useSetRegion();\n return { setLocale, setRegion, ...useInternalRegionSelector(options) };\n}\n"],"mappings":";;;AAOA,SAAgB,kBAAkB,SAAoB;AAEpD,QAAO;EAAE,WADS,cACA;EAAE,GAAG,0BAA0B,QAAQ;EAAE;;AAG7D,SAAgB,kBAAkB,SAAyC;AAGzE,QAAO;EAAE,WAFS,cAEA;EAAE,WADF,cACW;EAAE,GAAG,0BAA0B,QAAQ;EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/hooks/utils.ts"],"names":[],"mappings":"AAMA,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAGjE;AAED,wBAAgB,YAAY,IAAI,MAAM,GAAG,SAAS,CAEjD"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { getVersionId } from "@generaltranslation/react-core/pure";
|
|
2
|
+
import { useLocale, useLocaleDirection as useLocaleDirection$1 } from "@generaltranslation/react-core/hooks";
|
|
3
|
+
//#region src/hooks/utils.ts
|
|
4
|
+
function useLocaleDirection(locale) {
|
|
5
|
+
const currentLocale = useLocale();
|
|
6
|
+
return useLocaleDirection$1(locale ?? currentLocale);
|
|
7
|
+
}
|
|
8
|
+
function useVersionId() {
|
|
9
|
+
return getVersionId();
|
|
10
|
+
}
|
|
11
|
+
//#endregion
|
|
12
|
+
export { useLocaleDirection, useVersionId };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":["useCoreLocaleDirection"],"sources":["../../../src/hooks/utils.ts"],"sourcesContent":["import { getVersionId } from '@generaltranslation/react-core/pure';\nimport {\n useLocale,\n useLocaleDirection as useCoreLocaleDirection,\n} from '@generaltranslation/react-core/hooks';\n\nexport function useLocaleDirection(locale?: string): 'ltr' | 'rtl' {\n const currentLocale = useLocale();\n return useCoreLocaleDirection(locale ?? currentLocale);\n}\n\nexport function useVersionId(): string | undefined {\n return getVersionId();\n}\n"],"mappings":";;;AAMA,SAAgB,mBAAmB,QAAgC;CACjE,MAAM,gBAAgB,WAAW;AACjC,QAAOA,qBAAuB,UAAU,cAAc;;AAGxD,SAAgB,eAAmC;AACjD,QAAO,cAAc"}
|
package/dist/module/index.d.ts
CHANGED
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import { GTProvider } from './provider/GTProvider';
|
|
2
|
+
import { useSetLocale, useSetRegion, useSetEnableI18n } from './hooks/condition-store';
|
|
3
|
+
import { useLocaleSelector, useRegionSelector } from './hooks/selectors';
|
|
4
|
+
import { useLocaleDirection, useVersionId } from './hooks/utils';
|
|
2
5
|
import { getLocaleFromNativeStore } from './utils/nativeStore';
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
+
import { getLocale } from './utils/getLocale';
|
|
7
|
+
import { initializeGT } from './setup/initializeGT';
|
|
8
|
+
import type { GTProviderProps } from './provider/GTProvider';
|
|
9
|
+
import type { GetLocaleParams } from './utils/getLocale';
|
|
10
|
+
import type { InitializeGTParams } from './setup/initializeGT';
|
|
11
|
+
import type { DictionaryTranslationOptions, InlineTranslationOptions, RuntimeTranslationOptions } from '@generaltranslation/react-core/pure';
|
|
12
|
+
import type { RenderPipeline, RenderPreparedT } from '@generaltranslation/react-core/pure';
|
|
13
|
+
export { Branch, Plural, Derive, T, Currency, DateTime, RelativeTime, Var, Num, } from '@generaltranslation/react-core/components';
|
|
14
|
+
export { useLocale, useCustomMapping, useDefaultLocale, useEnableI18n, useLocales, useFormatLocales, useGT, useMessages, useTranslations, } from '@generaltranslation/react-core/hooks';
|
|
15
|
+
export { msg, decodeMsg, decodeOptions, derive, declareVar, decodeVars, mFallback, gtFallback, getFormatLocales, getTranslationsSnapshot, getReactI18nCache, setReactI18nCache, createRenderPipeline, } from '@generaltranslation/react-core/pure';
|
|
16
|
+
export { useRegion, useGTClass, useLocaleProperties, } from '@generaltranslation/react-core/hooks';
|
|
17
|
+
export { GTProvider, useSetLocale, useSetRegion, useSetEnableI18n, useLocaleSelector, useRegionSelector, useLocaleDirection, useVersionId, getLocaleFromNativeStore, getLocale, initializeGT, };
|
|
18
|
+
export type { DictionaryTranslationOptions, InlineTranslationOptions, RuntimeTranslationOptions, RenderPipeline, RenderPreparedT, GTProviderProps, GetLocaleParams, InitializeGTParams, };
|
|
6
19
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AACnD,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,gBAAgB,EACjB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACjE,OAAO,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE/D,OAAO,KAAK,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EACV,cAAc,EACd,eAAe,EAChB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EAEL,MAAM,EACN,MAAM,EACN,MAAM,EACN,CAAC,EACD,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,GAAG,EACH,GAAG,GACJ,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EAEL,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,aAAa,EACb,UAAU,EACV,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,GAChB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAEL,GAAG,EACH,SAAS,EACT,aAAa,EACb,MAAM,EACN,UAAU,EACV,UAAU,EACV,SAAS,EACT,UAAU,EACV,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,qCAAqC,CAAC;AAE7C,OAAO,EACL,SAAS,EACT,UAAU,EACV,mBAAmB,GACpB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,EAClB,YAAY,EACZ,wBAAwB,EACxB,SAAS,EACT,YAAY,GACb,CAAC;AAEF,YAAY,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EACzB,cAAc,EACd,eAAe,EACf,eAAe,EACf,eAAe,EACf,kBAAkB,GACnB,CAAC"}
|
package/dist/module/index.js
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import { getLocaleFromNativeStore } from "./utils/nativeStore.js";
|
|
2
|
+
import { getLocale } from "./utils/getLocale.js";
|
|
2
3
|
import { GTProvider } from "./provider/GTProvider.js";
|
|
3
|
-
import {
|
|
4
|
-
|
|
4
|
+
import { useSetEnableI18n, useSetLocale, useSetRegion } from "./hooks/condition-store.js";
|
|
5
|
+
import { useLocaleSelector, useRegionSelector } from "./hooks/selectors.js";
|
|
6
|
+
import { useLocaleDirection, useVersionId } from "./hooks/utils.js";
|
|
7
|
+
import { initializeGT } from "./setup/initializeGT.js";
|
|
8
|
+
import { createRenderPipeline, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getFormatLocales, getReactI18nCache, getTranslationsSnapshot, gtFallback, mFallback, msg, setReactI18nCache } from "@generaltranslation/react-core/pure";
|
|
9
|
+
import { Branch, Currency, DateTime, Derive, Num, Plural, RelativeTime, T, Var } from "@generaltranslation/react-core/components";
|
|
10
|
+
import { useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useGTClass, useLocale, useLocaleProperties, useLocales, useMessages, useRegion, useTranslations } from "@generaltranslation/react-core/hooks";
|
|
11
|
+
export { Branch, Currency, DateTime, Derive, GTProvider, Num, Plural, RelativeTime, T, Var, createRenderPipeline, declareVar, decodeMsg, decodeOptions, decodeVars, derive, getFormatLocales, getLocale, getLocaleFromNativeStore, getReactI18nCache, getTranslationsSnapshot, gtFallback, initializeGT, mFallback, msg, setReactI18nCache, useCustomMapping, useDefaultLocale, useEnableI18n, useFormatLocales, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useSetEnableI18n, useSetLocale, useSetRegion, useTranslations, useVersionId };
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import type { InternalGTProviderProps } from '@generaltranslation/react-core/components';
|
|
2
|
+
import type { ReactNode } from 'react';
|
|
3
|
+
import type { LocaleCandidates } from 'gt-i18n/internal/types';
|
|
4
|
+
import type { NativeConditionStoreParams } from '../condition-store/NativeConditionStore';
|
|
5
|
+
export type GTProviderProps = Omit<InternalGTProviderProps, 'conditionStore' | 'i18nStore' | 'translations'> & Omit<NativeConditionStoreParams, 'locale' | '_reload'> & {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
locale?: LocaleCandidates;
|
|
8
|
+
loadingFallback?: ReactNode;
|
|
9
|
+
};
|
|
10
|
+
export declare function GTProvider(props: GTProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
4
11
|
//# sourceMappingURL=GTProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/GTProvider.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,2CAA2C,CAAC;AAEzF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EAAE,gBAAgB,EAAU,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,yCAAyC,CAAC;AAUjD,MAAM,MAAM,eAAe,GAAG,IAAI,CAChC,uBAAuB,EACvB,gBAAgB,GAAG,WAAW,GAAG,cAAc,CAChD,GACC,IAAI,CAAC,0BAA0B,EAAE,QAAQ,GAAG,SAAS,CAAC,GAAG;IACvD,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,MAAM,CAAC,EAAE,gBAAgB,CAAC;IAC1B,eAAe,CAAC,EAAE,SAAS,CAAC;CAC7B,CAAC;AAKJ,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,2CAQhD"}
|