gt-react-native 10.20.4 → 11.0.0-odysseus.1

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.
Files changed (115) hide show
  1. package/README.md +26 -3
  2. package/dist/commonjs/condition-store/NativeConditionStore.js +80 -0
  3. package/dist/commonjs/condition-store/NativeConditionStore.js.map +1 -0
  4. package/dist/commonjs/hooks/condition-store.js +38 -0
  5. package/dist/commonjs/hooks/condition-store.js.map +1 -0
  6. package/dist/commonjs/hooks/selectors.js +23 -0
  7. package/dist/commonjs/hooks/selectors.js.map +1 -0
  8. package/dist/commonjs/hooks/utils.js +17 -0
  9. package/dist/commonjs/hooks/utils.js.map +1 -0
  10. package/dist/commonjs/index.js +221 -32
  11. package/dist/commonjs/provider/GTProvider.js +64 -15
  12. package/dist/commonjs/provider/GTProvider.js.map +1 -1
  13. package/dist/commonjs/provider/NativeGTProvider.js +31 -0
  14. package/dist/commonjs/provider/NativeGTProvider.js.map +1 -0
  15. package/dist/commonjs/provider/loadTranslations.js +27 -0
  16. package/dist/commonjs/provider/loadTranslations.js.map +1 -0
  17. package/dist/commonjs/setup/initializeGT.js +14 -0
  18. package/dist/commonjs/setup/initializeGT.js.map +1 -0
  19. package/dist/commonjs/utils/getInitialNativeConditions.js +20 -0
  20. package/dist/commonjs/utils/getInitialNativeConditions.js.map +1 -0
  21. package/dist/commonjs/utils/getLocale.js +28 -0
  22. package/dist/commonjs/utils/getLocale.js.map +1 -0
  23. package/dist/commonjs/utils/nativeStore.js +3 -3
  24. package/dist/commonjs/utils/nativeStore.js.map +1 -1
  25. package/dist/commonjs/utils/resolveLocale.js +12 -0
  26. package/dist/commonjs/utils/resolveLocale.js.map +1 -0
  27. package/dist/commonjs/utils/utils.js.map +1 -1
  28. package/dist/module/condition-store/NativeConditionStore.d.ts +35 -0
  29. package/dist/module/condition-store/NativeConditionStore.d.ts.map +1 -0
  30. package/dist/module/condition-store/NativeConditionStore.js +78 -0
  31. package/dist/module/condition-store/NativeConditionStore.js.map +1 -0
  32. package/dist/module/hooks/condition-store.d.ts +13 -0
  33. package/dist/module/hooks/condition-store.d.ts.map +1 -0
  34. package/dist/module/hooks/condition-store.js +34 -0
  35. package/dist/module/hooks/condition-store.js.map +1 -0
  36. package/dist/module/hooks/selectors.d.ts +39 -0
  37. package/dist/module/hooks/selectors.d.ts.map +1 -0
  38. package/dist/module/hooks/selectors.js +20 -0
  39. package/dist/module/hooks/selectors.js.map +1 -0
  40. package/dist/module/hooks/utils.d.ts +3 -0
  41. package/dist/module/hooks/utils.d.ts.map +1 -0
  42. package/dist/module/hooks/utils.js +14 -0
  43. package/dist/module/hooks/utils.js.map +1 -0
  44. package/dist/module/index.d.ts +16 -3
  45. package/dist/module/index.d.ts.map +1 -1
  46. package/dist/module/index.js +9 -2
  47. package/dist/module/provider/GTProvider.d.ts +10 -3
  48. package/dist/module/provider/GTProvider.d.ts.map +1 -1
  49. package/dist/module/provider/GTProvider.js +64 -11
  50. package/dist/module/provider/GTProvider.js.map +1 -1
  51. package/dist/module/provider/NativeGTProvider.d.ts +8 -0
  52. package/dist/module/provider/NativeGTProvider.d.ts.map +1 -0
  53. package/dist/module/provider/NativeGTProvider.js +29 -0
  54. package/dist/module/provider/NativeGTProvider.js.map +1 -0
  55. package/dist/module/provider/loadTranslations.d.ts +5 -0
  56. package/dist/module/provider/loadTranslations.d.ts.map +1 -0
  57. package/dist/module/provider/loadTranslations.js +25 -0
  58. package/dist/module/provider/loadTranslations.js.map +1 -0
  59. package/dist/module/setup/initializeGT.d.ts +5 -0
  60. package/dist/module/setup/initializeGT.d.ts.map +1 -0
  61. package/dist/module/setup/initializeGT.js +12 -0
  62. package/dist/module/setup/initializeGT.js.map +1 -0
  63. package/dist/module/utils/getInitialNativeConditions.d.ts +11 -0
  64. package/dist/module/utils/getInitialNativeConditions.d.ts.map +1 -0
  65. package/dist/module/utils/getInitialNativeConditions.js +17 -0
  66. package/dist/module/utils/getInitialNativeConditions.js.map +1 -0
  67. package/dist/module/utils/getLocale.d.ts +8 -0
  68. package/dist/module/utils/getLocale.d.ts.map +1 -0
  69. package/dist/module/utils/getLocale.js +26 -0
  70. package/dist/module/utils/getLocale.js.map +1 -0
  71. package/dist/module/utils/nativeStore.d.ts +1 -1
  72. package/dist/module/utils/nativeStore.d.ts.map +1 -1
  73. package/dist/module/utils/nativeStore.js +2 -2
  74. package/dist/module/utils/nativeStore.js.map +1 -1
  75. package/dist/module/utils/resolveLocale.d.ts +3 -0
  76. package/dist/module/utils/resolveLocale.d.ts.map +1 -0
  77. package/dist/module/utils/resolveLocale.js +10 -0
  78. package/dist/module/utils/resolveLocale.js.map +1 -0
  79. package/dist/module/utils/utils.d.ts +1 -1
  80. package/dist/module/utils/utils.d.ts.map +1 -1
  81. package/dist/module/utils/utils.js.map +1 -1
  82. package/package.json +8 -7
  83. package/src/condition-store/NativeConditionStore.ts +128 -0
  84. package/src/hooks/condition-store.ts +41 -0
  85. package/src/hooks/selectors.ts +17 -0
  86. package/src/hooks/utils.ts +14 -0
  87. package/src/index.tsx +74 -56
  88. package/src/provider/GTProvider.tsx +103 -13
  89. package/src/provider/NativeGTProvider.tsx +44 -0
  90. package/src/provider/loadTranslations.ts +34 -0
  91. package/src/setup/initializeGT.ts +23 -0
  92. package/src/utils/getInitialNativeConditions.ts +35 -0
  93. package/src/utils/getLocale.ts +34 -0
  94. package/src/utils/nativeStore.ts +3 -3
  95. package/src/utils/resolveLocale.ts +10 -0
  96. package/src/utils/utils.ts +1 -1
  97. package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js +0 -102
  98. package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js.map +0 -1
  99. package/dist/commonjs/provider/hooks/useRegionState.js +0 -35
  100. package/dist/commonjs/provider/hooks/useRegionState.js.map +0 -1
  101. package/dist/commonjs/types/config.js +0 -1
  102. package/dist/module/provider/hooks/locale/useDetermineLocale.d.ts +0 -4
  103. package/dist/module/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
  104. package/dist/module/provider/hooks/locale/useDetermineLocale.js +0 -100
  105. package/dist/module/provider/hooks/locale/useDetermineLocale.js.map +0 -1
  106. package/dist/module/provider/hooks/useRegionState.d.ts +0 -3
  107. package/dist/module/provider/hooks/useRegionState.d.ts.map +0 -1
  108. package/dist/module/provider/hooks/useRegionState.js +0 -33
  109. package/dist/module/provider/hooks/useRegionState.js.map +0 -1
  110. package/dist/module/types/config.d.ts +0 -30
  111. package/dist/module/types/config.d.ts.map +0 -1
  112. package/dist/module/types/config.js +0 -1
  113. package/src/provider/hooks/locale/useDetermineLocale.ts +0 -220
  114. package/src/provider/hooks/useRegionState.ts +0 -51
  115. package/src/types/config.ts +0 -36
@@ -1,20 +1,73 @@
1
- import { useDetermineLocale } from "./hooks/locale/useDetermineLocale.js";
2
- import { readAuthFromEnv } from "../utils/utils.js";
3
- import { useRegionState } from "./hooks/useRegionState.js";
4
- import { GTProvider as GTProvider$1 } from "@generaltranslation/react-core";
1
+ import { resolveLocale } from "../utils/resolveLocale.js";
2
+ import { getLocale } from "../utils/getLocale.js";
3
+ import { getInitialEnableI18n, getInitialRegion } from "../utils/getInitialNativeConditions.js";
4
+ import { loadTranslations } from "./loadTranslations.js";
5
+ import { NativeGTProvider } from "./NativeGTProvider.js";
6
+ import { ActivityIndicator, StyleSheet, View } from "react-native";
7
+ import { Suspense, use, useCallback, useMemo, useState } from "react";
5
8
  import { jsx } from "react/jsx-runtime";
6
9
  //#region src/provider/GTProvider.tsx
7
10
  function GTProvider(props) {
8
- return /* @__PURE__ */ jsx(GTProvider$1, {
9
- ssr: false,
10
- environment: __DEV__ ? "development" : "production",
11
+ const { loadingFallback, ...providerProps } = props;
12
+ return /* @__PURE__ */ jsx(Suspense, {
13
+ fallback: loadingFallback ?? /* @__PURE__ */ jsx(DefaultLoadingFallback, {}),
14
+ children: /* @__PURE__ */ jsx(LoadableGTProvider, { ...providerProps })
15
+ });
16
+ }
17
+ /**
18
+ * This wrapper takes the place of a loader that would be present in
19
+ * SSR style applications.
20
+ */
21
+ function LoadableGTProvider(props) {
22
+ const { locale, localeStoreKey, region, regionStoreKey, enableI18n, enableI18nStoreKey } = props;
23
+ const [nativeConditions, setNativeConditions] = useState(() => ({
24
+ locale: getLocale({ localeStoreKey }),
25
+ region: getInitialRegion({
26
+ region,
27
+ regionStoreKey
28
+ }),
29
+ enableI18n: getInitialEnableI18n({
30
+ enableI18n,
31
+ enableI18nStoreKey
32
+ })
33
+ }));
34
+ const activeLocale = resolveLocale(locale ?? nativeConditions.locale);
35
+ const activeRegion = region ?? nativeConditions.region;
36
+ const activeEnableI18n = enableI18n ?? nativeConditions.enableI18n;
37
+ const localeTranslations = use(loadTranslations(activeLocale));
38
+ const translations = useMemo(() => ({ [activeLocale]: localeTranslations }), [activeLocale, localeTranslations]);
39
+ const reload = useCallback((state) => {
40
+ setNativeConditions((previousState) => ({
41
+ locale: locale === void 0 ? state.locale : previousState.locale,
42
+ region: region === void 0 ? state.region : previousState.region,
43
+ enableI18n: enableI18n === void 0 ? state.enableI18n : previousState.enableI18n
44
+ }));
45
+ }, [
46
+ enableI18n,
47
+ locale,
48
+ region
49
+ ]);
50
+ return /* @__PURE__ */ jsx(NativeGTProvider, {
11
51
  ...props,
12
- readAuthFromEnv,
13
- useDetermineLocale,
14
- useRegionState
52
+ locale: activeLocale,
53
+ region: activeRegion,
54
+ enableI18n: activeEnableI18n,
55
+ translations,
56
+ _reload: reload
57
+ });
58
+ }
59
+ function DefaultLoadingFallback() {
60
+ return /* @__PURE__ */ jsx(View, {
61
+ style: styles.loadingContainer,
62
+ children: /* @__PURE__ */ jsx(ActivityIndicator, {})
15
63
  });
16
64
  }
65
+ const styles = StyleSheet.create({ loadingContainer: {
66
+ flex: 1,
67
+ alignItems: "center",
68
+ justifyContent: "center"
69
+ } });
17
70
  //#endregion
18
- export { GTProvider, GTProvider as default };
71
+ export { GTProvider };
19
72
 
20
73
  //# sourceMappingURL=GTProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"GTProvider.js","names":["_GTProvider"],"sources":["../../../src/provider/GTProvider.tsx"],"sourcesContent":["import { useDetermineLocale } from './hooks/locale/useDetermineLocale';\nimport type { GTProviderProps } from '../types/config';\nimport { GTProvider as _GTProvider } from '@generaltranslation/react-core';\nimport { readAuthFromEnv } from '../utils/utils';\nimport { useRegionState } from './hooks/useRegionState';\n\nexport function GTProvider(props: GTProviderProps): React.JSX.Element {\n return (\n <_GTProvider\n ssr={false}\n environment={__DEV__ ? 'development' : 'production'}\n {...props}\n readAuthFromEnv={readAuthFromEnv}\n useDetermineLocale={useDetermineLocale}\n useRegionState={useRegionState}\n />\n );\n}\n\nexport default GTProvider;\n"],"mappings":";;;;;;AAMA,SAAgB,WAAW,OAA2C;AACpE,QACE,oBAACA,cAAD;EACE,KAAK;EACL,aAAa,UAAU,gBAAgB;EACvC,GAAI;EACa;EACG;EACJ;EAChB,CAAA"}
1
+ {"version":3,"file":"GTProvider.js","names":[],"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,oBAAC,UAAD;EAAU,UAAU,mBAAmB,oBAAC,wBAAD,EAA0B,CAAA;YAC/D,oBAAC,oBAAD,EAAoB,GAAI,eAAiB,CAAA;EAChC,CAAA;;;;;;AAQf,SAAS,mBAAmB,OAAgC;CAC1D,MAAM,EACJ,QACA,gBACA,QACA,gBACA,YACA,uBACE;CAEJ,MAAM,CAAC,kBAAkB,uBACvB,gBAA2C;EACzC,QAAQ,UAAU,EAAE,gBAAgB,CAAC;EACrC,QAAQ,iBAAiB;GAAE;GAAQ;GAAgB,CAAC;EACpD,YAAY,qBAAqB;GAAE;GAAY;GAAoB,CAAC;EACrE,EAAE;CACL,MAAM,eAAe,cAAc,UAAU,iBAAiB,OAAO;CACrE,MAAM,eAAe,UAAU,iBAAiB;CAChD,MAAM,mBAAmB,cAAc,iBAAiB;CACxD,MAAM,qBAAqB,IAAI,iBAAiB,aAAa,CAAC;CAC9D,MAAM,eAAe,eACZ,GAAG,eAAe,oBAAoB,GAC7C,CAAC,cAAc,mBAAmB,CACnC;CACD,MAAM,SAAS,aACZ,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,oBAAC,kBAAD;EACE,GAAI;EACJ,QAAQ;EACR,QAAQ;EACR,YAAY;EACE;EACd,SAAS;EACT,CAAA;;AAIN,SAAS,yBAAyB;AAChC,QACE,oBAAC,MAAD;EAAM,OAAO,OAAO;YAClB,oBAAC,mBAAD,EAAqB,CAAA;EAChB,CAAA;;AAIX,MAAM,SAAS,WAAW,OAAO,EAC/B,kBAAkB;CAChB,MAAM;CACN,YAAY;CACZ,gBAAgB;CACjB,EACF,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { type InternalGTProviderProps } from '@generaltranslation/react-core/components';
2
+ import type { LocaleCandidates } from 'gt-i18n/internal/types';
3
+ import type { NativeConditionStoreParams } from '../condition-store/NativeConditionStore';
4
+ export type NativeGTProviderProps = Omit<InternalGTProviderProps, 'conditionStore' | 'i18nStore'> & Omit<NativeConditionStoreParams, 'locale'> & {
5
+ locale: LocaleCandidates;
6
+ };
7
+ export declare function NativeGTProvider(props: NativeGTProviderProps): import("react/jsx-runtime").JSX.Element;
8
+ //# sourceMappingURL=NativeGTProvider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeGTProvider.d.ts","sourceRoot":"","sources":["../../../src/provider/NativeGTProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,2CAA2C,CAAC;AAEnD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAG1F,MAAM,MAAM,qBAAqB,GAAG,IAAI,CACtC,uBAAuB,EACvB,gBAAgB,GAAG,WAAW,CAC/B,GACC,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,GAAG;IAC3C,MAAM,EAAE,gBAAgB,CAAC;CAC1B,CAAC;AAEJ,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,qBAAqB,2CAyB5D"}
@@ -0,0 +1,29 @@
1
+ import { NativeConditionStore } from "../condition-store/NativeConditionStore.js";
2
+ import { useMemo, useRef } from "react";
3
+ import { I18nStore, InternalGTProvider } from "@generaltranslation/react-core/components";
4
+ import { jsx } from "react/jsx-runtime";
5
+ //#region src/provider/NativeGTProvider.tsx
6
+ function NativeGTProvider(props) {
7
+ const conditionStore = useMemo(() => {
8
+ return new NativeConditionStore(props);
9
+ }, [
10
+ props.locale,
11
+ props.region,
12
+ props.enableI18n,
13
+ props.localeStoreKey,
14
+ props.regionStoreKey,
15
+ props.enableI18nStoreKey,
16
+ props._reload
17
+ ]);
18
+ const i18nStoreRef = useRef(null);
19
+ if (i18nStoreRef.current == null) i18nStoreRef.current = new I18nStore();
20
+ return /* @__PURE__ */ jsx(InternalGTProvider, {
21
+ ...props,
22
+ conditionStore,
23
+ i18nStore: i18nStoreRef.current
24
+ });
25
+ }
26
+ //#endregion
27
+ export { NativeGTProvider };
28
+
29
+ //# sourceMappingURL=NativeGTProvider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"NativeGTProvider.js","names":[],"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,iBAAiB,cAAc;AACnC,SAAO,IAAI,qBAAqB,MAAM;IACrC;EACD,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACN,MAAM;EACP,CAAC;CAEF,MAAM,eAAe,OAAyB,KAAK;AACnD,KAAI,aAAa,WAAW,KAC1B,cAAa,UAAU,IAAI,WAAW;AAGxC,QACE,oBAAC,oBAAD;EACE,GAAI;EACY;EAChB,WAAW,aAAa;EACxB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import type { Hash } from 'gt-i18n/internal/types';
2
+ import type { Translation } from 'gt-i18n/types';
3
+ export type LocaleTranslations = Record<Hash, Translation>;
4
+ export declare function loadTranslations(locale: string): Promise<LocaleTranslations>;
5
+ //# sourceMappingURL=loadTranslations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"loadTranslations.d.ts","sourceRoot":"","sources":["../../../src/provider/loadTranslations.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAEjD,MAAM,MAAM,kBAAkB,GAAG,MAAM,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;AAO3D,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAsB5E"}
@@ -0,0 +1,25 @@
1
+ import { getReactI18nCache } from "@generaltranslation/react-core/pure";
2
+ //#region src/provider/loadTranslations.ts
3
+ const translationPromises = /* @__PURE__ */ new WeakMap();
4
+ function loadTranslations(locale) {
5
+ const i18nCache = getReactI18nCache();
6
+ let i18nCacheTranslationPromises = translationPromises.get(i18nCache);
7
+ if (i18nCacheTranslationPromises == null) {
8
+ i18nCacheTranslationPromises = /* @__PURE__ */ new Map();
9
+ translationPromises.set(i18nCache, i18nCacheTranslationPromises);
10
+ }
11
+ let promise = i18nCacheTranslationPromises.get(locale);
12
+ if (promise == null) {
13
+ promise = i18nCache.loadTranslations(locale).catch((error) => {
14
+ i18nCacheTranslationPromises.delete(locale);
15
+ console.warn(`Failed to load translations for locale "${locale}". Falling back to an empty translation snapshot.`, error);
16
+ return {};
17
+ });
18
+ i18nCacheTranslationPromises.set(locale, promise);
19
+ }
20
+ return promise;
21
+ }
22
+ //#endregion
23
+ export { loadTranslations };
24
+
25
+ //# 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,YAAY,mBAAmB;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,5 @@
1
+ import type { ReactI18nCacheParams } from '@generaltranslation/react-core/pure';
2
+ import type { GTServicesEnabledParams, I18nConfigParams } from 'gt-i18n/internal/types';
3
+ export type InitializeGTParams = I18nConfigParams & GTServicesEnabledParams & ReactI18nCacheParams;
4
+ export declare function initializeGT(config: InitializeGTParams): void;
5
+ //# sourceMappingURL=initializeGT.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializeGT.d.ts","sourceRoot":"","sources":["../../../src/setup/initializeGT.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qCAAqC,CAAC;AAEhF,OAAO,KAAK,EACV,uBAAuB,EACvB,gBAAgB,EACjB,MAAM,wBAAwB,CAAC;AAEhC,MAAM,MAAM,kBAAkB,GAAG,gBAAgB,GAC/C,uBAAuB,GACvB,oBAAoB,CAAC;AAEvB,wBAAgB,YAAY,CAAC,MAAM,EAAE,kBAAkB,GAAG,IAAI,CAM7D"}
@@ -0,0 +1,12 @@
1
+ import { ReactI18nCache, initializeI18nConfig, setReactI18nCache } from "@generaltranslation/react-core/pure";
2
+ import { setupGTServicesEnabled } from "gt-i18n/internal";
3
+ //#region src/setup/initializeGT.ts
4
+ function initializeGT(config) {
5
+ setupGTServicesEnabled(config);
6
+ initializeI18nConfig(config, "server-render");
7
+ setReactI18nCache(new ReactI18nCache(config));
8
+ }
9
+ //#endregion
10
+ export { initializeGT };
11
+
12
+ //# sourceMappingURL=initializeGT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"initializeGT.js","names":[],"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,wBAAuB,OAAO;AAC9B,sBAAqB,QAAQ,gBAAgB;AAG7C,mBAAkB,IADI,eAAe,OACV,CAAC"}
@@ -0,0 +1,11 @@
1
+ import type { WritableConditionStoreParams } from 'gt-i18n/internal/types';
2
+ type InitialRegionParams = Pick<WritableConditionStoreParams, 'region'> & {
3
+ regionStoreKey?: string;
4
+ };
5
+ type InitialEnableI18nParams = Pick<WritableConditionStoreParams, 'enableI18n'> & {
6
+ enableI18nStoreKey?: string;
7
+ };
8
+ export declare function getInitialRegion({ region, regionStoreKey, }: InitialRegionParams): string | undefined;
9
+ export declare function getInitialEnableI18n({ enableI18n, enableI18nStoreKey, }: InitialEnableI18nParams): boolean;
10
+ export {};
11
+ //# sourceMappingURL=getInitialNativeConditions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInitialNativeConditions.d.ts","sourceRoot":"","sources":["../../../src/utils/getInitialNativeConditions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,wBAAwB,CAAC;AAO3E,KAAK,mBAAmB,GAAG,IAAI,CAAC,4BAA4B,EAAE,QAAQ,CAAC,GAAG;IACxE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,KAAK,uBAAuB,GAAG,IAAI,CACjC,4BAA4B,EAC5B,YAAY,CACb,GAAG;IACF,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,EAC/B,MAAM,EACN,cAAsC,GACvC,EAAE,mBAAmB,GAAG,MAAM,GAAG,SAAS,CAG1C;AAED,wBAAgB,oBAAoB,CAAC,EACnC,UAAU,EACV,kBAA8C,GAC/C,EAAE,uBAAuB,GAAG,OAAO,CAKnC"}
@@ -0,0 +1,17 @@
1
+ import { nativeStoreGet } from "./nativeStore.js";
2
+ import { defaultEnableI18nCookieName, defaultRegionCookieName } from "@generaltranslation/react-core/pure";
3
+ //#region src/utils/getInitialNativeConditions.ts
4
+ function getInitialRegion({ region, regionStoreKey = defaultRegionCookieName }) {
5
+ if (region !== void 0) return region;
6
+ return nativeStoreGet(regionStoreKey) || void 0;
7
+ }
8
+ function getInitialEnableI18n({ enableI18n, enableI18nStoreKey = defaultEnableI18nCookieName }) {
9
+ if (enableI18n !== void 0) return enableI18n;
10
+ const storedEnableI18n = nativeStoreGet(enableI18nStoreKey);
11
+ if (storedEnableI18n === null) return true;
12
+ return storedEnableI18n === "true";
13
+ }
14
+ //#endregion
15
+ export { getInitialEnableI18n, getInitialRegion };
16
+
17
+ //# sourceMappingURL=getInitialNativeConditions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getInitialNativeConditions.js","names":["defaultRegionStoreKey","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,2BACyB;AAC1C,KAAI,WAAW,KAAA,EAAW,QAAO;AACjC,QAAO,eAAe,eAAe,IAAI,KAAA;;AAG3C,SAAgB,qBAAqB,EACnC,YACA,qBAAqBC,+BACc;AACnC,KAAI,eAAe,KAAA,EAAW,QAAO;CACrC,MAAM,mBAAmB,eAAe,mBAAmB;AAC3D,KAAI,qBAAqB,KAAM,QAAO;AACtC,QAAO,qBAAqB"}
@@ -0,0 +1,8 @@
1
+ export type GetLocaleParams = {
2
+ localeStoreKey?: string;
3
+ };
4
+ /**
5
+ * @internal
6
+ */
7
+ export declare function getLocale({ localeStoreKey, }?: GetLocaleParams): string;
8
+ //# sourceMappingURL=getLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocale.d.ts","sourceRoot":"","sources":["../../../src/utils/getLocale.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,SAAS,CAAC,EACxB,cAAsC,GACvC,GAAE,eAAoB,GAAG,MAAM,CAM/B"}
@@ -0,0 +1,26 @@
1
+ import { getNativeLocales } from "./getNativeLocales.js";
2
+ import { nativeStoreGet } from "./nativeStore.js";
3
+ import { resolveLocale } from "./resolveLocale.js";
4
+ import { defaultLocaleCookieName } from "@generaltranslation/react-core/pure";
5
+ //#region src/utils/getLocale.ts
6
+ /**
7
+ * @internal
8
+ */
9
+ function getLocale({ localeStoreKey = defaultLocaleCookieName } = {}) {
10
+ const candidates = [];
11
+ pushLocaleCandidates(candidates, nativeStoreGet(localeStoreKey));
12
+ candidates.push(...getNativeLocales());
13
+ return resolveLocale(candidates);
14
+ }
15
+ function pushLocaleCandidates(target, locale) {
16
+ if (!locale) return;
17
+ if (Array.isArray(locale)) {
18
+ target.push(...locale);
19
+ return;
20
+ }
21
+ target.push(locale);
22
+ }
23
+ //#endregion
24
+ export { getLocale };
25
+
26
+ //# sourceMappingURL=getLocale.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getLocale.js","names":["defaultLocaleStoreKey"],"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,4BACE,EAAE,EAAU;CAC/B,MAAM,aAAuB,EAAE;AAC/B,sBAAqB,YAAY,eAAe,eAAe,CAAC;AAChE,YAAW,KAAK,GAAG,kBAAkB,CAAC;AAEtC,QAAO,cAAc,WAAW;;AAGlC,SAAS,qBACP,QACA,QACA;AACA,KAAI,CAAC,OAAQ;AACb,KAAI,MAAM,QAAQ,OAAO,EAAE;AACzB,SAAO,KAAK,GAAG,OAAO;AACtB;;AAEF,QAAO,KAAK,OAAO"}
@@ -4,7 +4,7 @@
4
4
  * This reads persisted native storage directly, so it can temporarily be out of
5
5
  * sync with React state while a locale change is in progress.
6
6
  *
7
- * If GTProvider uses a custom localeCookieName, pass that same value as the key.
7
+ * If GTProvider uses a custom localeStoreKey, pass that same value as the key.
8
8
  *
9
9
  * @param key - The key to get the locale from
10
10
  * @returns The locale from the native store
@@ -1 +1 @@
1
- {"version":3,"file":"nativeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/nativeStore.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,SAA0B,GAC5B,MAAM,GAAG,IAAI,CAEf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW/D"}
1
+ {"version":3,"file":"nativeStore.d.ts","sourceRoot":"","sources":["../../../src/utils/nativeStore.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CACtC,GAAG,SAAwB,GAC1B,MAAM,GAAG,IAAI,CAEf;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAUzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAW/D"}
@@ -1,7 +1,7 @@
1
1
  import NativeGtReactNative_default from "../NativeGtReactNative.js";
2
2
  import { ssrUnsupportedWarning } from "../errors-dir/warnings.js";
3
3
  import { Platform } from "react-native";
4
- import { defaultLocaleCookieName } from "@generaltranslation/react-core/internal";
4
+ import { defaultLocaleCookieName } from "@generaltranslation/react-core/pure";
5
5
  //#region src/utils/nativeStore.ts
6
6
  /**
7
7
  * Get the locale from the native store.
@@ -9,7 +9,7 @@ import { defaultLocaleCookieName } from "@generaltranslation/react-core/internal
9
9
  * This reads persisted native storage directly, so it can temporarily be out of
10
10
  * sync with React state while a locale change is in progress.
11
11
  *
12
- * If GTProvider uses a custom localeCookieName, pass that same value as the key.
12
+ * If GTProvider uses a custom localeStoreKey, pass that same value as the key.
13
13
  *
14
14
  * @param key - The key to get the locale from
15
15
  * @returns The locale from the native store
@@ -1 +1 @@
1
- {"version":3,"file":"nativeStore.js","names":["GtReactNative"],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { defaultLocaleCookieName } from '@generaltranslation/react-core/internal';\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 localeCookieName, 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 = defaultLocaleCookieName\n): string | null {\n return nativeStoreGet(key);\n}\n\n/**\n * Get a value from the native store\n * @param key - The key to get the value for\n * @returns The value for the key\n */\nexport function nativeStoreGet(key: string): string | null {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return null;\n }\n return localStorage.getItem(key);\n }\n return GtReactNative.nativeStoreGet(key);\n}\n\n/**\n * Set a value in the native store\n * @param key - The key to set the value for\n * @param value - The value to set\n */\nexport function nativeStoreSet(key: string, value: string): void {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return;\n }\n localStorage.setItem(key, value);\n return;\n }\n GtReactNative.nativeStoreSet(key, value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,yBACd,MAAM,yBACS;AACf,QAAO,eAAe,IAAI;;;;;;;AAQ5B,SAAgB,eAAe,KAA4B;AACzD,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC,UAAO;;AAET,SAAO,aAAa,QAAQ,IAAI;;AAElC,QAAOA,4BAAc,eAAe,IAAI;;;;;;;AAQ1C,SAAgB,eAAe,KAAa,OAAqB;AAC/D,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC;;AAEF,eAAa,QAAQ,KAAK,MAAM;AAChC;;AAEF,6BAAc,eAAe,KAAK,MAAM"}
1
+ {"version":3,"file":"nativeStore.js","names":["defaultLocaleStoreKey","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,yBACS;AACf,QAAO,eAAe,IAAI;;;;;;;AAQ5B,SAAgB,eAAe,KAA4B;AACzD,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC,UAAO;;AAET,SAAO,aAAa,QAAQ,IAAI;;AAElC,QAAOC,4BAAc,eAAe,IAAI;;;;;;;AAQ1C,SAAgB,eAAe,KAAa,OAAqB;AAC/D,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC;;AAEF,eAAa,QAAQ,KAAK,MAAM;AAChC;;AAEF,6BAAc,eAAe,KAAK,MAAM"}
@@ -0,0 +1,3 @@
1
+ import type { LocaleCandidates } from 'gt-i18n/internal/types';
2
+ export declare function resolveLocale(candidates?: LocaleCandidates | null): string;
3
+ //# sourceMappingURL=resolveLocale.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolveLocale.d.ts","sourceRoot":"","sources":["../../../src/utils/resolveLocale.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE/D,wBAAgB,aAAa,CAAC,UAAU,CAAC,EAAE,gBAAgB,GAAG,IAAI,GAAG,MAAM,CAM1E"}
@@ -0,0 +1,10 @@
1
+ import { getI18nConfig } from "gt-i18n/internal";
2
+ //#region src/utils/resolveLocale.ts
3
+ function resolveLocale(candidates) {
4
+ const i18nConfig = getI18nConfig();
5
+ return i18nConfig.determineLocale(candidates ?? void 0) || i18nConfig.getDefaultLocale();
6
+ }
7
+ //#endregion
8
+ export { resolveLocale };
9
+
10
+ //# 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,aAAa,eAAe;AAClC,QACE,WAAW,gBAAgB,cAAc,KAAA,EAAU,IACnD,WAAW,kBAAkB"}
@@ -1,3 +1,3 @@
1
- import type { AuthFromEnvParams, AuthFromEnvReturn } from '@generaltranslation/react-core/types';
1
+ import type { AuthFromEnvParams, AuthFromEnvReturn } from '@generaltranslation/react-core/pure';
2
2
  export declare function readAuthFromEnv(params: AuthFromEnvParams): AuthFromEnvReturn;
3
3
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,sCAAsC,CAAC;AAE9C,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,CAM5E"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,qCAAqC,CAAC;AAE7C,wBAAgB,eAAe,CAAC,MAAM,EAAE,iBAAiB,GAAG,iBAAiB,CAM5E"}
@@ -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/types';\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"}
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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gt-react-native",
3
- "version": "10.20.4",
3
+ "version": "11.0.0-odysseus.1",
4
4
  "description": "An i18n package for React Native",
5
5
  "main": "./dist/commonjs/index.js",
6
6
  "module": "./dist/module/index.js",
@@ -80,8 +80,8 @@
80
80
  "registry": "https://registry.npmjs.org/"
81
81
  },
82
82
  "peerDependencies": {
83
- "react": "*",
84
- "react-native": "*"
83
+ "react": ">=19.0.0",
84
+ "react-native": ">=0.78.0"
85
85
  },
86
86
  "dependencies": {
87
87
  "@formatjs/intl-datetimeformat": "^6.18.2",
@@ -92,10 +92,11 @@
92
92
  "@formatjs/intl-numberformat": "^8.15.6",
93
93
  "@formatjs/intl-pluralrules": "^5.4.6",
94
94
  "@formatjs/intl-relativetimeformat": "^11.4.13",
95
- "@generaltranslation/format": "0.1.1",
96
- "@generaltranslation/react-core": "1.8.24",
97
- "@generaltranslation/supported-locales": "2.1.4",
98
- "generaltranslation": "8.2.18"
95
+ "@generaltranslation/format": "0.1.2-odysseus.0",
96
+ "@generaltranslation/react-core": "2.0.0-odysseus.0",
97
+ "@generaltranslation/supported-locales": "2.1.2-odysseus.0",
98
+ "generaltranslation": "9.0.0-odysseus.0",
99
+ "gt-i18n": "1.0.0-odysseus.0"
99
100
  },
100
101
  "devDependencies": {
101
102
  "@babel/core": "^7.28.4",
@@ -0,0 +1,128 @@
1
+ import type {
2
+ LocaleCandidates,
3
+ WritableConditionStoreInterface,
4
+ WritableConditionStoreParams,
5
+ } from 'gt-i18n/internal/types';
6
+ import {
7
+ defaultEnableI18nCookieName as defaultEnableI18nStoreKey,
8
+ defaultLocaleCookieName as defaultLocaleStoreKey,
9
+ defaultRegionCookieName as defaultRegionStoreKey,
10
+ } from '@generaltranslation/react-core/pure';
11
+ import { getLocale } from '../utils/getLocale';
12
+ import {
13
+ getInitialEnableI18n,
14
+ getInitialRegion,
15
+ } from '../utils/getInitialNativeConditions';
16
+ import { nativeStoreGet, nativeStoreSet } from '../utils/nativeStore';
17
+ import { resolveLocale } from '../utils/resolveLocale';
18
+
19
+ export type NativeConditionStoreParams = WritableConditionStoreParams & {
20
+ localeStoreKey?: string;
21
+ regionStoreKey?: string;
22
+ enableI18nStoreKey?: string;
23
+ _reload?: ReloadType;
24
+ };
25
+
26
+ export type NativeConditionStoreState = {
27
+ locale: string;
28
+ region: string | undefined;
29
+ enableI18n: boolean;
30
+ };
31
+
32
+ export type ReloadType = (state: NativeConditionStoreState) => void;
33
+
34
+ /**
35
+ * Condition store implementation for React Native.
36
+ */
37
+ export class NativeConditionStore implements WritableConditionStoreInterface {
38
+ private localeStoreKey: string;
39
+ private regionStoreKey: string;
40
+ private enableI18nStoreKey: string;
41
+ private customReload: ReloadType;
42
+
43
+ constructor(config: NativeConditionStoreParams) {
44
+ this.customReload = config._reload ?? (() => undefined);
45
+ this.localeStoreKey = config.localeStoreKey ?? defaultLocaleStoreKey;
46
+ this.regionStoreKey = config.regionStoreKey ?? defaultRegionStoreKey;
47
+ this.enableI18nStoreKey =
48
+ config.enableI18nStoreKey ?? defaultEnableI18nStoreKey;
49
+
50
+ this.updateLocale(
51
+ config.locale ?? getLocale({ localeStoreKey: this.localeStoreKey })
52
+ );
53
+ const region = getInitialRegion({
54
+ region: config.region,
55
+ regionStoreKey: this.regionStoreKey,
56
+ });
57
+ if (region !== undefined) {
58
+ this.updateRegion(region);
59
+ }
60
+ this.updateEnableI18n(
61
+ getInitialEnableI18n({
62
+ enableI18n: config.enableI18n,
63
+ enableI18nStoreKey: this.enableI18nStoreKey,
64
+ })
65
+ );
66
+ }
67
+
68
+ updateConfig = ({
69
+ localeStoreKey,
70
+ regionStoreKey,
71
+ enableI18nStoreKey,
72
+ }: Pick<
73
+ NativeConditionStoreParams,
74
+ 'localeStoreKey' | 'regionStoreKey' | 'enableI18nStoreKey'
75
+ >): void => {
76
+ this.localeStoreKey = localeStoreKey ?? defaultLocaleStoreKey;
77
+ this.regionStoreKey = regionStoreKey ?? defaultRegionStoreKey;
78
+ this.enableI18nStoreKey = enableI18nStoreKey ?? defaultEnableI18nStoreKey;
79
+ };
80
+
81
+ getLocale = (): string => {
82
+ return getLocale({ localeStoreKey: this.localeStoreKey });
83
+ };
84
+
85
+ setLocale = (locale: LocaleCandidates): void => {
86
+ const nextLocale = resolveLocale(locale);
87
+ nativeStoreSet(this.localeStoreKey, nextLocale);
88
+ this.reload({ locale: nextLocale });
89
+ };
90
+
91
+ getRegion = (): string | undefined => {
92
+ return nativeStoreGet(this.regionStoreKey) || undefined;
93
+ };
94
+
95
+ setRegion = (region: string | undefined): void => {
96
+ this.updateRegion(region);
97
+ this.reload({ region });
98
+ };
99
+
100
+ getEnableI18n = (): boolean => {
101
+ return nativeStoreGet(this.enableI18nStoreKey) !== 'false';
102
+ };
103
+
104
+ setEnableI18n = (enableI18n: boolean): void => {
105
+ this.updateEnableI18n(enableI18n);
106
+ this.reload({ enableI18n });
107
+ };
108
+
109
+ updateLocale = (locale: LocaleCandidates): void => {
110
+ nativeStoreSet(this.localeStoreKey, resolveLocale(locale));
111
+ };
112
+
113
+ updateRegion = (region: string | undefined): void => {
114
+ nativeStoreSet(this.regionStoreKey, region ?? '');
115
+ };
116
+
117
+ updateEnableI18n = (enableI18n: boolean): void => {
118
+ nativeStoreSet(this.enableI18nStoreKey, enableI18n ? 'true' : 'false');
119
+ };
120
+
121
+ reload = (state: Partial<NativeConditionStoreState> = {}): void => {
122
+ this.customReload({
123
+ locale: state.locale ?? this.getLocale(),
124
+ region: 'region' in state ? state.region : this.getRegion(),
125
+ enableI18n: state.enableI18n ?? this.getEnableI18n(),
126
+ });
127
+ };
128
+ }
@@ -0,0 +1,41 @@
1
+ import { useCallback } from 'react';
2
+ import { useConditionStore } from '@generaltranslation/react-core/hooks';
3
+
4
+ /**
5
+ * Returns a function that sets the locale.
6
+ */
7
+ export function useSetLocale() {
8
+ const conditionStore = useConditionStore();
9
+ return useCallback(
10
+ (locale: string) => {
11
+ conditionStore.setLocale(locale);
12
+ },
13
+ [conditionStore]
14
+ );
15
+ }
16
+
17
+ /**
18
+ * Returns a function that sets the region.
19
+ */
20
+ export function useSetRegion() {
21
+ const conditionStore = useConditionStore();
22
+ return useCallback(
23
+ (region: string | undefined) => {
24
+ conditionStore.setRegion(region);
25
+ },
26
+ [conditionStore]
27
+ );
28
+ }
29
+
30
+ /**
31
+ * Returns a function that sets the enableI18n flag.
32
+ */
33
+ export function useSetEnableI18n() {
34
+ const conditionStore = useConditionStore();
35
+ return useCallback(
36
+ (enableI18n: boolean) => {
37
+ conditionStore.setEnableI18n(enableI18n);
38
+ },
39
+ [conditionStore]
40
+ );
41
+ }