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.
- 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 +88 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/gtreactnative/GtReactNativeModuleImpl.kt +56 -0
- package/android/src/main/java/com/gtreactnative/GtReactNativePackage.kt +35 -0
- package/android/src/newarch/com/gtreactnative/GtReactNativeModule.kt +30 -0
- package/android/src/oldarch/com/gtreactnative/GtReactNativeModule.kt +36 -0
- package/ios/GtReactNative.h +13 -0
- package/ios/GtReactNative.mm +99 -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 +142 -0
- package/lib/module/provider/hooks/locale/useDetermineLocale.js.map +1 -0
- package/lib/module/provider/hooks/useRegionState.js +43 -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/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 +33 -0
- package/lib/module/utils/polyfill.js.map +1 -0
- package/lib/module/utils/utils.js +13 -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/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 +152 -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 +194 -0
- package/src/provider/hooks/useRegionState.ts +51 -0
- package/src/types/config.ts +35 -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 +12 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GTProvider.d.ts","sourceRoot":"","sources":["../../../../src/provider/GTProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAKvD,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,KAAK,CAAC,GAAG,CAAC,OAAO,CAWpE;AAED,eAAe,UAAU,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { UseDetermineLocaleParams, UseDetermineLocaleReturn } from '@generaltranslation/react-core/types';
|
|
2
|
+
export declare function useDetermineLocale({ locale: _locale, defaultLocale, locales, localeCookieName, ssr, // not relevant
|
|
3
|
+
customMapping, }: UseDetermineLocaleParams): UseDetermineLocaleReturn;
|
|
4
|
+
//# sourceMappingURL=useDetermineLocale.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDetermineLocale.d.ts","sourceRoot":"","sources":["../../../../../../src/provider/hooks/locale/useDetermineLocale.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,sCAAsC,CAAC;AAI9C,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EAAE,OAAY,EACpB,aAAoC,EACpC,OAAY,EACZ,gBAA8C,EAC9C,GAAW,EAAE,eAAe;AAC5B,aAAa,GACd,EAAE,wBAAwB,GAAG,wBAAwB,CA2DrD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useRegionState.d.ts","sourceRoot":"","sources":["../../../../../src/provider/hooks/useRegionState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAsB9C,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,GAAG,EACH,gBAAgB,GACjB,EAAE,oBAAoB,GAAG,oBAAoB,CAoB7C"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { RenderMethod, Translations, CustomLoader, GTConfig } from '@generaltranslation/react-core/types';
|
|
2
|
+
import type { CustomMapping } from 'generaltranslation/types';
|
|
3
|
+
export type GTProviderProps = {
|
|
4
|
+
children?: React.ReactNode;
|
|
5
|
+
projectId?: string;
|
|
6
|
+
devApiKey?: string;
|
|
7
|
+
dictionary?: any;
|
|
8
|
+
locales?: string[];
|
|
9
|
+
defaultLocale?: string;
|
|
10
|
+
locale?: string;
|
|
11
|
+
region?: string;
|
|
12
|
+
cacheUrl?: string;
|
|
13
|
+
runtimeUrl?: string;
|
|
14
|
+
renderSettings?: {
|
|
15
|
+
method: RenderMethod;
|
|
16
|
+
timeout?: number;
|
|
17
|
+
};
|
|
18
|
+
_versionId?: string;
|
|
19
|
+
ssr?: boolean;
|
|
20
|
+
localeCookieName?: string;
|
|
21
|
+
translations?: Translations | null;
|
|
22
|
+
loadDictionary?: CustomLoader;
|
|
23
|
+
loadTranslations?: CustomLoader;
|
|
24
|
+
config?: GTConfig;
|
|
25
|
+
fallback?: React.ReactNode;
|
|
26
|
+
customMapping?: CustomMapping;
|
|
27
|
+
modelProvider?: string;
|
|
28
|
+
[key: string]: any;
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../../src/types/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,QAAQ,EACT,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAE9D,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE;QACf,MAAM,EAAE,YAAY,CAAC;QACrB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC;IACF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,YAAY,GAAG,IAAI,CAAC;IACnC,cAAc,CAAC,EAAE,YAAY,CAAC;IAC9B,gBAAgB,CAAC,EAAE,YAAY,CAAC;IAChC,MAAM,CAAC,EAAE,QAAQ,CAAC;IAClB,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get native device locales in preference order
|
|
3
|
+
* Returns an empty array if detection fails or is not supported
|
|
4
|
+
*
|
|
5
|
+
* iOS: Returns current locale first, followed by preferred languages
|
|
6
|
+
* Android: Returns user's preferred language list (LocaleList on API 24+, single locale on older versions)
|
|
7
|
+
* Web: Returns browser language preferences from navigator
|
|
8
|
+
*/
|
|
9
|
+
export declare function getNativeLocales(): string[];
|
|
10
|
+
//# sourceMappingURL=getNativeLocales.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getNativeLocales.d.ts","sourceRoot":"","sources":["../../../../src/utils/getNativeLocales.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAa3C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Native store interface, used to replace cookie behavior from gt-react
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Get a value from the native store
|
|
6
|
+
* @param key - The key to get the value for
|
|
7
|
+
* @returns The value for the key
|
|
8
|
+
*/
|
|
9
|
+
export declare function nativeStoreGet(key: string): string | null;
|
|
10
|
+
/**
|
|
11
|
+
* Set a value in the native store
|
|
12
|
+
* @param key - The key to set the value for
|
|
13
|
+
* @param value - The value to set
|
|
14
|
+
*/
|
|
15
|
+
export declare function nativeStoreSet(key: string, value: string): void;
|
|
16
|
+
//# sourceMappingURL=nativeStore.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"nativeStore.d.ts","sourceRoot":"","sources":["../../../../src/utils/nativeStore.ts"],"names":[],"mappings":"AAGA;;GAEG;AAEH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAKzD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAM/D"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import '@formatjs/intl-getcanonicallocales/polyfill';
|
|
2
|
+
import '@formatjs/intl-locale/polyfill';
|
|
3
|
+
import '@formatjs/intl-displaynames/polyfill';
|
|
4
|
+
import '@formatjs/intl-listformat/polyfill';
|
|
5
|
+
import '@formatjs/intl-pluralrules/polyfill-force';
|
|
6
|
+
import '@formatjs/intl-numberformat/polyfill';
|
|
7
|
+
import '@formatjs/intl-relativetimeformat/polyfill';
|
|
8
|
+
import '@formatjs/intl-datetimeformat/polyfill';
|
|
9
|
+
import '@formatjs/intl-datetimeformat/add-all-tz';
|
|
10
|
+
import '@formatjs/intl-displaynames/locale-data/en';
|
|
11
|
+
import '@formatjs/intl-displaynames/locale-data/zh';
|
|
12
|
+
import '@formatjs/intl-displaynames/locale-data/es';
|
|
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
|
+
import '@formatjs/intl-pluralrules/locale-data/en';
|
|
17
|
+
import '@formatjs/intl-pluralrules/locale-data/zh';
|
|
18
|
+
import '@formatjs/intl-pluralrules/locale-data/es';
|
|
19
|
+
import '@formatjs/intl-numberformat/locale-data/en';
|
|
20
|
+
import '@formatjs/intl-numberformat/locale-data/zh';
|
|
21
|
+
import '@formatjs/intl-numberformat/locale-data/es';
|
|
22
|
+
import '@formatjs/intl-relativetimeformat/locale-data/en';
|
|
23
|
+
import '@formatjs/intl-relativetimeformat/locale-data/zh';
|
|
24
|
+
import '@formatjs/intl-relativetimeformat/locale-data/es';
|
|
25
|
+
import '@formatjs/intl-datetimeformat/locale-data/en';
|
|
26
|
+
import '@formatjs/intl-datetimeformat/locale-data/zh';
|
|
27
|
+
import '@formatjs/intl-datetimeformat/locale-data/es';
|
|
28
|
+
//# sourceMappingURL=polyfill.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"polyfill.d.ts","sourceRoot":"","sources":["../../../../src/utils/polyfill.ts"],"names":[],"mappings":"AAGA,OAAO,6CAA6C,CAAC;AACrD,OAAO,gCAAgC,CAAC;AACxC,OAAO,sCAAsC,CAAC;AAC9C,OAAO,oCAAoC,CAAC;AAC5C,OAAO,2CAA2C,CAAC;AACnD,OAAO,sCAAsC,CAAC;AAC9C,OAAO,4CAA4C,CAAC;AACpD,OAAO,wCAAwC,CAAC;AAChD,OAAO,0CAA0C,CAAC;AAElD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AAEpD,OAAO,0CAA0C,CAAC;AAClD,OAAO,0CAA0C,CAAC;AAClD,OAAO,0CAA0C,CAAC;AAElD,OAAO,2CAA2C,CAAC;AACnD,OAAO,2CAA2C,CAAC;AACnD,OAAO,2CAA2C,CAAC;AAEnD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AACpD,OAAO,4CAA4C,CAAC;AAEpD,OAAO,kDAAkD,CAAC;AAC1D,OAAO,kDAAkD,CAAC;AAC1D,OAAO,kDAAkD,CAAC;AAE1D,OAAO,8CAA8C,CAAC;AACtD,OAAO,8CAA8C,CAAC;AACtD,OAAO,8CAA8C,CAAC"}
|
|
@@ -0,0 +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"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,157 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gt-react-native",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
|
|
3
|
+
"version": "0.0.1-alpha.10",
|
|
4
|
+
"description": "An i18n package for React Native",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"!ios/build",
|
|
23
|
+
"!android/build",
|
|
24
|
+
"!android/gradle",
|
|
25
|
+
"!android/gradlew",
|
|
26
|
+
"!android/gradlew.bat",
|
|
27
|
+
"!android/local.properties",
|
|
28
|
+
"!**/__tests__",
|
|
29
|
+
"!**/__fixtures__",
|
|
30
|
+
"!**/__mocks__",
|
|
31
|
+
"!**/.*"
|
|
32
|
+
],
|
|
9
33
|
"scripts": {
|
|
10
|
-
"
|
|
34
|
+
"example": "yarn workspace gt-react-native-example",
|
|
35
|
+
"test": "jest",
|
|
36
|
+
"typecheck": "tsc",
|
|
37
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
38
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
39
|
+
"prepare": "bob build",
|
|
40
|
+
"release": "yarn clean && yarn prepare && npm publish --tag latest",
|
|
41
|
+
"release:alpha": "yarn clean && yarn prepare && npm publish --tag alpha"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/generaltranslation/gt-react-native.git"
|
|
51
|
+
},
|
|
52
|
+
"author": "General Translation, Inc. <support@generaltranslation.com> (https://generaltranslation.com)",
|
|
53
|
+
"license": "FSL-1.1-ALv2",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/generaltranslation/gt-react-native/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/generaltranslation/gt-react-native#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
63
|
+
"@eslint/compat": "^1.3.2",
|
|
64
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
65
|
+
"@eslint/js": "^9.35.0",
|
|
66
|
+
"@evilmartians/lefthook": "^1.12.3",
|
|
67
|
+
"@react-native-community/cli": "20.0.1",
|
|
68
|
+
"@react-native/babel-preset": "0.81.1",
|
|
69
|
+
"@react-native/eslint-config": "^0.81.1",
|
|
70
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
71
|
+
"@types/jest": "^29.5.14",
|
|
72
|
+
"@types/react": "^19.1.0",
|
|
73
|
+
"commitlint": "^19.8.1",
|
|
74
|
+
"del-cli": "^6.0.0",
|
|
75
|
+
"eslint": "^9.35.0",
|
|
76
|
+
"eslint-config-prettier": "^10.1.8",
|
|
77
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
78
|
+
"jest": "^29.7.0",
|
|
79
|
+
"prettier": "^3.6.2",
|
|
80
|
+
"react": "19.1.0",
|
|
81
|
+
"react-native": "0.81.1",
|
|
82
|
+
"react-native-builder-bob": "^0.40.13",
|
|
83
|
+
"turbo": "^2.5.6",
|
|
84
|
+
"typescript": "^5.9.2"
|
|
85
|
+
},
|
|
86
|
+
"dependencies": {
|
|
87
|
+
"@formatjs/intl-datetimeformat": "^6.18.2",
|
|
88
|
+
"@formatjs/intl-displaynames": "^6.8.13",
|
|
89
|
+
"@formatjs/intl-getcanonicallocales": "^2.5.6",
|
|
90
|
+
"@formatjs/intl-listformat": "^7.7.13",
|
|
91
|
+
"@formatjs/intl-locale": "^4.2.13",
|
|
92
|
+
"@formatjs/intl-numberformat": "^8.15.6",
|
|
93
|
+
"@formatjs/intl-pluralrules": "^5.4.6",
|
|
94
|
+
"@formatjs/intl-relativetimeformat": "^11.4.13",
|
|
95
|
+
"@generaltranslation/react-core": "^1.0.0",
|
|
96
|
+
"@generaltranslation/supported-locales": "^2.0.16",
|
|
97
|
+
"generaltranslation": "^7.7.0"
|
|
98
|
+
},
|
|
99
|
+
"peerDependencies": {
|
|
100
|
+
"react": "*",
|
|
101
|
+
"react-native": "*"
|
|
102
|
+
},
|
|
103
|
+
"workspaces": [
|
|
104
|
+
"example"
|
|
105
|
+
],
|
|
106
|
+
"packageManager": "yarn@3.6.1",
|
|
107
|
+
"jest": {
|
|
108
|
+
"preset": "react-native",
|
|
109
|
+
"modulePathIgnorePatterns": [
|
|
110
|
+
"<rootDir>/example/node_modules",
|
|
111
|
+
"<rootDir>/lib/"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"commitlint": {
|
|
115
|
+
"extends": [
|
|
116
|
+
"@commitlint/config-conventional"
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
"prettier": {
|
|
120
|
+
"quoteProps": "consistent",
|
|
121
|
+
"singleQuote": true,
|
|
122
|
+
"tabWidth": 2,
|
|
123
|
+
"trailingComma": "es5",
|
|
124
|
+
"useTabs": false
|
|
125
|
+
},
|
|
126
|
+
"react-native-builder-bob": {
|
|
127
|
+
"source": "src",
|
|
128
|
+
"output": "lib",
|
|
129
|
+
"targets": [
|
|
130
|
+
[
|
|
131
|
+
"module",
|
|
132
|
+
{
|
|
133
|
+
"esm": true
|
|
134
|
+
}
|
|
135
|
+
],
|
|
136
|
+
[
|
|
137
|
+
"typescript",
|
|
138
|
+
{
|
|
139
|
+
"project": "tsconfig.build.json"
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
"codegenConfig": {
|
|
145
|
+
"name": "GtReactNativeSpec",
|
|
146
|
+
"type": "modules",
|
|
147
|
+
"jsSrcsDir": "./src",
|
|
148
|
+
"android": {
|
|
149
|
+
"javaPackageName": "com.gtreactnative"
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
"create-react-native-library": {
|
|
153
|
+
"languages": "kotlin-objc",
|
|
154
|
+
"type": "turbo-module",
|
|
155
|
+
"version": "0.54.5"
|
|
11
156
|
}
|
|
12
157
|
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
export interface Spec extends TurboModule {
|
|
4
|
+
multiply(a: number, b: number): number;
|
|
5
|
+
getNativeLocales(): string[];
|
|
6
|
+
nativeStoreGet(key: string): string | null;
|
|
7
|
+
nativeStoreSet(key: string, value: string): void;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const PACKAGE_NAME = 'gt-react';
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import './utils/polyfill';
|
|
2
|
+
import GtReactNative from './NativeGtReactNative';
|
|
3
|
+
|
|
4
|
+
import { GTProvider } from './provider/GTProvider';
|
|
5
|
+
export function multiply(a: number, b: number): number {
|
|
6
|
+
return GtReactNative.multiply(a, b);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
T,
|
|
11
|
+
useGT,
|
|
12
|
+
useTranslations,
|
|
13
|
+
useDefaultLocale,
|
|
14
|
+
useLocale,
|
|
15
|
+
useRegion,
|
|
16
|
+
Var,
|
|
17
|
+
Num,
|
|
18
|
+
Currency,
|
|
19
|
+
DateTime,
|
|
20
|
+
Plural,
|
|
21
|
+
Branch,
|
|
22
|
+
useLocales,
|
|
23
|
+
useLocaleSelector,
|
|
24
|
+
useSetLocale,
|
|
25
|
+
useGTClass,
|
|
26
|
+
useLocaleProperties,
|
|
27
|
+
useRegionSelector,
|
|
28
|
+
useLocaleDirection,
|
|
29
|
+
useMessages,
|
|
30
|
+
msg,
|
|
31
|
+
decodeMsg,
|
|
32
|
+
decodeOptions,
|
|
33
|
+
} from '@generaltranslation/react-core';
|
|
34
|
+
import type {
|
|
35
|
+
DictionaryTranslationOptions,
|
|
36
|
+
InlineTranslationOptions,
|
|
37
|
+
RuntimeTranslationOptions,
|
|
38
|
+
} from '@generaltranslation/react-core/types';
|
|
39
|
+
|
|
40
|
+
export {
|
|
41
|
+
Var,
|
|
42
|
+
Num,
|
|
43
|
+
Currency,
|
|
44
|
+
DateTime,
|
|
45
|
+
T,
|
|
46
|
+
GTProvider,
|
|
47
|
+
Plural,
|
|
48
|
+
Branch,
|
|
49
|
+
useGT,
|
|
50
|
+
useTranslations,
|
|
51
|
+
useDefaultLocale,
|
|
52
|
+
useLocale,
|
|
53
|
+
useLocales,
|
|
54
|
+
useSetLocale,
|
|
55
|
+
useLocaleSelector,
|
|
56
|
+
useRegion,
|
|
57
|
+
useRegionSelector,
|
|
58
|
+
useGTClass,
|
|
59
|
+
useLocaleProperties,
|
|
60
|
+
useLocaleDirection,
|
|
61
|
+
type DictionaryTranslationOptions,
|
|
62
|
+
type InlineTranslationOptions,
|
|
63
|
+
type RuntimeTranslationOptions,
|
|
64
|
+
msg,
|
|
65
|
+
decodeMsg,
|
|
66
|
+
decodeOptions,
|
|
67
|
+
useMessages,
|
|
68
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useDetermineLocale } from './hooks/locale/useDetermineLocale';
|
|
2
|
+
import type { GTProviderProps } from '../types/config';
|
|
3
|
+
import { GTProvider as _GTProvider } from '@generaltranslation/react-core';
|
|
4
|
+
import { readAuthFromEnv } from '../utils/utils';
|
|
5
|
+
import { useRegionState } from './hooks/useRegionState';
|
|
6
|
+
|
|
7
|
+
export function GTProvider(props: GTProviderProps): React.JSX.Element {
|
|
8
|
+
return (
|
|
9
|
+
<_GTProvider
|
|
10
|
+
ssr={false}
|
|
11
|
+
environment={__DEV__ ? 'development' : 'production'}
|
|
12
|
+
{...props}
|
|
13
|
+
readAuthFromEnv={readAuthFromEnv}
|
|
14
|
+
useDetermineLocale={useDetermineLocale}
|
|
15
|
+
useRegionState={useRegionState}
|
|
16
|
+
/>
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default GTProvider;
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import { determineLocale, resolveAliasLocale } from 'generaltranslation';
|
|
3
|
+
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
4
|
+
import type { CustomMapping } from 'generaltranslation/types';
|
|
5
|
+
import type {
|
|
6
|
+
UseDetermineLocaleParams,
|
|
7
|
+
UseDetermineLocaleReturn,
|
|
8
|
+
} from '@generaltranslation/react-core/types';
|
|
9
|
+
import { getNativeLocales } from '../../../utils/getNativeLocales';
|
|
10
|
+
import { nativeStoreGet, nativeStoreSet } from '../../../utils/nativeStore';
|
|
11
|
+
|
|
12
|
+
export function useDetermineLocale({
|
|
13
|
+
locale: _locale = '',
|
|
14
|
+
defaultLocale = libraryDefaultLocale,
|
|
15
|
+
locales = [],
|
|
16
|
+
localeCookieName = 'generaltranslation.locale',
|
|
17
|
+
ssr = false, // not relevant
|
|
18
|
+
customMapping,
|
|
19
|
+
}: UseDetermineLocaleParams): UseDetermineLocaleReturn {
|
|
20
|
+
// resolve alias locale
|
|
21
|
+
_locale = resolveAliasLocale(_locale, customMapping);
|
|
22
|
+
locales = locales.map((locale) => resolveAliasLocale(locale, customMapping));
|
|
23
|
+
|
|
24
|
+
const initializeLocale = () => {
|
|
25
|
+
const result = resolveAliasLocale(
|
|
26
|
+
ssr
|
|
27
|
+
? _locale
|
|
28
|
+
? determineLocale(_locale, locales, customMapping) || ''
|
|
29
|
+
: ''
|
|
30
|
+
: getNewLocale({
|
|
31
|
+
_locale,
|
|
32
|
+
locale: _locale,
|
|
33
|
+
locales,
|
|
34
|
+
defaultLocale,
|
|
35
|
+
localeCookieName,
|
|
36
|
+
customMapping,
|
|
37
|
+
}),
|
|
38
|
+
customMapping
|
|
39
|
+
);
|
|
40
|
+
return result;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// maintaining the state of locale
|
|
44
|
+
const [locale, _setLocale] = useState<string>(initializeLocale());
|
|
45
|
+
|
|
46
|
+
// Functions for setting internal locale state
|
|
47
|
+
const [setLocale, setLocaleWithoutPersist] = createSetLocale({
|
|
48
|
+
locale,
|
|
49
|
+
locales,
|
|
50
|
+
defaultLocale,
|
|
51
|
+
localeCookieName,
|
|
52
|
+
_setLocale,
|
|
53
|
+
customMapping,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// check browser for locales
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
const newLocale = getNewLocale({
|
|
59
|
+
_locale,
|
|
60
|
+
locale,
|
|
61
|
+
locales,
|
|
62
|
+
defaultLocale,
|
|
63
|
+
localeCookieName,
|
|
64
|
+
customMapping,
|
|
65
|
+
});
|
|
66
|
+
setLocaleWithoutPersist(newLocale);
|
|
67
|
+
}, [
|
|
68
|
+
_locale,
|
|
69
|
+
locale,
|
|
70
|
+
locales,
|
|
71
|
+
defaultLocale,
|
|
72
|
+
localeCookieName,
|
|
73
|
+
customMapping,
|
|
74
|
+
setLocaleWithoutPersist,
|
|
75
|
+
]);
|
|
76
|
+
|
|
77
|
+
return [locale, setLocale];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ----- HELPER FUNCTIONS ---- //
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Choose a locale to use
|
|
84
|
+
* (1) use provided locale
|
|
85
|
+
* (2) use cookie locale
|
|
86
|
+
* (3) use preferred locale
|
|
87
|
+
* (5) fallback to defaultLocale
|
|
88
|
+
* Update the cookie locale to be correct
|
|
89
|
+
*/
|
|
90
|
+
function getNewLocale({
|
|
91
|
+
_locale,
|
|
92
|
+
locale,
|
|
93
|
+
locales,
|
|
94
|
+
defaultLocale,
|
|
95
|
+
localeCookieName,
|
|
96
|
+
customMapping,
|
|
97
|
+
}: {
|
|
98
|
+
_locale: string;
|
|
99
|
+
locale: string;
|
|
100
|
+
locales: string[];
|
|
101
|
+
defaultLocale: string;
|
|
102
|
+
localeCookieName: string;
|
|
103
|
+
customMapping?: CustomMapping;
|
|
104
|
+
}): string {
|
|
105
|
+
// No change, return
|
|
106
|
+
if (
|
|
107
|
+
_locale &&
|
|
108
|
+
_locale === locale &&
|
|
109
|
+
determineLocale(_locale, locales, customMapping) === locale
|
|
110
|
+
) {
|
|
111
|
+
return resolveAliasLocale(_locale, customMapping);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Check for locale in native store
|
|
115
|
+
let storedLocale = nativeStoreGet(localeCookieName);
|
|
116
|
+
if (storedLocale) {
|
|
117
|
+
storedLocale = resolveAliasLocale(storedLocale, customMapping);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// check user's configured locales
|
|
121
|
+
let preferredLocales = getNativeLocales();
|
|
122
|
+
if (preferredLocales.length === 0) preferredLocales = [defaultLocale];
|
|
123
|
+
preferredLocales = preferredLocales.map((l) =>
|
|
124
|
+
resolveAliasLocale(l, customMapping)
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
// determine locale
|
|
128
|
+
let newLocale =
|
|
129
|
+
determineLocale(
|
|
130
|
+
[
|
|
131
|
+
...(_locale ? [_locale] : []), // prefer user passed locale
|
|
132
|
+
...(storedLocale ? [storedLocale] : []), // then prefer stored locale
|
|
133
|
+
...preferredLocales, // then prefer browser locale
|
|
134
|
+
],
|
|
135
|
+
locales,
|
|
136
|
+
customMapping
|
|
137
|
+
) || defaultLocale;
|
|
138
|
+
if (newLocale) {
|
|
139
|
+
newLocale = resolveAliasLocale(newLocale, customMapping);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// if stored locale not valid, change it back to whatever we use for fallback
|
|
143
|
+
if (storedLocale && storedLocale !== newLocale) {
|
|
144
|
+
nativeStoreSet(localeCookieName, newLocale);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// return new locale
|
|
148
|
+
return newLocale;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function createSetLocale({
|
|
152
|
+
locale,
|
|
153
|
+
locales,
|
|
154
|
+
defaultLocale,
|
|
155
|
+
_setLocale,
|
|
156
|
+
localeCookieName,
|
|
157
|
+
customMapping,
|
|
158
|
+
}: {
|
|
159
|
+
locale: string;
|
|
160
|
+
locales: string[];
|
|
161
|
+
defaultLocale: string;
|
|
162
|
+
localeCookieName: string;
|
|
163
|
+
_setLocale: any;
|
|
164
|
+
customMapping?: CustomMapping;
|
|
165
|
+
}): [(newLocale: string) => void, (newLocale: string) => void] {
|
|
166
|
+
locale = resolveAliasLocale(locale, customMapping);
|
|
167
|
+
// Just update the internal state, don't persist it
|
|
168
|
+
const setLocaleWithoutPersist = (newLocale: string): string => {
|
|
169
|
+
// validate locale
|
|
170
|
+
const validatedLocale = resolveAliasLocale(
|
|
171
|
+
determineLocale(newLocale, locales, customMapping) ||
|
|
172
|
+
locale ||
|
|
173
|
+
defaultLocale,
|
|
174
|
+
customMapping
|
|
175
|
+
);
|
|
176
|
+
if (validatedLocale !== newLocale) {
|
|
177
|
+
console.warn(
|
|
178
|
+
`[gt-react-native] Unsupported locale: ${validatedLocale} -> ${newLocale}`
|
|
179
|
+
);
|
|
180
|
+
}
|
|
181
|
+
// persist locale
|
|
182
|
+
_setLocale(validatedLocale);
|
|
183
|
+
|
|
184
|
+
return validatedLocale;
|
|
185
|
+
};
|
|
186
|
+
// update locale and persist it in native store
|
|
187
|
+
const setLocale = (newLocale: string): void => {
|
|
188
|
+
newLocale = resolveAliasLocale(newLocale, customMapping);
|
|
189
|
+
setLocaleWithoutPersist(newLocale);
|
|
190
|
+
const validatedLocale = setLocaleWithoutPersist(newLocale);
|
|
191
|
+
nativeStoreSet(localeCookieName, validatedLocale);
|
|
192
|
+
};
|
|
193
|
+
return [setLocale, setLocaleWithoutPersist];
|
|
194
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import type {
|
|
3
|
+
UseRegionStateParams,
|
|
4
|
+
UseRegionStateReturn,
|
|
5
|
+
} from '@generaltranslation/react-core/types';
|
|
6
|
+
import { nativeStoreGet, nativeStoreSet } from '../../utils/nativeStore';
|
|
7
|
+
|
|
8
|
+
function getNewRegion({
|
|
9
|
+
_region,
|
|
10
|
+
regionCookieName,
|
|
11
|
+
}: {
|
|
12
|
+
_region: string | undefined;
|
|
13
|
+
regionCookieName: string;
|
|
14
|
+
}) {
|
|
15
|
+
// Check for region in native store
|
|
16
|
+
const cookieRegion = nativeStoreGet(regionCookieName) || undefined;
|
|
17
|
+
const newRegion = _region || cookieRegion;
|
|
18
|
+
|
|
19
|
+
// if state not valid, change it to newRegion
|
|
20
|
+
if (cookieRegion && cookieRegion !== newRegion) {
|
|
21
|
+
nativeStoreSet(regionCookieName, newRegion || '');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return newRegion;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function useRegionState({
|
|
28
|
+
_region,
|
|
29
|
+
ssr,
|
|
30
|
+
regionCookieName,
|
|
31
|
+
}: UseRegionStateParams): UseRegionStateReturn {
|
|
32
|
+
const [region, _setRegion] = useState<string | undefined>(
|
|
33
|
+
ssr
|
|
34
|
+
? undefined
|
|
35
|
+
: getNewRegion({
|
|
36
|
+
_region,
|
|
37
|
+
regionCookieName,
|
|
38
|
+
})
|
|
39
|
+
);
|
|
40
|
+
const setRegion = (newRegion: string | undefined) => {
|
|
41
|
+
_setRegion(newRegion);
|
|
42
|
+
nativeStoreSet(regionCookieName, newRegion || '');
|
|
43
|
+
};
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
_setRegion(getNewRegion({ _region, regionCookieName }));
|
|
46
|
+
}, [_region, regionCookieName]);
|
|
47
|
+
return {
|
|
48
|
+
region,
|
|
49
|
+
setRegion,
|
|
50
|
+
};
|
|
51
|
+
}
|