gt-react-native 0.0.0 → 0.0.1-alpha.10

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 (76) hide show
  1. package/GtReactNative.podspec +21 -0
  2. package/LICENSE +105 -0
  3. package/README.md +27 -1
  4. package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeGtReactNativeSpec.java +51 -0
  5. package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
  6. package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec-generated.cpp +50 -0
  7. package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec.h +31 -0
  8. package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI-generated.cpp +51 -0
  9. package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI.h +98 -0
  10. package/android/build.gradle +88 -0
  11. package/android/gradle.properties +5 -0
  12. package/android/src/main/AndroidManifest.xml +2 -0
  13. package/android/src/main/java/com/gtreactnative/GtReactNativeModuleImpl.kt +56 -0
  14. package/android/src/main/java/com/gtreactnative/GtReactNativePackage.kt +35 -0
  15. package/android/src/newarch/com/gtreactnative/GtReactNativeModule.kt +30 -0
  16. package/android/src/oldarch/com/gtreactnative/GtReactNativeModule.kt +36 -0
  17. package/ios/GtReactNative.h +13 -0
  18. package/ios/GtReactNative.mm +99 -0
  19. package/lib/module/NativeGtReactNative.js +5 -0
  20. package/lib/module/NativeGtReactNative.js.map +1 -0
  21. package/lib/module/errors-dir/constants.js +4 -0
  22. package/lib/module/errors-dir/constants.js.map +1 -0
  23. package/lib/module/index.js +11 -0
  24. package/lib/module/index.js.map +1 -0
  25. package/lib/module/package.json +1 -0
  26. package/lib/module/provider/GTProvider.js +19 -0
  27. package/lib/module/provider/GTProvider.js.map +1 -0
  28. package/lib/module/provider/hooks/locale/useDetermineLocale.js +142 -0
  29. package/lib/module/provider/hooks/locale/useDetermineLocale.js.map +1 -0
  30. package/lib/module/provider/hooks/useRegionState.js +43 -0
  31. package/lib/module/provider/hooks/useRegionState.js.map +1 -0
  32. package/lib/module/types/config.js +4 -0
  33. package/lib/module/types/config.js.map +1 -0
  34. package/lib/module/utils/getNativeLocales.js +54 -0
  35. package/lib/module/utils/getNativeLocales.js.map +1 -0
  36. package/lib/module/utils/nativeStore.js +34 -0
  37. package/lib/module/utils/nativeStore.js.map +1 -0
  38. package/lib/module/utils/polyfill.js +33 -0
  39. package/lib/module/utils/polyfill.js.map +1 -0
  40. package/lib/module/utils/utils.js +13 -0
  41. package/lib/module/utils/utils.js.map +1 -0
  42. package/lib/typescript/package.json +1 -0
  43. package/lib/typescript/src/NativeGtReactNative.d.ts +10 -0
  44. package/lib/typescript/src/NativeGtReactNative.d.ts.map +1 -0
  45. package/lib/typescript/src/errors-dir/constants.d.ts +2 -0
  46. package/lib/typescript/src/errors-dir/constants.d.ts.map +1 -0
  47. package/lib/typescript/src/index.d.ts +7 -0
  48. package/lib/typescript/src/index.d.ts.map +1 -0
  49. package/lib/typescript/src/provider/GTProvider.d.ts +4 -0
  50. package/lib/typescript/src/provider/GTProvider.d.ts.map +1 -0
  51. package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts +4 -0
  52. package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
  53. package/lib/typescript/src/provider/hooks/useRegionState.d.ts +3 -0
  54. package/lib/typescript/src/provider/hooks/useRegionState.d.ts.map +1 -0
  55. package/lib/typescript/src/types/config.d.ts +30 -0
  56. package/lib/typescript/src/types/config.d.ts.map +1 -0
  57. package/lib/typescript/src/utils/getNativeLocales.d.ts +10 -0
  58. package/lib/typescript/src/utils/getNativeLocales.d.ts.map +1 -0
  59. package/lib/typescript/src/utils/nativeStore.d.ts +16 -0
  60. package/lib/typescript/src/utils/nativeStore.d.ts.map +1 -0
  61. package/lib/typescript/src/utils/polyfill.d.ts +28 -0
  62. package/lib/typescript/src/utils/polyfill.d.ts.map +1 -0
  63. package/lib/typescript/src/utils/utils.d.ts +3 -0
  64. package/lib/typescript/src/utils/utils.d.ts.map +1 -0
  65. package/package.json +152 -7
  66. package/src/NativeGtReactNative.ts +10 -0
  67. package/src/errors-dir/constants.ts +1 -0
  68. package/src/index.tsx +68 -0
  69. package/src/provider/GTProvider.tsx +20 -0
  70. package/src/provider/hooks/locale/useDetermineLocale.ts +194 -0
  71. package/src/provider/hooks/useRegionState.ts +51 -0
  72. package/src/types/config.ts +35 -0
  73. package/src/utils/getNativeLocales.ts +53 -0
  74. package/src/utils/nativeStore.ts +31 -0
  75. package/src/utils/polyfill.ts +36 -0
  76. package/src/utils/utils.ts +12 -0
@@ -0,0 +1,35 @@
1
+ import type {
2
+ RenderMethod,
3
+ Translations,
4
+ CustomLoader,
5
+ GTConfig,
6
+ } from '@generaltranslation/react-core/types';
7
+ import type { CustomMapping } from 'generaltranslation/types';
8
+
9
+ export type GTProviderProps = {
10
+ children?: React.ReactNode;
11
+ projectId?: string;
12
+ devApiKey?: string;
13
+ dictionary?: any;
14
+ locales?: string[];
15
+ defaultLocale?: string;
16
+ locale?: string;
17
+ region?: string;
18
+ cacheUrl?: string;
19
+ runtimeUrl?: string;
20
+ renderSettings?: {
21
+ method: RenderMethod;
22
+ timeout?: number;
23
+ };
24
+ _versionId?: string;
25
+ ssr?: boolean;
26
+ localeCookieName?: string;
27
+ translations?: Translations | null;
28
+ loadDictionary?: CustomLoader;
29
+ loadTranslations?: CustomLoader;
30
+ config?: GTConfig;
31
+ fallback?: React.ReactNode;
32
+ customMapping?: CustomMapping;
33
+ modelProvider?: string;
34
+ [key: string]: any;
35
+ };
@@ -0,0 +1,53 @@
1
+ import { Platform } from 'react-native';
2
+ import GtReactNative from '../NativeGtReactNative';
3
+
4
+ /**
5
+ * Get native device locales in preference order
6
+ * Returns an empty array if detection fails or is not supported
7
+ *
8
+ * iOS: Returns current locale first, followed by preferred languages
9
+ * Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)
10
+ * Web: Returns browser language preferences from navigator
11
+ */
12
+ export function getNativeLocales(): string[] {
13
+ try {
14
+ // Web platform - use browser locale detection
15
+ if (Platform.OS === 'web') {
16
+ return getWebLocales();
17
+ }
18
+
19
+ // Try to get locales from native module
20
+ return GtReactNative.getNativeLocales() || [];
21
+ } catch (error) {
22
+ // Return empty array on any error (native module not available, etc.)
23
+ return [];
24
+ }
25
+ }
26
+
27
+ /**
28
+ * Get browser locales for web platform
29
+ */
30
+ function getWebLocales(): string[] {
31
+ try {
32
+ if (typeof navigator === 'undefined') {
33
+ return [];
34
+ }
35
+
36
+ const locales: string[] = [];
37
+
38
+ // Use navigator.languages if available (most browsers)
39
+ if (navigator.languages && Array.isArray(navigator.languages)) {
40
+ locales.push(...navigator.languages);
41
+ } else if (navigator.language) {
42
+ // Fallback to single language
43
+ locales.push(navigator.language);
44
+ } else if ((navigator as any).userLanguage) {
45
+ // IE fallback
46
+ locales.push((navigator as any).userLanguage);
47
+ }
48
+
49
+ return locales;
50
+ } catch (error) {
51
+ return [];
52
+ }
53
+ }
@@ -0,0 +1,31 @@
1
+ import { Platform } from 'react-native';
2
+ import GtReactNative from '../NativeGtReactNative';
3
+
4
+ /**
5
+ * Native store interface, used to replace cookie behavior from gt-react
6
+ */
7
+
8
+ /**
9
+ * Get a value from the native store
10
+ * @param key - The key to get the value for
11
+ * @returns The value for the key
12
+ */
13
+ export function nativeStoreGet(key: string): string | null {
14
+ if (Platform.OS === 'web') {
15
+ return localStorage.getItem(key);
16
+ }
17
+ return GtReactNative.nativeStoreGet(key);
18
+ }
19
+
20
+ /**
21
+ * Set a value in the native store
22
+ * @param key - The key to set the value for
23
+ * @param value - The value to set
24
+ */
25
+ export function nativeStoreSet(key: string, value: string): void {
26
+ if (Platform.OS === 'web') {
27
+ localStorage.setItem(key, value);
28
+ return;
29
+ }
30
+ GtReactNative.nativeStoreSet(key, value);
31
+ }
@@ -0,0 +1,36 @@
1
+ // Intl object not natively supported, see: https://formatjs.github.io/docs/polyfills
2
+ // See also: The Ultimate Guide to React Native Optimization - page 124
3
+
4
+ import '@formatjs/intl-getcanonicallocales/polyfill';
5
+ import '@formatjs/intl-locale/polyfill';
6
+ import '@formatjs/intl-displaynames/polyfill';
7
+ import '@formatjs/intl-listformat/polyfill';
8
+ import '@formatjs/intl-pluralrules/polyfill-force'; // https://github.com/formatjs/formatjs/issues/4463
9
+ import '@formatjs/intl-numberformat/polyfill';
10
+ import '@formatjs/intl-relativetimeformat/polyfill';
11
+ import '@formatjs/intl-datetimeformat/polyfill';
12
+ import '@formatjs/intl-datetimeformat/add-all-tz';
13
+
14
+ import '@formatjs/intl-displaynames/locale-data/en';
15
+ import '@formatjs/intl-displaynames/locale-data/zh';
16
+ import '@formatjs/intl-displaynames/locale-data/es';
17
+
18
+ import '@formatjs/intl-listformat/locale-data/en';
19
+ import '@formatjs/intl-listformat/locale-data/zh';
20
+ import '@formatjs/intl-listformat/locale-data/es';
21
+
22
+ import '@formatjs/intl-pluralrules/locale-data/en';
23
+ import '@formatjs/intl-pluralrules/locale-data/zh';
24
+ import '@formatjs/intl-pluralrules/locale-data/es';
25
+
26
+ import '@formatjs/intl-numberformat/locale-data/en';
27
+ import '@formatjs/intl-numberformat/locale-data/zh';
28
+ import '@formatjs/intl-numberformat/locale-data/es';
29
+
30
+ import '@formatjs/intl-relativetimeformat/locale-data/en';
31
+ import '@formatjs/intl-relativetimeformat/locale-data/zh';
32
+ import '@formatjs/intl-relativetimeformat/locale-data/es';
33
+
34
+ import '@formatjs/intl-datetimeformat/locale-data/en';
35
+ import '@formatjs/intl-datetimeformat/locale-data/zh';
36
+ import '@formatjs/intl-datetimeformat/locale-data/es';
@@ -0,0 +1,12 @@
1
+ import type {
2
+ AuthFromEnvParams,
3
+ AuthFromEnvReturn,
4
+ } from '@generaltranslation/react-core/types';
5
+
6
+ export function readAuthFromEnv(params: AuthFromEnvParams): AuthFromEnvReturn {
7
+ const { projectId, devApiKey } = params;
8
+ return {
9
+ projectId: projectId || '',
10
+ devApiKey: devApiKey,
11
+ };
12
+ }