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
package/README.md
CHANGED
|
@@ -29,13 +29,36 @@ npx gt init
|
|
|
29
29
|
```
|
|
30
30
|
|
|
31
31
|
```jsx
|
|
32
|
+
// index.ts
|
|
33
|
+
import { registerRootComponent } from 'expo';
|
|
34
|
+
import { initializeGT } from 'gt-react-native';
|
|
35
|
+
import App from './App';
|
|
36
|
+
import gtConfig from './gt.config.json';
|
|
37
|
+
import esTranslations from './src/_gt/es.json';
|
|
38
|
+
import frTranslations from './src/_gt/fr.json';
|
|
39
|
+
|
|
40
|
+
const localTranslations = {
|
|
41
|
+
es: esTranslations,
|
|
42
|
+
fr: frTranslations,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
initializeGT({
|
|
46
|
+
defaultLocale: gtConfig.defaultLocale,
|
|
47
|
+
locales: gtConfig.locales,
|
|
48
|
+
loadTranslations: async (locale) => localTranslations[locale] ?? {},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
registerRootComponent(App);
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
```jsx
|
|
55
|
+
// App.tsx
|
|
56
|
+
import { Text } from 'react-native';
|
|
32
57
|
import { T, GTProvider } from 'gt-react-native';
|
|
33
|
-
import gtConfig from '../gt.config.json';
|
|
34
|
-
import { loadTranslations } from './loadTranslations';
|
|
35
58
|
|
|
36
59
|
export default function App() {
|
|
37
60
|
return (
|
|
38
|
-
<GTProvider
|
|
61
|
+
<GTProvider>
|
|
39
62
|
<T>
|
|
40
63
|
<Text>This gets translated automatically.</Text>
|
|
41
64
|
</T>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_utils_nativeStore = require("../utils/nativeStore.js");
|
|
4
|
+
const require_utils_resolveLocale = require("../utils/resolveLocale.js");
|
|
5
|
+
const require_utils_getLocale = require("../utils/getLocale.js");
|
|
6
|
+
const require_utils_getInitialNativeConditions = require("../utils/getInitialNativeConditions.js");
|
|
7
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
8
|
+
//#region src/condition-store/NativeConditionStore.ts
|
|
9
|
+
/**
|
|
10
|
+
* Condition store implementation for React Native.
|
|
11
|
+
*/
|
|
12
|
+
var NativeConditionStore = class {
|
|
13
|
+
localeStoreKey;
|
|
14
|
+
regionStoreKey;
|
|
15
|
+
enableI18nStoreKey;
|
|
16
|
+
customReload;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
this.customReload = config._reload ?? (() => void 0);
|
|
19
|
+
this.localeStoreKey = config.localeStoreKey ?? _generaltranslation_react_core_pure.defaultLocaleCookieName;
|
|
20
|
+
this.regionStoreKey = config.regionStoreKey ?? _generaltranslation_react_core_pure.defaultRegionCookieName;
|
|
21
|
+
this.enableI18nStoreKey = config.enableI18nStoreKey ?? _generaltranslation_react_core_pure.defaultEnableI18nCookieName;
|
|
22
|
+
this.updateLocale(config.locale ?? require_utils_getLocale.getLocale({ localeStoreKey: this.localeStoreKey }));
|
|
23
|
+
const region = require_utils_getInitialNativeConditions.getInitialRegion({
|
|
24
|
+
region: config.region,
|
|
25
|
+
regionStoreKey: this.regionStoreKey
|
|
26
|
+
});
|
|
27
|
+
if (region !== void 0) this.updateRegion(region);
|
|
28
|
+
this.updateEnableI18n(require_utils_getInitialNativeConditions.getInitialEnableI18n({
|
|
29
|
+
enableI18n: config.enableI18n,
|
|
30
|
+
enableI18nStoreKey: this.enableI18nStoreKey
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
updateConfig = ({ localeStoreKey, regionStoreKey, enableI18nStoreKey }) => {
|
|
34
|
+
this.localeStoreKey = localeStoreKey ?? _generaltranslation_react_core_pure.defaultLocaleCookieName;
|
|
35
|
+
this.regionStoreKey = regionStoreKey ?? _generaltranslation_react_core_pure.defaultRegionCookieName;
|
|
36
|
+
this.enableI18nStoreKey = enableI18nStoreKey ?? _generaltranslation_react_core_pure.defaultEnableI18nCookieName;
|
|
37
|
+
};
|
|
38
|
+
getLocale = () => {
|
|
39
|
+
return require_utils_getLocale.getLocale({ localeStoreKey: this.localeStoreKey });
|
|
40
|
+
};
|
|
41
|
+
setLocale = (locale) => {
|
|
42
|
+
const nextLocale = require_utils_resolveLocale.resolveLocale(locale);
|
|
43
|
+
require_utils_nativeStore.nativeStoreSet(this.localeStoreKey, nextLocale);
|
|
44
|
+
this.reload({ locale: nextLocale });
|
|
45
|
+
};
|
|
46
|
+
getRegion = () => {
|
|
47
|
+
return require_utils_nativeStore.nativeStoreGet(this.regionStoreKey) || void 0;
|
|
48
|
+
};
|
|
49
|
+
setRegion = (region) => {
|
|
50
|
+
this.updateRegion(region);
|
|
51
|
+
this.reload({ region });
|
|
52
|
+
};
|
|
53
|
+
getEnableI18n = () => {
|
|
54
|
+
return require_utils_nativeStore.nativeStoreGet(this.enableI18nStoreKey) !== "false";
|
|
55
|
+
};
|
|
56
|
+
setEnableI18n = (enableI18n) => {
|
|
57
|
+
this.updateEnableI18n(enableI18n);
|
|
58
|
+
this.reload({ enableI18n });
|
|
59
|
+
};
|
|
60
|
+
updateLocale = (locale) => {
|
|
61
|
+
require_utils_nativeStore.nativeStoreSet(this.localeStoreKey, require_utils_resolveLocale.resolveLocale(locale));
|
|
62
|
+
};
|
|
63
|
+
updateRegion = (region) => {
|
|
64
|
+
require_utils_nativeStore.nativeStoreSet(this.regionStoreKey, region ?? "");
|
|
65
|
+
};
|
|
66
|
+
updateEnableI18n = (enableI18n) => {
|
|
67
|
+
require_utils_nativeStore.nativeStoreSet(this.enableI18nStoreKey, enableI18n ? "true" : "false");
|
|
68
|
+
};
|
|
69
|
+
reload = (state = {}) => {
|
|
70
|
+
this.customReload({
|
|
71
|
+
locale: state.locale ?? this.getLocale(),
|
|
72
|
+
region: "region" in state ? state.region : this.getRegion(),
|
|
73
|
+
enableI18n: state.enableI18n ?? this.getEnableI18n()
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
};
|
|
77
|
+
//#endregion
|
|
78
|
+
exports.NativeConditionStore = NativeConditionStore;
|
|
79
|
+
|
|
80
|
+
//# sourceMappingURL=NativeConditionStore.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeConditionStore.js","names":["defaultLocaleStoreKey","defaultRegionStoreKey","defaultEnableI18nStoreKey","getLocale","getInitialRegion","getInitialEnableI18n","resolveLocale","nativeStoreGet"],"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,oCAAAA;AAC/C,OAAK,iBAAiB,OAAO,kBAAkBC,oCAAAA;AAC/C,OAAK,qBACH,OAAO,sBAAsBC,oCAAAA;AAE/B,OAAK,aACH,OAAO,UAAUC,wBAAAA,UAAU,EAAE,gBAAgB,KAAK,gBAAgB,CAAC,CACpE;EACD,MAAM,SAASC,yCAAAA,iBAAiB;GAC9B,QAAQ,OAAO;GACf,gBAAgB,KAAK;GACtB,CAAC;AACF,MAAI,WAAW,KAAA,EACb,MAAK,aAAa,OAAO;AAE3B,OAAK,iBACHC,yCAAAA,qBAAqB;GACnB,YAAY,OAAO;GACnB,oBAAoB,KAAK;GAC1B,CAAC,CACH;;CAGH,gBAAgB,EACd,gBACA,gBACA,yBAIU;AACV,OAAK,iBAAiB,kBAAkBL,oCAAAA;AACxC,OAAK,iBAAiB,kBAAkBC,oCAAAA;AACxC,OAAK,qBAAqB,sBAAsBC,oCAAAA;;CAGlD,kBAA0B;AACxB,SAAOC,wBAAAA,UAAU,EAAE,gBAAgB,KAAK,gBAAgB,CAAC;;CAG3D,aAAa,WAAmC;EAC9C,MAAM,aAAaG,4BAAAA,cAAc,OAAO;AACxC,4BAAA,eAAe,KAAK,gBAAgB,WAAW;AAC/C,OAAK,OAAO,EAAE,QAAQ,YAAY,CAAC;;CAGrC,kBAAsC;AACpC,SAAOC,0BAAAA,eAAe,KAAK,eAAe,IAAI,KAAA;;CAGhD,aAAa,WAAqC;AAChD,OAAK,aAAa,OAAO;AACzB,OAAK,OAAO,EAAE,QAAQ,CAAC;;CAGzB,sBAA+B;AAC7B,SAAOA,0BAAAA,eAAe,KAAK,mBAAmB,KAAK;;CAGrD,iBAAiB,eAA8B;AAC7C,OAAK,iBAAiB,WAAW;AACjC,OAAK,OAAO,EAAE,YAAY,CAAC;;CAG7B,gBAAgB,WAAmC;AACjD,4BAAA,eAAe,KAAK,gBAAgBD,4BAAAA,cAAc,OAAO,CAAC;;CAG5D,gBAAgB,WAAqC;AACnD,4BAAA,eAAe,KAAK,gBAAgB,UAAU,GAAG;;CAGnD,oBAAoB,eAA8B;AAChD,4BAAA,eAAe,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,38 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let _generaltranslation_react_core_hooks = require("@generaltranslation/react-core/hooks");
|
|
5
|
+
//#region src/hooks/condition-store.ts
|
|
6
|
+
/**
|
|
7
|
+
* Returns a function that sets the locale.
|
|
8
|
+
*/
|
|
9
|
+
function useSetLocale() {
|
|
10
|
+
const conditionStore = (0, _generaltranslation_react_core_hooks.useConditionStore)();
|
|
11
|
+
return (0, react.useCallback)((locale) => {
|
|
12
|
+
conditionStore.setLocale(locale);
|
|
13
|
+
}, [conditionStore]);
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Returns a function that sets the region.
|
|
17
|
+
*/
|
|
18
|
+
function useSetRegion() {
|
|
19
|
+
const conditionStore = (0, _generaltranslation_react_core_hooks.useConditionStore)();
|
|
20
|
+
return (0, react.useCallback)((region) => {
|
|
21
|
+
conditionStore.setRegion(region);
|
|
22
|
+
}, [conditionStore]);
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Returns a function that sets the enableI18n flag.
|
|
26
|
+
*/
|
|
27
|
+
function useSetEnableI18n() {
|
|
28
|
+
const conditionStore = (0, _generaltranslation_react_core_hooks.useConditionStore)();
|
|
29
|
+
return (0, react.useCallback)((enableI18n) => {
|
|
30
|
+
conditionStore.setEnableI18n(enableI18n);
|
|
31
|
+
}, [conditionStore]);
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
exports.useSetEnableI18n = useSetEnableI18n;
|
|
35
|
+
exports.useSetLocale = useSetLocale;
|
|
36
|
+
exports.useSetRegion = useSetRegion;
|
|
37
|
+
|
|
38
|
+
//# 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,kBAAA,GAAA,qCAAA,oBAAoC;AAC1C,SAAA,GAAA,MAAA,cACG,WAAmB;AAClB,iBAAe,UAAU,OAAO;IAElC,CAAC,eAAe,CACjB;;;;;AAMH,SAAgB,eAAe;CAC7B,MAAM,kBAAA,GAAA,qCAAA,oBAAoC;AAC1C,SAAA,GAAA,MAAA,cACG,WAA+B;AAC9B,iBAAe,UAAU,OAAO;IAElC,CAAC,eAAe,CACjB;;;;;AAMH,SAAgB,mBAAmB;CACjC,MAAM,kBAAA,GAAA,qCAAA,oBAAoC;AAC1C,SAAA,GAAA,MAAA,cACG,eAAwB;AACvB,iBAAe,cAAc,WAAW;IAE1C,CAAC,eAAe,CACjB"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_hooks_condition_store = require("./condition-store.js");
|
|
4
|
+
let _generaltranslation_react_core_hooks = require("@generaltranslation/react-core/hooks");
|
|
5
|
+
//#region src/hooks/selectors.ts
|
|
6
|
+
function useLocaleSelector(locales) {
|
|
7
|
+
return {
|
|
8
|
+
setLocale: require_hooks_condition_store.useSetLocale(),
|
|
9
|
+
...(0, _generaltranslation_react_core_hooks.useInternalLocaleSelector)(locales)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function useRegionSelector(options) {
|
|
13
|
+
return {
|
|
14
|
+
setLocale: require_hooks_condition_store.useSetLocale(),
|
|
15
|
+
setRegion: require_hooks_condition_store.useSetRegion(),
|
|
16
|
+
...(0, _generaltranslation_react_core_hooks.useInternalRegionSelector)(options)
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
exports.useLocaleSelector = useLocaleSelector;
|
|
21
|
+
exports.useRegionSelector = useRegionSelector;
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=selectors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"selectors.js","names":["useSetLocale","useSetRegion"],"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,WADSA,8BAAAA,cACA;EAAE,IAAA,GAAA,qCAAA,2BAA6B,QAAQ;EAAE;;AAG7D,SAAgB,kBAAkB,SAAyC;AAGzE,QAAO;EAAE,WAFSA,8BAAAA,cAEA;EAAE,WADFC,8BAAAA,cACW;EAAE,IAAA,GAAA,qCAAA,2BAA6B,QAAQ;EAAE"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 _generaltranslation_react_core_hooks = require("@generaltranslation/react-core/hooks");
|
|
5
|
+
//#region src/hooks/utils.ts
|
|
6
|
+
function useLocaleDirection(locale) {
|
|
7
|
+
const currentLocale = (0, _generaltranslation_react_core_hooks.useLocale)();
|
|
8
|
+
return (0, _generaltranslation_react_core_hooks.useLocaleDirection)(locale ?? currentLocale);
|
|
9
|
+
}
|
|
10
|
+
function useVersionId() {
|
|
11
|
+
return (0, _generaltranslation_react_core_pure.getVersionId)();
|
|
12
|
+
}
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.useLocaleDirection = useLocaleDirection;
|
|
15
|
+
exports.useVersionId = useVersionId;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","names":[],"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,iBAAA,GAAA,qCAAA,YAA2B;AACjC,SAAA,GAAA,qCAAA,oBAA8B,UAAU,cAAc;;AAGxD,SAAgB,eAAmC;AACjD,SAAA,GAAA,oCAAA,eAAqB"}
|
package/dist/commonjs/index.js
CHANGED
|
@@ -1,37 +1,227 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./_virtual/_rolldown/runtime.js");
|
|
3
3
|
const require_utils_nativeStore = require("./utils/nativeStore.js");
|
|
4
|
+
const require_utils_getLocale = require("./utils/getLocale.js");
|
|
4
5
|
const require_provider_GTProvider = require("./provider/GTProvider.js");
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
const require_hooks_condition_store = require("./hooks/condition-store.js");
|
|
7
|
+
const require_hooks_selectors = require("./hooks/selectors.js");
|
|
8
|
+
const require_hooks_utils = require("./hooks/utils.js");
|
|
9
|
+
const require_setup_initializeGT = require("./setup/initializeGT.js");
|
|
10
|
+
let _generaltranslation_react_core_pure = require("@generaltranslation/react-core/pure");
|
|
11
|
+
let _generaltranslation_react_core_components = require("@generaltranslation/react-core/components");
|
|
12
|
+
let _generaltranslation_react_core_hooks = require("@generaltranslation/react-core/hooks");
|
|
13
|
+
Object.defineProperty(exports, "Branch", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function() {
|
|
16
|
+
return _generaltranslation_react_core_components.Branch;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "Currency", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function() {
|
|
22
|
+
return _generaltranslation_react_core_components.Currency;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
Object.defineProperty(exports, "DateTime", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
get: function() {
|
|
28
|
+
return _generaltranslation_react_core_components.DateTime;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
Object.defineProperty(exports, "Derive", {
|
|
32
|
+
enumerable: true,
|
|
33
|
+
get: function() {
|
|
34
|
+
return _generaltranslation_react_core_components.Derive;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
9
37
|
exports.GTProvider = require_provider_GTProvider.GTProvider;
|
|
10
|
-
exports
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
exports
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
Object.defineProperty(exports, "Num", {
|
|
39
|
+
enumerable: true,
|
|
40
|
+
get: function() {
|
|
41
|
+
return _generaltranslation_react_core_components.Num;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(exports, "Plural", {
|
|
45
|
+
enumerable: true,
|
|
46
|
+
get: function() {
|
|
47
|
+
return _generaltranslation_react_core_components.Plural;
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
Object.defineProperty(exports, "RelativeTime", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function() {
|
|
53
|
+
return _generaltranslation_react_core_components.RelativeTime;
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
Object.defineProperty(exports, "T", {
|
|
57
|
+
enumerable: true,
|
|
58
|
+
get: function() {
|
|
59
|
+
return _generaltranslation_react_core_components.T;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
Object.defineProperty(exports, "Var", {
|
|
63
|
+
enumerable: true,
|
|
64
|
+
get: function() {
|
|
65
|
+
return _generaltranslation_react_core_components.Var;
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
Object.defineProperty(exports, "createRenderPipeline", {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function() {
|
|
71
|
+
return _generaltranslation_react_core_pure.createRenderPipeline;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
Object.defineProperty(exports, "declareVar", {
|
|
75
|
+
enumerable: true,
|
|
76
|
+
get: function() {
|
|
77
|
+
return _generaltranslation_react_core_pure.declareVar;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
Object.defineProperty(exports, "decodeMsg", {
|
|
81
|
+
enumerable: true,
|
|
82
|
+
get: function() {
|
|
83
|
+
return _generaltranslation_react_core_pure.decodeMsg;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
Object.defineProperty(exports, "decodeOptions", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function() {
|
|
89
|
+
return _generaltranslation_react_core_pure.decodeOptions;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "decodeVars", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function() {
|
|
95
|
+
return _generaltranslation_react_core_pure.decodeVars;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
Object.defineProperty(exports, "derive", {
|
|
99
|
+
enumerable: true,
|
|
100
|
+
get: function() {
|
|
101
|
+
return _generaltranslation_react_core_pure.derive;
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
Object.defineProperty(exports, "getFormatLocales", {
|
|
105
|
+
enumerable: true,
|
|
106
|
+
get: function() {
|
|
107
|
+
return _generaltranslation_react_core_pure.getFormatLocales;
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
exports.getLocale = require_utils_getLocale.getLocale;
|
|
20
111
|
exports.getLocaleFromNativeStore = require_utils_nativeStore.getLocaleFromNativeStore;
|
|
21
|
-
exports
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
exports
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
exports
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
112
|
+
Object.defineProperty(exports, "getReactI18nCache", {
|
|
113
|
+
enumerable: true,
|
|
114
|
+
get: function() {
|
|
115
|
+
return _generaltranslation_react_core_pure.getReactI18nCache;
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
Object.defineProperty(exports, "getTranslationsSnapshot", {
|
|
119
|
+
enumerable: true,
|
|
120
|
+
get: function() {
|
|
121
|
+
return _generaltranslation_react_core_pure.getTranslationsSnapshot;
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
Object.defineProperty(exports, "gtFallback", {
|
|
125
|
+
enumerable: true,
|
|
126
|
+
get: function() {
|
|
127
|
+
return _generaltranslation_react_core_pure.gtFallback;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
exports.initializeGT = require_setup_initializeGT.initializeGT;
|
|
131
|
+
Object.defineProperty(exports, "mFallback", {
|
|
132
|
+
enumerable: true,
|
|
133
|
+
get: function() {
|
|
134
|
+
return _generaltranslation_react_core_pure.mFallback;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, "msg", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function() {
|
|
140
|
+
return _generaltranslation_react_core_pure.msg;
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
Object.defineProperty(exports, "setReactI18nCache", {
|
|
144
|
+
enumerable: true,
|
|
145
|
+
get: function() {
|
|
146
|
+
return _generaltranslation_react_core_pure.setReactI18nCache;
|
|
147
|
+
}
|
|
148
|
+
});
|
|
149
|
+
Object.defineProperty(exports, "useCustomMapping", {
|
|
150
|
+
enumerable: true,
|
|
151
|
+
get: function() {
|
|
152
|
+
return _generaltranslation_react_core_hooks.useCustomMapping;
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
Object.defineProperty(exports, "useDefaultLocale", {
|
|
156
|
+
enumerable: true,
|
|
157
|
+
get: function() {
|
|
158
|
+
return _generaltranslation_react_core_hooks.useDefaultLocale;
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
Object.defineProperty(exports, "useEnableI18n", {
|
|
162
|
+
enumerable: true,
|
|
163
|
+
get: function() {
|
|
164
|
+
return _generaltranslation_react_core_hooks.useEnableI18n;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
Object.defineProperty(exports, "useFormatLocales", {
|
|
168
|
+
enumerable: true,
|
|
169
|
+
get: function() {
|
|
170
|
+
return _generaltranslation_react_core_hooks.useFormatLocales;
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
Object.defineProperty(exports, "useGT", {
|
|
174
|
+
enumerable: true,
|
|
175
|
+
get: function() {
|
|
176
|
+
return _generaltranslation_react_core_hooks.useGT;
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
Object.defineProperty(exports, "useGTClass", {
|
|
180
|
+
enumerable: true,
|
|
181
|
+
get: function() {
|
|
182
|
+
return _generaltranslation_react_core_hooks.useGTClass;
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
Object.defineProperty(exports, "useLocale", {
|
|
186
|
+
enumerable: true,
|
|
187
|
+
get: function() {
|
|
188
|
+
return _generaltranslation_react_core_hooks.useLocale;
|
|
189
|
+
}
|
|
190
|
+
});
|
|
191
|
+
exports.useLocaleDirection = require_hooks_utils.useLocaleDirection;
|
|
192
|
+
Object.defineProperty(exports, "useLocaleProperties", {
|
|
193
|
+
enumerable: true,
|
|
194
|
+
get: function() {
|
|
195
|
+
return _generaltranslation_react_core_hooks.useLocaleProperties;
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
exports.useLocaleSelector = require_hooks_selectors.useLocaleSelector;
|
|
199
|
+
Object.defineProperty(exports, "useLocales", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
get: function() {
|
|
202
|
+
return _generaltranslation_react_core_hooks.useLocales;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(exports, "useMessages", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
get: function() {
|
|
208
|
+
return _generaltranslation_react_core_hooks.useMessages;
|
|
209
|
+
}
|
|
210
|
+
});
|
|
211
|
+
Object.defineProperty(exports, "useRegion", {
|
|
212
|
+
enumerable: true,
|
|
213
|
+
get: function() {
|
|
214
|
+
return _generaltranslation_react_core_hooks.useRegion;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
exports.useRegionSelector = require_hooks_selectors.useRegionSelector;
|
|
218
|
+
exports.useSetEnableI18n = require_hooks_condition_store.useSetEnableI18n;
|
|
219
|
+
exports.useSetLocale = require_hooks_condition_store.useSetLocale;
|
|
220
|
+
exports.useSetRegion = require_hooks_condition_store.useSetRegion;
|
|
221
|
+
Object.defineProperty(exports, "useTranslations", {
|
|
222
|
+
enumerable: true,
|
|
223
|
+
get: function() {
|
|
224
|
+
return _generaltranslation_react_core_hooks.useTranslations;
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
exports.useVersionId = require_hooks_utils.useVersionId;
|
|
@@ -1,26 +1,75 @@
|
|
|
1
|
-
Object.
|
|
2
|
-
__esModule: { value: true },
|
|
3
|
-
[Symbol.toStringTag]: { value: "Module" }
|
|
4
|
-
});
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
5
2
|
require("../_virtual/_rolldown/runtime.js");
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
3
|
+
const require_utils_resolveLocale = require("../utils/resolveLocale.js");
|
|
4
|
+
const require_utils_getLocale = require("../utils/getLocale.js");
|
|
5
|
+
const require_utils_getInitialNativeConditions = require("../utils/getInitialNativeConditions.js");
|
|
6
|
+
const require_provider_loadTranslations = require("./loadTranslations.js");
|
|
7
|
+
const require_provider_NativeGTProvider = require("./NativeGTProvider.js");
|
|
8
|
+
let react_native = require("react-native");
|
|
9
|
+
let react = require("react");
|
|
10
10
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
11
|
//#region src/provider/GTProvider.tsx
|
|
12
12
|
function GTProvider(props) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const { loadingFallback, ...providerProps } = props;
|
|
14
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.Suspense, {
|
|
15
|
+
fallback: loadingFallback ?? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DefaultLoadingFallback, {}),
|
|
16
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(LoadableGTProvider, { ...providerProps })
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* This wrapper takes the place of a loader that would be present in
|
|
21
|
+
* SSR style applications.
|
|
22
|
+
*/
|
|
23
|
+
function LoadableGTProvider(props) {
|
|
24
|
+
const { locale, localeStoreKey, region, regionStoreKey, enableI18n, enableI18nStoreKey } = props;
|
|
25
|
+
const [nativeConditions, setNativeConditions] = (0, react.useState)(() => ({
|
|
26
|
+
locale: require_utils_getLocale.getLocale({ localeStoreKey }),
|
|
27
|
+
region: require_utils_getInitialNativeConditions.getInitialRegion({
|
|
28
|
+
region,
|
|
29
|
+
regionStoreKey
|
|
30
|
+
}),
|
|
31
|
+
enableI18n: require_utils_getInitialNativeConditions.getInitialEnableI18n({
|
|
32
|
+
enableI18n,
|
|
33
|
+
enableI18nStoreKey
|
|
34
|
+
})
|
|
35
|
+
}));
|
|
36
|
+
const activeLocale = require_utils_resolveLocale.resolveLocale(locale ?? nativeConditions.locale);
|
|
37
|
+
const activeRegion = region ?? nativeConditions.region;
|
|
38
|
+
const activeEnableI18n = enableI18n ?? nativeConditions.enableI18n;
|
|
39
|
+
const localeTranslations = (0, react.use)(require_provider_loadTranslations.loadTranslations(activeLocale));
|
|
40
|
+
const translations = (0, react.useMemo)(() => ({ [activeLocale]: localeTranslations }), [activeLocale, localeTranslations]);
|
|
41
|
+
const reload = (0, react.useCallback)((state) => {
|
|
42
|
+
setNativeConditions((previousState) => ({
|
|
43
|
+
locale: locale === void 0 ? state.locale : previousState.locale,
|
|
44
|
+
region: region === void 0 ? state.region : previousState.region,
|
|
45
|
+
enableI18n: enableI18n === void 0 ? state.enableI18n : previousState.enableI18n
|
|
46
|
+
}));
|
|
47
|
+
}, [
|
|
48
|
+
enableI18n,
|
|
49
|
+
locale,
|
|
50
|
+
region
|
|
51
|
+
]);
|
|
52
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_provider_NativeGTProvider.NativeGTProvider, {
|
|
16
53
|
...props,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
54
|
+
locale: activeLocale,
|
|
55
|
+
region: activeRegion,
|
|
56
|
+
enableI18n: activeEnableI18n,
|
|
57
|
+
translations,
|
|
58
|
+
_reload: reload
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function DefaultLoadingFallback() {
|
|
62
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
|
|
63
|
+
style: styles.loadingContainer,
|
|
64
|
+
children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.ActivityIndicator, {})
|
|
20
65
|
});
|
|
21
66
|
}
|
|
67
|
+
const styles = react_native.StyleSheet.create({ loadingContainer: {
|
|
68
|
+
flex: 1,
|
|
69
|
+
alignItems: "center",
|
|
70
|
+
justifyContent: "center"
|
|
71
|
+
} });
|
|
22
72
|
//#endregion
|
|
23
73
|
exports.GTProvider = GTProvider;
|
|
24
|
-
exports.default = GTProvider;
|
|
25
74
|
|
|
26
75
|
//# sourceMappingURL=GTProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GTProvider.js","names":["
|
|
1
|
+
{"version":3,"file":"GTProvider.js","names":["Suspense","getLocale","getInitialRegion","getInitialEnableI18n","resolveLocale","loadTranslations","NativeGTProvider","View","ActivityIndicator","StyleSheet"],"sources":["../../../src/provider/GTProvider.tsx"],"sourcesContent":["import type { InternalGTProviderProps } from '@generaltranslation/react-core/components';\nimport { Suspense, use, useCallback, useMemo, useState } from 'react';\nimport type { ReactNode } from 'react';\nimport { ActivityIndicator, StyleSheet, View } from 'react-native';\nimport type { LocaleCandidates, Locale } from 'gt-i18n/internal/types';\nimport type {\n NativeConditionStoreParams,\n NativeConditionStoreState,\n} from '../condition-store/NativeConditionStore';\nimport { getLocale } from '../utils/getLocale';\nimport {\n getInitialEnableI18n,\n getInitialRegion,\n} from '../utils/getInitialNativeConditions';\nimport { resolveLocale } from '../utils/resolveLocale';\nimport { loadTranslations, type LocaleTranslations } from './loadTranslations';\nimport { NativeGTProvider } from './NativeGTProvider';\n\nexport type GTProviderProps = Omit<\n InternalGTProviderProps,\n 'conditionStore' | 'i18nStore' | 'translations'\n> &\n Omit<NativeConditionStoreParams, 'locale' | '_reload'> & {\n children?: ReactNode;\n locale?: LocaleCandidates;\n loadingFallback?: ReactNode;\n };\n\ntype LoadableGTProviderProps = Omit<GTProviderProps, 'loadingFallback'>;\ntype TranslationSnapshot = Record<Locale, LocaleTranslations>;\n\nexport function GTProvider(props: GTProviderProps) {\n const { loadingFallback, ...providerProps } = props;\n\n return (\n <Suspense fallback={loadingFallback ?? <DefaultLoadingFallback />}>\n <LoadableGTProvider {...providerProps} />\n </Suspense>\n );\n}\n\n/**\n * This wrapper takes the place of a loader that would be present in\n * SSR style applications.\n */\nfunction LoadableGTProvider(props: LoadableGTProviderProps) {\n const {\n locale,\n localeStoreKey,\n region,\n regionStoreKey,\n enableI18n,\n enableI18nStoreKey,\n } = props;\n // Keep native conditions in React state so condition-store writes trigger rerenders.\n const [nativeConditions, setNativeConditions] =\n useState<NativeConditionStoreState>(() => ({\n locale: getLocale({ localeStoreKey }),\n region: getInitialRegion({ region, regionStoreKey }),\n enableI18n: getInitialEnableI18n({ enableI18n, enableI18nStoreKey }),\n }));\n const activeLocale = resolveLocale(locale ?? nativeConditions.locale);\n const activeRegion = region ?? nativeConditions.region;\n const activeEnableI18n = enableI18n ?? nativeConditions.enableI18n;\n const localeTranslations = use(loadTranslations(activeLocale));\n const translations = useMemo<TranslationSnapshot>(\n () => ({ [activeLocale]: localeTranslations }),\n [activeLocale, localeTranslations]\n );\n const reload = useCallback(\n (state: NativeConditionStoreState) => {\n setNativeConditions((previousState) => ({\n locale: locale === undefined ? state.locale : previousState.locale,\n region: region === undefined ? state.region : previousState.region,\n enableI18n:\n enableI18n === undefined\n ? state.enableI18n\n : previousState.enableI18n,\n }));\n },\n [enableI18n, locale, region]\n );\n\n return (\n <NativeGTProvider\n {...props}\n locale={activeLocale}\n region={activeRegion}\n enableI18n={activeEnableI18n}\n translations={translations}\n _reload={reload}\n />\n );\n}\n\nfunction DefaultLoadingFallback() {\n return (\n <View style={styles.loadingContainer}>\n <ActivityIndicator />\n </View>\n );\n}\n\nconst styles = StyleSheet.create({\n loadingContainer: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n },\n});\n"],"mappings":";;;;;;;;;;;AA+BA,SAAgB,WAAW,OAAwB;CACjD,MAAM,EAAE,iBAAiB,GAAG,kBAAkB;AAE9C,QACE,iBAAA,GAAA,kBAAA,KAACA,MAAAA,UAAD;EAAU,UAAU,mBAAmB,iBAAA,GAAA,kBAAA,KAAC,wBAAD,EAA0B,CAAA;YAC/D,iBAAA,GAAA,kBAAA,KAAC,oBAAD,EAAoB,GAAI,eAAiB,CAAA;EAChC,CAAA;;;;;;AAQf,SAAS,mBAAmB,OAAgC;CAC1D,MAAM,EACJ,QACA,gBACA,QACA,gBACA,YACA,uBACE;CAEJ,MAAM,CAAC,kBAAkB,wBAAA,GAAA,MAAA,iBACoB;EACzC,QAAQC,wBAAAA,UAAU,EAAE,gBAAgB,CAAC;EACrC,QAAQC,yCAAAA,iBAAiB;GAAE;GAAQ;GAAgB,CAAC;EACpD,YAAYC,yCAAAA,qBAAqB;GAAE;GAAY;GAAoB,CAAC;EACrE,EAAE;CACL,MAAM,eAAeC,4BAAAA,cAAc,UAAU,iBAAiB,OAAO;CACrE,MAAM,eAAe,UAAU,iBAAiB;CAChD,MAAM,mBAAmB,cAAc,iBAAiB;CACxD,MAAM,sBAAA,GAAA,MAAA,KAAyBC,kCAAAA,iBAAiB,aAAa,CAAC;CAC9D,MAAM,gBAAA,GAAA,MAAA,gBACG,GAAG,eAAe,oBAAoB,GAC7C,CAAC,cAAc,mBAAmB,CACnC;CACD,MAAM,UAAA,GAAA,MAAA,cACH,UAAqC;AACpC,uBAAqB,mBAAmB;GACtC,QAAQ,WAAW,KAAA,IAAY,MAAM,SAAS,cAAc;GAC5D,QAAQ,WAAW,KAAA,IAAY,MAAM,SAAS,cAAc;GAC5D,YACE,eAAe,KAAA,IACX,MAAM,aACN,cAAc;GACrB,EAAE;IAEL;EAAC;EAAY;EAAQ;EAAO,CAC7B;AAED,QACE,iBAAA,GAAA,kBAAA,KAACC,kCAAAA,kBAAD;EACE,GAAI;EACJ,QAAQ;EACR,QAAQ;EACR,YAAY;EACE;EACd,SAAS;EACT,CAAA;;AAIN,SAAS,yBAAyB;AAChC,QACE,iBAAA,GAAA,kBAAA,KAACC,aAAAA,MAAD;EAAM,OAAO,OAAO;YAClB,iBAAA,GAAA,kBAAA,KAACC,aAAAA,mBAAD,EAAqB,CAAA;EAChB,CAAA;;AAIX,MAAM,SAASC,aAAAA,WAAW,OAAO,EAC/B,kBAAkB;CAChB,MAAM;CACN,YAAY;CACZ,gBAAgB;CACjB,EACF,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
require("../_virtual/_rolldown/runtime.js");
|
|
3
|
+
const require_condition_store_NativeConditionStore = require("../condition-store/NativeConditionStore.js");
|
|
4
|
+
let react = require("react");
|
|
5
|
+
let _generaltranslation_react_core_components = require("@generaltranslation/react-core/components");
|
|
6
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
7
|
+
//#region src/provider/NativeGTProvider.tsx
|
|
8
|
+
function NativeGTProvider(props) {
|
|
9
|
+
const conditionStore = (0, react.useMemo)(() => {
|
|
10
|
+
return new require_condition_store_NativeConditionStore.NativeConditionStore(props);
|
|
11
|
+
}, [
|
|
12
|
+
props.locale,
|
|
13
|
+
props.region,
|
|
14
|
+
props.enableI18n,
|
|
15
|
+
props.localeStoreKey,
|
|
16
|
+
props.regionStoreKey,
|
|
17
|
+
props.enableI18nStoreKey,
|
|
18
|
+
props._reload
|
|
19
|
+
]);
|
|
20
|
+
const i18nStoreRef = (0, react.useRef)(null);
|
|
21
|
+
if (i18nStoreRef.current == null) i18nStoreRef.current = new _generaltranslation_react_core_components.I18nStore();
|
|
22
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_generaltranslation_react_core_components.InternalGTProvider, {
|
|
23
|
+
...props,
|
|
24
|
+
conditionStore,
|
|
25
|
+
i18nStore: i18nStoreRef.current
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
exports.NativeGTProvider = NativeGTProvider;
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=NativeGTProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NativeGTProvider.js","names":["NativeConditionStore","I18nStore","InternalGTProvider"],"sources":["../../../src/provider/NativeGTProvider.tsx"],"sourcesContent":["import {\n I18nStore,\n InternalGTProvider,\n type InternalGTProviderProps,\n} from '@generaltranslation/react-core/components';\nimport { useMemo, useRef } from 'react';\nimport type { LocaleCandidates } from 'gt-i18n/internal/types';\nimport type { NativeConditionStoreParams } from '../condition-store/NativeConditionStore';\nimport { NativeConditionStore } from '../condition-store/NativeConditionStore';\n\nexport type NativeGTProviderProps = Omit<\n InternalGTProviderProps,\n 'conditionStore' | 'i18nStore'\n> &\n Omit<NativeConditionStoreParams, 'locale'> & {\n locale: LocaleCandidates;\n };\n\nexport function NativeGTProvider(props: NativeGTProviderProps) {\n const conditionStore = useMemo(() => {\n return new NativeConditionStore(props);\n }, [\n props.locale,\n props.region,\n props.enableI18n,\n props.localeStoreKey,\n props.regionStoreKey,\n props.enableI18nStoreKey,\n props._reload,\n ]);\n\n const i18nStoreRef = useRef<I18nStore | null>(null);\n if (i18nStoreRef.current == null) {\n i18nStoreRef.current = new I18nStore();\n }\n\n return (\n <InternalGTProvider\n {...props}\n conditionStore={conditionStore}\n i18nStore={i18nStoreRef.current}\n />\n );\n}\n"],"mappings":";;;;;;;AAkBA,SAAgB,iBAAiB,OAA8B;CAC7D,MAAM,kBAAA,GAAA,MAAA,eAA+B;AACnC,SAAO,IAAIA,6CAAAA,qBAAqB,MAAM;IACrC;EACD,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACP,CAAC;CAEF,MAAM,gBAAA,GAAA,MAAA,QAAwC,KAAK;AACnD,KAAI,aAAa,WAAW,KAC1B,cAAa,UAAU,IAAIC,0CAAAA,WAAW;AAGxC,QACE,iBAAA,GAAA,kBAAA,KAACC,0CAAAA,oBAAD;EACE,GAAI;EACY;EAChB,WAAW,aAAa;EACxB,CAAA"}
|