gt-react-native 0.0.0 → 0.0.1-alpha.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/GtReactNative.podspec +21 -0
- package/LICENSE +105 -0
- package/README.md +27 -1
- package/android/app/build/generated/source/codegen/java/com/facebook/fbreact/specs/NativeGtReactNativeSpec.java +51 -0
- package/android/app/build/generated/source/codegen/jni/CMakeLists.txt +28 -0
- package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec-generated.cpp +50 -0
- package/android/app/build/generated/source/codegen/jni/GtReactNativeSpec.h +31 -0
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI-generated.cpp +51 -0
- package/android/app/build/generated/source/codegen/jni/react/renderer/components/GtReactNativeSpec/GtReactNativeSpecJSI.h +98 -0
- package/android/build.gradle +77 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/gtreactnative/GtReactNativeModule.kt +68 -0
- package/android/src/main/java/com/gtreactnative/GtReactNativePackage.kt +33 -0
- package/ios/GtReactNative.h +5 -0
- package/ios/GtReactNative.mm +64 -0
- package/lib/module/NativeGtReactNative.js +5 -0
- package/lib/module/NativeGtReactNative.js.map +1 -0
- package/lib/module/errors-dir/constants.js +4 -0
- package/lib/module/errors-dir/constants.js.map +1 -0
- package/lib/module/index.js +11 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/provider/GTProvider.js +19 -0
- package/lib/module/provider/GTProvider.js.map +1 -0
- package/lib/module/provider/hooks/locale/useDetermineLocale.js +140 -0
- package/lib/module/provider/hooks/locale/useDetermineLocale.js.map +1 -0
- package/lib/module/provider/hooks/useRegionState.js +55 -0
- package/lib/module/provider/hooks/useRegionState.js.map +1 -0
- package/lib/module/types/config.js +4 -0
- package/lib/module/types/config.js.map +1 -0
- package/lib/module/utils/constants.js +8 -0
- package/lib/module/utils/constants.js.map +1 -0
- package/lib/module/utils/getNativeLocales.js +54 -0
- package/lib/module/utils/getNativeLocales.js.map +1 -0
- package/lib/module/utils/nativeStore.js +34 -0
- package/lib/module/utils/nativeStore.js.map +1 -0
- package/lib/module/utils/polyfill.js +32 -0
- package/lib/module/utils/polyfill.js.map +1 -0
- package/lib/module/utils/utils.js +16 -0
- package/lib/module/utils/utils.js.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeGtReactNative.d.ts +10 -0
- package/lib/typescript/src/NativeGtReactNative.d.ts.map +1 -0
- package/lib/typescript/src/errors-dir/constants.d.ts +2 -0
- package/lib/typescript/src/errors-dir/constants.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +7 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/provider/GTProvider.d.ts +4 -0
- package/lib/typescript/src/provider/GTProvider.d.ts.map +1 -0
- package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts +4 -0
- package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
- package/lib/typescript/src/provider/hooks/useRegionState.d.ts +3 -0
- package/lib/typescript/src/provider/hooks/useRegionState.d.ts.map +1 -0
- package/lib/typescript/src/types/config.d.ts +30 -0
- package/lib/typescript/src/types/config.d.ts.map +1 -0
- package/lib/typescript/src/utils/constants.d.ts +3 -0
- package/lib/typescript/src/utils/constants.d.ts.map +1 -0
- package/lib/typescript/src/utils/getNativeLocales.d.ts +10 -0
- package/lib/typescript/src/utils/getNativeLocales.d.ts.map +1 -0
- package/lib/typescript/src/utils/nativeStore.d.ts +16 -0
- package/lib/typescript/src/utils/nativeStore.d.ts.map +1 -0
- package/lib/typescript/src/utils/polyfill.d.ts +28 -0
- package/lib/typescript/src/utils/polyfill.d.ts.map +1 -0
- package/lib/typescript/src/utils/utils.d.ts +3 -0
- package/lib/typescript/src/utils/utils.d.ts.map +1 -0
- package/package.json +153 -7
- package/src/NativeGtReactNative.ts +10 -0
- package/src/errors-dir/constants.ts +1 -0
- package/src/index.tsx +68 -0
- package/src/provider/GTProvider.tsx +20 -0
- package/src/provider/hooks/locale/useDetermineLocale.ts +192 -0
- package/src/provider/hooks/useRegionState.ts +63 -0
- package/src/types/config.ts +35 -0
- package/src/utils/constants.ts +5 -0
- package/src/utils/getNativeLocales.ts +53 -0
- package/src/utils/nativeStore.ts +31 -0
- package/src/utils/polyfill.ts +36 -0
- package/src/utils/utils.ts +13 -0
|
@@ -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
|
+
// This is a temporary solution, we will do something smarter before the first release
|
|
2
|
+
|
|
3
|
+
import '@formatjs/intl-getcanonicallocales/polyfill';
|
|
4
|
+
|
|
5
|
+
import '@formatjs/intl-locale/polyfill';
|
|
6
|
+
|
|
7
|
+
import '@formatjs/intl-displaynames/polyfill';
|
|
8
|
+
import '@formatjs/intl-displaynames/locale-data/en';
|
|
9
|
+
import '@formatjs/intl-displaynames/locale-data/zh';
|
|
10
|
+
import '@formatjs/intl-displaynames/locale-data/es';
|
|
11
|
+
|
|
12
|
+
import '@formatjs/intl-listformat/polyfill';
|
|
13
|
+
import '@formatjs/intl-listformat/locale-data/en';
|
|
14
|
+
import '@formatjs/intl-listformat/locale-data/zh';
|
|
15
|
+
import '@formatjs/intl-listformat/locale-data/es';
|
|
16
|
+
|
|
17
|
+
import '@formatjs/intl-pluralrules/polyfill';
|
|
18
|
+
import '@formatjs/intl-pluralrules/locale-data/en';
|
|
19
|
+
import '@formatjs/intl-pluralrules/locale-data/zh';
|
|
20
|
+
import '@formatjs/intl-pluralrules/locale-data/es';
|
|
21
|
+
|
|
22
|
+
import '@formatjs/intl-numberformat/polyfill';
|
|
23
|
+
import '@formatjs/intl-numberformat/locale-data/en';
|
|
24
|
+
import '@formatjs/intl-numberformat/locale-data/zh';
|
|
25
|
+
import '@formatjs/intl-numberformat/locale-data/es';
|
|
26
|
+
|
|
27
|
+
import '@formatjs/intl-relativetimeformat/polyfill';
|
|
28
|
+
import '@formatjs/intl-relativetimeformat/locale-data/en';
|
|
29
|
+
import '@formatjs/intl-relativetimeformat/locale-data/zh';
|
|
30
|
+
import '@formatjs/intl-relativetimeformat/locale-data/es';
|
|
31
|
+
|
|
32
|
+
import '@formatjs/intl-datetimeformat/polyfill';
|
|
33
|
+
import '@formatjs/intl-datetimeformat/add-all-tz';
|
|
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,13 @@
|
|
|
1
|
+
// import Config from 'react-native-config';
|
|
2
|
+
import type {
|
|
3
|
+
AuthFromEnvParams,
|
|
4
|
+
AuthFromEnvReturn,
|
|
5
|
+
} from '@generaltranslation/react-core/types';
|
|
6
|
+
|
|
7
|
+
export function readAuthFromEnv(params: AuthFromEnvParams): AuthFromEnvReturn {
|
|
8
|
+
const { projectId, devApiKey } = params;
|
|
9
|
+
return {
|
|
10
|
+
projectId: projectId || '', //|| Config.GT_PROJECT_ID || '',
|
|
11
|
+
devApiKey: devApiKey, //|| Config.GT_DEV_API_KEY || undefined,
|
|
12
|
+
};
|
|
13
|
+
}
|