gt-react-native 11.0.13 → 11.1.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.
- package/dist/commonjs/NativeGtReactNative.js +2 -1
- package/dist/commonjs/NativeGtReactNative.js.map +1 -1
- package/dist/commonjs/utils/getNativeLocales.js +1 -1
- package/dist/commonjs/utils/getNativeLocales.js.map +1 -1
- package/dist/commonjs/utils/nativeStore.js +2 -2
- package/dist/commonjs/utils/nativeStore.js.map +1 -1
- package/dist/module/NativeGtReactNative.d.ts +1 -1
- package/dist/module/NativeGtReactNative.d.ts.map +1 -1
- package/dist/module/NativeGtReactNative.js +2 -2
- package/dist/module/NativeGtReactNative.js.map +1 -1
- package/dist/module/utils/getNativeLocales.js +1 -1
- package/dist/module/utils/getNativeLocales.js.map +1 -1
- package/dist/module/utils/nativeStore.js +2 -2
- package/dist/module/utils/nativeStore.js.map +1 -1
- package/package.json +6 -6
- package/src/NativeGtReactNative.ts +13 -3
- package/src/utils/getNativeLocales.ts +1 -1
- package/src/utils/nativeStore.ts +2 -2
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
require("./_virtual/_rolldown/runtime.js");
|
|
3
|
+
let react_native = require("react-native");
|
|
3
4
|
//#region src/NativeGtReactNative.ts
|
|
4
|
-
const GtReactNative =
|
|
5
|
+
const GtReactNative = react_native.Platform.OS === "web" ? null : react_native.TurboModuleRegistry.getEnforcing("GtReactNative");
|
|
5
6
|
//#endregion
|
|
6
7
|
exports.GtReactNative = GtReactNative;
|
|
7
8
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeGtReactNative.js","names":["TurboModuleRegistry"],"sources":["../../src/NativeGtReactNative.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\nexport interface Spec extends TurboModule {\n multiply(a: number, b: number): number;\n getNativeLocales(): string[];\n nativeStoreGet(key: string): string | null;\n nativeStoreSet(key: string, value: string): void;\n}\n\nexport const GtReactNative =\n TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"NativeGtReactNative.js","names":["Platform","TurboModuleRegistry"],"sources":["../../src/NativeGtReactNative.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { Platform, TurboModuleRegistry } from 'react-native';\nexport interface Spec extends TurboModule {\n multiply(a: number, b: number): number;\n getNativeLocales(): string[];\n nativeStoreGet(key: string): string | null;\n nativeStoreSet(key: string, value: string): void;\n}\n\n// On web (react-native-web / Expo web) the native module is never registered, so\n// calling getEnforcing at module load throws and crashes the whole bundle before\n// any Platform.OS guard in the sibling utilities can run. Resolve to null on web:\n// its only importers, utils/getNativeLocales.ts and utils/nativeStore.ts, never\n// reach it there, because each serves its web fallback (navigator.languages,\n// localStorage) behind its own Platform.OS === 'web' branch first. On native\n// platforms getEnforcing is kept unchanged, so a misconfigured native build\n// still fails loudly at import as before.\nexport const GtReactNative: Spec | null =\n Platform.OS === 'web'\n ? null\n : TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');\n"],"mappings":";;;;AAiBA,MAAa,gBACXA,aAAAA,SAAS,OAAO,QACZ,OACAC,aAAAA,oBAAoB,aAAmB,gBAAgB"}
|
|
@@ -14,7 +14,7 @@ let react_native = require("react-native");
|
|
|
14
14
|
function getNativeLocales() {
|
|
15
15
|
try {
|
|
16
16
|
if (react_native.Platform.OS === "web") return getWebLocales();
|
|
17
|
-
return require_NativeGtReactNative.GtReactNative
|
|
17
|
+
return require_NativeGtReactNative.GtReactNative?.getNativeLocales() || [];
|
|
18
18
|
} catch {
|
|
19
19
|
return [];
|
|
20
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNativeLocales.js","names":["Platform","GtReactNative"],"sources":["../../../src/utils/getNativeLocales.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { GtReactNative } from '../NativeGtReactNative';\n\n/**\n * Get native device locales in preference order\n * Returns an empty array if detection fails or is not supported\n *\n * iOS: Returns current locale first, followed by preferred languages\n * Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)\n * Web: Returns browser language preferences from navigator\n */\nexport function getNativeLocales(): string[] {\n try {\n // Web platform - use browser locale detection\n if (Platform.OS === 'web') {\n return getWebLocales();\n }\n\n // Try to get locales from native module\n return GtReactNative
|
|
1
|
+
{"version":3,"file":"getNativeLocales.js","names":["Platform","GtReactNative"],"sources":["../../../src/utils/getNativeLocales.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { GtReactNative } from '../NativeGtReactNative';\n\n/**\n * Get native device locales in preference order\n * Returns an empty array if detection fails or is not supported\n *\n * iOS: Returns current locale first, followed by preferred languages\n * Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)\n * Web: Returns browser language preferences from navigator\n */\nexport function getNativeLocales(): string[] {\n try {\n // Web platform - use browser locale detection\n if (Platform.OS === 'web') {\n return getWebLocales();\n }\n\n // Try to get locales from native module\n return GtReactNative?.getNativeLocales() || [];\n } catch {\n // Return empty array on any error (native module not available, etc.)\n return [];\n }\n}\n\n/**\n * Get browser locales for web platform\n */\nfunction getWebLocales(): string[] {\n try {\n if (typeof navigator === 'undefined') {\n return [];\n }\n\n const locales: string[] = [];\n\n // Use navigator.languages if available (most browsers)\n if (navigator.languages && Array.isArray(navigator.languages)) {\n locales.push(...navigator.languages);\n } else if (navigator.language) {\n // Fallback to single language\n locales.push(navigator.language);\n } else {\n // IE fallback\n const legacyNavigator = navigator as Navigator & {\n userLanguage?: string;\n };\n if (legacyNavigator.userLanguage) {\n locales.push(legacyNavigator.userLanguage);\n }\n }\n\n return locales;\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAWA,SAAgB,mBAA6B;AAC3C,KAAI;AAEF,MAAIA,aAAAA,SAAS,OAAO,MAClB,QAAO,eAAe;AAIxB,SAAOC,4BAAAA,eAAe,kBAAkB,IAAI,EAAE;SACxC;AAEN,SAAO,EAAE;;;;;;AAOb,SAAS,gBAA0B;AACjC,KAAI;AACF,MAAI,OAAO,cAAc,YACvB,QAAO,EAAE;EAGX,MAAM,UAAoB,EAAE;AAG5B,MAAI,UAAU,aAAa,MAAM,QAAQ,UAAU,UAAU,CAC3D,SAAQ,KAAK,GAAG,UAAU,UAAU;WAC3B,UAAU,SAEnB,SAAQ,KAAK,UAAU,SAAS;OAC3B;GAEL,MAAM,kBAAkB;AAGxB,OAAI,gBAAgB,aAClB,SAAQ,KAAK,gBAAgB,aAAa;;AAI9C,SAAO;SACD;AACN,SAAO,EAAE"}
|
|
@@ -32,7 +32,7 @@ function nativeStoreGet(key) {
|
|
|
32
32
|
}
|
|
33
33
|
return localStorage.getItem(key);
|
|
34
34
|
}
|
|
35
|
-
return require_NativeGtReactNative.GtReactNative
|
|
35
|
+
return require_NativeGtReactNative.GtReactNative?.nativeStoreGet(key) ?? null;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* Set a value in the native store
|
|
@@ -48,7 +48,7 @@ function nativeStoreSet(key, value) {
|
|
|
48
48
|
localStorage.setItem(key, value);
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
require_NativeGtReactNative.GtReactNative
|
|
51
|
+
require_NativeGtReactNative.GtReactNative?.nativeStoreSet(key, value);
|
|
52
52
|
}
|
|
53
53
|
//#endregion
|
|
54
54
|
exports.getLocaleFromNativeStore = getLocaleFromNativeStore;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeStore.js","names":["Platform","ssrUnsupportedWarning","GtReactNative"],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { GtReactNative } from '../NativeGtReactNative';\nimport { ssrUnsupportedWarning } from '../errors-dir/warnings';\n\n/**\n * Get the locale from the native store.\n *\n * This reads persisted native storage directly, so it can temporarily be out of\n * sync with React state while a locale change is in progress.\n *\n * Defaults to the store key configured through initializeGT().\n *\n * @param key - The key to get the locale from\n * @returns The locale from the native store\n */\nexport function getLocaleFromNativeStore(\n key = getI18nConfig().getLocaleCookieName()\n): string | null {\n return nativeStoreGet(key);\n}\n\n/**\n * Get a value from the native store\n * @param key - The key to get the value for\n * @returns The value for the key\n */\nexport function nativeStoreGet(key: string): string | null {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return null;\n }\n return localStorage.getItem(key);\n }\n return GtReactNative
|
|
1
|
+
{"version":3,"file":"nativeStore.js","names":["Platform","ssrUnsupportedWarning","GtReactNative"],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { GtReactNative } from '../NativeGtReactNative';\nimport { ssrUnsupportedWarning } from '../errors-dir/warnings';\n\n/**\n * Get the locale from the native store.\n *\n * This reads persisted native storage directly, so it can temporarily be out of\n * sync with React state while a locale change is in progress.\n *\n * Defaults to the store key configured through initializeGT().\n *\n * @param key - The key to get the locale from\n * @returns The locale from the native store\n */\nexport function getLocaleFromNativeStore(\n key = getI18nConfig().getLocaleCookieName()\n): string | null {\n return nativeStoreGet(key);\n}\n\n/**\n * Get a value from the native store\n * @param key - The key to get the value for\n * @returns The value for the key\n */\nexport function nativeStoreGet(key: string): string | null {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return null;\n }\n return localStorage.getItem(key);\n }\n return GtReactNative?.nativeStoreGet(key) ?? null;\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,OAAA,GAAA,oCAAA,gBAAqB,CAAC,qBAAqB,EAC5B;AACf,QAAO,eAAe,IAAI;;;;;;;AAQ5B,SAAgB,eAAe,KAA4B;AACzD,KAAIA,aAAAA,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAKC,4BAAAA,sBAAsB;AACnC,UAAO;;AAET,SAAO,aAAa,QAAQ,IAAI;;AAElC,QAAOC,4BAAAA,eAAe,eAAe,IAAI,IAAI;;;;;;;AAQ/C,SAAgB,eAAe,KAAa,OAAqB;AAC/D,KAAIF,aAAAA,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAKC,4BAAAA,sBAAsB;AACnC;;AAEF,eAAa,QAAQ,KAAK,MAAM;AAChC;;AAEF,6BAAA,eAAe,eAAe,KAAK,MAAM"}
|
|
@@ -5,5 +5,5 @@ export interface Spec extends TurboModule {
|
|
|
5
5
|
nativeStoreGet(key: string): string | null;
|
|
6
6
|
nativeStoreSet(key: string, value: string): void;
|
|
7
7
|
}
|
|
8
|
-
export declare const GtReactNative: Spec;
|
|
8
|
+
export declare const GtReactNative: Spec | null;
|
|
9
9
|
//# sourceMappingURL=NativeGtReactNative.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeGtReactNative.d.ts","sourceRoot":"","sources":["../../src/NativeGtReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC,gBAAgB,IAAI,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAClD;
|
|
1
|
+
{"version":3,"file":"NativeGtReactNative.d.ts","sourceRoot":"","sources":["../../src/NativeGtReactNative.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEhD,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,QAAQ,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACvC,gBAAgB,IAAI,MAAM,EAAE,CAAC;IAC7B,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3C,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAClD;AAUD,eAAO,MAAM,aAAa,EAAE,IAAI,GAAG,IAG0B,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { TurboModuleRegistry } from "react-native";
|
|
1
|
+
import { Platform, TurboModuleRegistry } from "react-native";
|
|
2
2
|
//#region src/NativeGtReactNative.ts
|
|
3
|
-
const GtReactNative = TurboModuleRegistry.getEnforcing("GtReactNative");
|
|
3
|
+
const GtReactNative = Platform.OS === "web" ? null : TurboModuleRegistry.getEnforcing("GtReactNative");
|
|
4
4
|
//#endregion
|
|
5
5
|
export { GtReactNative };
|
|
6
6
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeGtReactNative.js","names":[],"sources":["../../src/NativeGtReactNative.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { TurboModuleRegistry } from 'react-native';\nexport interface Spec extends TurboModule {\n multiply(a: number, b: number): number;\n getNativeLocales(): string[];\n nativeStoreGet(key: string): string | null;\n nativeStoreSet(key: string, value: string): void;\n}\n\nexport const GtReactNative =\n TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');\n"],"mappings":";;
|
|
1
|
+
{"version":3,"file":"NativeGtReactNative.js","names":[],"sources":["../../src/NativeGtReactNative.ts"],"sourcesContent":["import type { TurboModule } from 'react-native';\nimport { Platform, TurboModuleRegistry } from 'react-native';\nexport interface Spec extends TurboModule {\n multiply(a: number, b: number): number;\n getNativeLocales(): string[];\n nativeStoreGet(key: string): string | null;\n nativeStoreSet(key: string, value: string): void;\n}\n\n// On web (react-native-web / Expo web) the native module is never registered, so\n// calling getEnforcing at module load throws and crashes the whole bundle before\n// any Platform.OS guard in the sibling utilities can run. Resolve to null on web:\n// its only importers, utils/getNativeLocales.ts and utils/nativeStore.ts, never\n// reach it there, because each serves its web fallback (navigator.languages,\n// localStorage) behind its own Platform.OS === 'web' branch first. On native\n// platforms getEnforcing is kept unchanged, so a misconfigured native build\n// still fails loudly at import as before.\nexport const GtReactNative: Spec | null =\n Platform.OS === 'web'\n ? null\n : TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');\n"],"mappings":";;AAiBA,MAAa,gBACX,SAAS,OAAO,QACZ,OACA,oBAAoB,aAAmB,gBAAgB"}
|
|
@@ -12,7 +12,7 @@ import { Platform } from "react-native";
|
|
|
12
12
|
function getNativeLocales() {
|
|
13
13
|
try {
|
|
14
14
|
if (Platform.OS === "web") return getWebLocales();
|
|
15
|
-
return GtReactNative
|
|
15
|
+
return GtReactNative?.getNativeLocales() || [];
|
|
16
16
|
} catch {
|
|
17
17
|
return [];
|
|
18
18
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getNativeLocales.js","names":[],"sources":["../../../src/utils/getNativeLocales.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { GtReactNative } from '../NativeGtReactNative';\n\n/**\n * Get native device locales in preference order\n * Returns an empty array if detection fails or is not supported\n *\n * iOS: Returns current locale first, followed by preferred languages\n * Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)\n * Web: Returns browser language preferences from navigator\n */\nexport function getNativeLocales(): string[] {\n try {\n // Web platform - use browser locale detection\n if (Platform.OS === 'web') {\n return getWebLocales();\n }\n\n // Try to get locales from native module\n return GtReactNative
|
|
1
|
+
{"version":3,"file":"getNativeLocales.js","names":[],"sources":["../../../src/utils/getNativeLocales.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { GtReactNative } from '../NativeGtReactNative';\n\n/**\n * Get native device locales in preference order\n * Returns an empty array if detection fails or is not supported\n *\n * iOS: Returns current locale first, followed by preferred languages\n * Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)\n * Web: Returns browser language preferences from navigator\n */\nexport function getNativeLocales(): string[] {\n try {\n // Web platform - use browser locale detection\n if (Platform.OS === 'web') {\n return getWebLocales();\n }\n\n // Try to get locales from native module\n return GtReactNative?.getNativeLocales() || [];\n } catch {\n // Return empty array on any error (native module not available, etc.)\n return [];\n }\n}\n\n/**\n * Get browser locales for web platform\n */\nfunction getWebLocales(): string[] {\n try {\n if (typeof navigator === 'undefined') {\n return [];\n }\n\n const locales: string[] = [];\n\n // Use navigator.languages if available (most browsers)\n if (navigator.languages && Array.isArray(navigator.languages)) {\n locales.push(...navigator.languages);\n } else if (navigator.language) {\n // Fallback to single language\n locales.push(navigator.language);\n } else {\n // IE fallback\n const legacyNavigator = navigator as Navigator & {\n userLanguage?: string;\n };\n if (legacyNavigator.userLanguage) {\n locales.push(legacyNavigator.userLanguage);\n }\n }\n\n return locales;\n } catch {\n return [];\n }\n}\n"],"mappings":";;;;;;;;;;;AAWA,SAAgB,mBAA6B;AAC3C,KAAI;AAEF,MAAI,SAAS,OAAO,MAClB,QAAO,eAAe;AAIxB,SAAO,eAAe,kBAAkB,IAAI,EAAE;SACxC;AAEN,SAAO,EAAE;;;;;;AAOb,SAAS,gBAA0B;AACjC,KAAI;AACF,MAAI,OAAO,cAAc,YACvB,QAAO,EAAE;EAGX,MAAM,UAAoB,EAAE;AAG5B,MAAI,UAAU,aAAa,MAAM,QAAQ,UAAU,UAAU,CAC3D,SAAQ,KAAK,GAAG,UAAU,UAAU;WAC3B,UAAU,SAEnB,SAAQ,KAAK,UAAU,SAAS;OAC3B;GAEL,MAAM,kBAAkB;AAGxB,OAAI,gBAAgB,aAClB,SAAQ,KAAK,gBAAgB,aAAa;;AAI9C,SAAO;SACD;AACN,SAAO,EAAE"}
|
|
@@ -30,7 +30,7 @@ function nativeStoreGet(key) {
|
|
|
30
30
|
}
|
|
31
31
|
return localStorage.getItem(key);
|
|
32
32
|
}
|
|
33
|
-
return GtReactNative
|
|
33
|
+
return GtReactNative?.nativeStoreGet(key) ?? null;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
36
36
|
* Set a value in the native store
|
|
@@ -46,7 +46,7 @@ function nativeStoreSet(key, value) {
|
|
|
46
46
|
localStorage.setItem(key, value);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
|
-
GtReactNative
|
|
49
|
+
GtReactNative?.nativeStoreSet(key, value);
|
|
50
50
|
}
|
|
51
51
|
//#endregion
|
|
52
52
|
export { getLocaleFromNativeStore, nativeStoreGet, nativeStoreSet };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nativeStore.js","names":[],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { GtReactNative } from '../NativeGtReactNative';\nimport { ssrUnsupportedWarning } from '../errors-dir/warnings';\n\n/**\n * Get the locale from the native store.\n *\n * This reads persisted native storage directly, so it can temporarily be out of\n * sync with React state while a locale change is in progress.\n *\n * Defaults to the store key configured through initializeGT().\n *\n * @param key - The key to get the locale from\n * @returns The locale from the native store\n */\nexport function getLocaleFromNativeStore(\n key = getI18nConfig().getLocaleCookieName()\n): string | null {\n return nativeStoreGet(key);\n}\n\n/**\n * Get a value from the native store\n * @param key - The key to get the value for\n * @returns The value for the key\n */\nexport function nativeStoreGet(key: string): string | null {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return null;\n }\n return localStorage.getItem(key);\n }\n return GtReactNative
|
|
1
|
+
{"version":3,"file":"nativeStore.js","names":[],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport { getI18nConfig } from '@generaltranslation/react-core/pure';\nimport { GtReactNative } from '../NativeGtReactNative';\nimport { ssrUnsupportedWarning } from '../errors-dir/warnings';\n\n/**\n * Get the locale from the native store.\n *\n * This reads persisted native storage directly, so it can temporarily be out of\n * sync with React state while a locale change is in progress.\n *\n * Defaults to the store key configured through initializeGT().\n *\n * @param key - The key to get the locale from\n * @returns The locale from the native store\n */\nexport function getLocaleFromNativeStore(\n key = getI18nConfig().getLocaleCookieName()\n): string | null {\n return nativeStoreGet(key);\n}\n\n/**\n * Get a value from the native store\n * @param key - The key to get the value for\n * @returns The value for the key\n */\nexport function nativeStoreGet(key: string): string | null {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return null;\n }\n return localStorage.getItem(key);\n }\n return GtReactNative?.nativeStoreGet(key) ?? null;\n}\n\n/**\n * Set a value in the native store\n * @param key - The key to set the value for\n * @param value - The value to set\n */\nexport function nativeStoreSet(key: string, value: string): void {\n if (Platform.OS === 'web') {\n if (typeof localStorage === 'undefined') {\n // eslint-disable-next-line no-console\n console.warn(ssrUnsupportedWarning);\n return;\n }\n localStorage.setItem(key, value);\n return;\n }\n GtReactNative?.nativeStoreSet(key, value);\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,SAAgB,yBACd,MAAM,eAAe,CAAC,qBAAqB,EAC5B;AACf,QAAO,eAAe,IAAI;;;;;;;AAQ5B,SAAgB,eAAe,KAA4B;AACzD,KAAI,SAAS,OAAO,OAAO;AACzB,MAAI,OAAO,iBAAiB,aAAa;AAEvC,WAAQ,KAAK,sBAAsB;AACnC,UAAO;;AAET,SAAO,aAAa,QAAQ,IAAI;;AAElC,QAAO,eAAe,eAAe,IAAI,IAAI;;;;;;;AAQ/C,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,gBAAe,eAAe,KAAK,MAAM"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-react-native",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.1.1",
|
|
4
4
|
"description": "An i18n package for React Native",
|
|
5
5
|
"main": "./dist/commonjs/index.js",
|
|
6
6
|
"module": "./dist/module/index.js",
|
|
@@ -92,11 +92,11 @@
|
|
|
92
92
|
"@formatjs/intl-numberformat": "^8.15.6",
|
|
93
93
|
"@formatjs/intl-pluralrules": "^5.4.6",
|
|
94
94
|
"@formatjs/intl-relativetimeformat": "^11.4.13",
|
|
95
|
-
"@generaltranslation/format": "0.1.
|
|
96
|
-
"@generaltranslation/react-core": "11.
|
|
97
|
-
"@generaltranslation/supported-locales": "2.1.
|
|
98
|
-
"generaltranslation": "9.0.
|
|
99
|
-
"gt-i18n": "1.0.
|
|
95
|
+
"@generaltranslation/format": "0.1.4",
|
|
96
|
+
"@generaltranslation/react-core": "11.1.1",
|
|
97
|
+
"@generaltranslation/supported-locales": "2.1.12",
|
|
98
|
+
"generaltranslation": "9.0.5",
|
|
99
|
+
"gt-i18n": "1.0.9"
|
|
100
100
|
},
|
|
101
101
|
"devDependencies": {
|
|
102
102
|
"@babel/core": "^7.28.4",
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { TurboModule } from 'react-native';
|
|
2
|
-
import { TurboModuleRegistry } from 'react-native';
|
|
2
|
+
import { Platform, TurboModuleRegistry } from 'react-native';
|
|
3
3
|
export interface Spec extends TurboModule {
|
|
4
4
|
multiply(a: number, b: number): number;
|
|
5
5
|
getNativeLocales(): string[];
|
|
@@ -7,5 +7,15 @@ export interface Spec extends TurboModule {
|
|
|
7
7
|
nativeStoreSet(key: string, value: string): void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
// On web (react-native-web / Expo web) the native module is never registered, so
|
|
11
|
+
// calling getEnforcing at module load throws and crashes the whole bundle before
|
|
12
|
+
// any Platform.OS guard in the sibling utilities can run. Resolve to null on web:
|
|
13
|
+
// its only importers, utils/getNativeLocales.ts and utils/nativeStore.ts, never
|
|
14
|
+
// reach it there, because each serves its web fallback (navigator.languages,
|
|
15
|
+
// localStorage) behind its own Platform.OS === 'web' branch first. On native
|
|
16
|
+
// platforms getEnforcing is kept unchanged, so a misconfigured native build
|
|
17
|
+
// still fails loudly at import as before.
|
|
18
|
+
export const GtReactNative: Spec | null =
|
|
19
|
+
Platform.OS === 'web'
|
|
20
|
+
? null
|
|
21
|
+
: TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');
|
|
@@ -17,7 +17,7 @@ export function getNativeLocales(): string[] {
|
|
|
17
17
|
}
|
|
18
18
|
|
|
19
19
|
// Try to get locales from native module
|
|
20
|
-
return GtReactNative
|
|
20
|
+
return GtReactNative?.getNativeLocales() || [];
|
|
21
21
|
} catch {
|
|
22
22
|
// Return empty array on any error (native module not available, etc.)
|
|
23
23
|
return [];
|
package/src/utils/nativeStore.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function nativeStoreGet(key: string): string | null {
|
|
|
34
34
|
}
|
|
35
35
|
return localStorage.getItem(key);
|
|
36
36
|
}
|
|
37
|
-
return GtReactNative
|
|
37
|
+
return GtReactNative?.nativeStoreGet(key) ?? null;
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
/**
|
|
@@ -52,5 +52,5 @@ export function nativeStoreSet(key: string, value: string): void {
|
|
|
52
52
|
localStorage.setItem(key, value);
|
|
53
53
|
return;
|
|
54
54
|
}
|
|
55
|
-
GtReactNative
|
|
55
|
+
GtReactNative?.nativeStoreSet(key, value);
|
|
56
56
|
}
|