gt-react-native 10.19.16 → 10.19.18
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 +9 -7
- package/dist/commonjs/NativeGtReactNative.js.map +1 -1
- package/dist/commonjs/_virtual/_rolldown/runtime.js +23 -0
- package/dist/commonjs/errors-dir/constants.js +5 -6
- package/dist/commonjs/errors-dir/constants.js.map +1 -1
- package/dist/commonjs/errors-dir/errors.js +12 -7
- package/dist/commonjs/errors-dir/errors.js.map +1 -1
- package/dist/commonjs/errors-dir/warnings.js +34 -15
- package/dist/commonjs/errors-dir/warnings.js.map +1 -1
- package/dist/commonjs/index.js +35 -194
- package/dist/commonjs/internal.js +3 -13
- package/dist/commonjs/plugin-dir/index.js +35 -51
- package/dist/commonjs/plugin-dir/index.js.map +1 -1
- package/dist/commonjs/plugin-dir/types.js +24 -9
- package/dist/commonjs/plugin-dir/types.js.map +1 -1
- package/dist/commonjs/plugin-dir/utils/resolveLocales.js +52 -69
- package/dist/commonjs/plugin-dir/utils/resolveLocales.js.map +1 -1
- package/dist/commonjs/plugin.js +5 -13
- package/dist/commonjs/provider/GTProvider.js +22 -20
- package/dist/commonjs/provider/GTProvider.js.map +1 -1
- package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js +96 -160
- package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js.map +1 -1
- package/dist/commonjs/provider/hooks/useRegionState.js +32 -44
- package/dist/commonjs/provider/hooks/useRegionState.js.map +1 -1
- package/dist/commonjs/tools/testLocalePolyfill.js +125 -146
- package/dist/commonjs/tools/testLocalePolyfill.js.map +1 -1
- package/dist/commonjs/types/config.js +1 -6
- package/dist/commonjs/utils/getNativeLocales.js +36 -54
- package/dist/commonjs/utils/getNativeLocales.js.map +1 -1
- package/dist/commonjs/utils/nativeStore.js +37 -42
- package/dist/commonjs/utils/nativeStore.js.map +1 -1
- package/dist/commonjs/utils/utils.js +10 -14
- package/dist/commonjs/utils/utils.js.map +1 -1
- package/dist/module/NativeGtReactNative.d.ts.map +1 -0
- package/dist/module/NativeGtReactNative.js +5 -3
- package/dist/module/NativeGtReactNative.js.map +1 -1
- package/dist/module/errors-dir/constants.d.ts.map +1 -0
- package/dist/module/errors-dir/constants.js +4 -2
- package/dist/module/errors-dir/constants.js.map +1 -1
- package/dist/module/errors-dir/errors.d.ts.map +1 -0
- package/dist/module/errors-dir/errors.js +11 -3
- package/dist/module/errors-dir/errors.js.map +1 -1
- package/dist/{typescript/commonjs/src → module}/errors-dir/warnings.d.ts +1 -1
- package/dist/module/errors-dir/warnings.d.ts.map +1 -0
- package/dist/module/errors-dir/warnings.js +31 -11
- package/dist/module/errors-dir/warnings.js.map +1 -1
- package/dist/module/index.d.ts.map +1 -0
- package/dist/module/index.js +2 -5
- package/dist/module/internal.d.ts.map +1 -0
- package/dist/module/internal.js +2 -4
- package/dist/module/plugin-dir/index.d.ts.map +1 -0
- package/dist/module/plugin-dir/index.js +28 -45
- package/dist/module/plugin-dir/index.js.map +1 -1
- package/dist/module/plugin-dir/types.d.ts.map +1 -0
- package/dist/module/plugin-dir/types.js +22 -5
- package/dist/module/plugin-dir/types.js.map +1 -1
- package/dist/module/plugin-dir/utils/resolveLocales.d.ts.map +1 -0
- package/dist/module/plugin-dir/utils/resolveLocales.js +46 -62
- package/dist/module/plugin-dir/utils/resolveLocales.js.map +1 -1
- package/dist/module/plugin.d.ts.map +1 -0
- package/dist/module/plugin.js +2 -4
- package/dist/module/provider/GTProvider.d.ts.map +1 -0
- package/dist/module/provider/GTProvider.js +15 -14
- package/dist/module/provider/GTProvider.js.map +1 -1
- package/dist/module/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
- package/dist/module/provider/hooks/locale/useDetermineLocale.js +91 -153
- package/dist/module/provider/hooks/locale/useDetermineLocale.js.map +1 -1
- package/dist/module/provider/hooks/useRegionState.d.ts.map +1 -0
- package/dist/module/provider/hooks/useRegionState.js +29 -39
- package/dist/module/provider/hooks/useRegionState.js.map +1 -1
- package/dist/module/tools/testLocalePolyfill.d.ts.map +1 -0
- package/dist/module/tools/testLocalePolyfill.js +124 -143
- package/dist/module/tools/testLocalePolyfill.js.map +1 -1
- package/dist/module/types/config.d.ts.map +1 -0
- package/dist/module/types/config.js +0 -3
- package/dist/module/utils/getNativeLocales.d.ts.map +1 -0
- package/dist/module/utils/getNativeLocales.js +35 -51
- package/dist/module/utils/getNativeLocales.js.map +1 -1
- package/dist/module/utils/nativeStore.d.ts.map +1 -0
- package/dist/module/utils/nativeStore.js +35 -38
- package/dist/module/utils/nativeStore.js.map +1 -1
- package/dist/module/utils/utils.d.ts.map +1 -0
- package/dist/module/utils/utils.js +10 -11
- package/dist/module/utils/utils.js.map +1 -1
- package/package.json +15 -37
- package/src/errors-dir/errors.ts +8 -1
- package/src/errors-dir/warnings.ts +30 -9
- package/dist/commonjs/index.js.map +0 -1
- package/dist/commonjs/internal.js.map +0 -1
- package/dist/commonjs/package.json +0 -1
- package/dist/commonjs/plugin.js.map +0 -1
- package/dist/commonjs/types/config.js.map +0 -1
- package/dist/module/index.js.map +0 -1
- package/dist/module/internal.js.map +0 -1
- package/dist/module/package.json +0 -1
- package/dist/module/plugin.js.map +0 -1
- package/dist/module/types/config.js.map +0 -1
- package/dist/typescript/commonjs/package.json +0 -1
- package/dist/typescript/commonjs/src/NativeGtReactNative.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/errors-dir/constants.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/errors-dir/errors.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/errors-dir/warnings.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/index.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/internal.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/plugin-dir/index.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/plugin-dir/types.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/plugin-dir/utils/resolveLocales.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/plugin.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/provider/GTProvider.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/provider/hooks/useRegionState.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/tools/testLocalePolyfill.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/types/config.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/utils/getNativeLocales.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/utils/nativeStore.d.ts.map +0 -1
- package/dist/typescript/commonjs/src/utils/utils.d.ts.map +0 -1
- package/dist/typescript/module/package.json +0 -1
- package/dist/typescript/module/src/NativeGtReactNative.d.ts +0 -10
- package/dist/typescript/module/src/NativeGtReactNative.d.ts.map +0 -1
- package/dist/typescript/module/src/errors-dir/constants.d.ts +0 -2
- package/dist/typescript/module/src/errors-dir/constants.d.ts.map +0 -1
- package/dist/typescript/module/src/errors-dir/errors.d.ts +0 -2
- package/dist/typescript/module/src/errors-dir/errors.d.ts.map +0 -1
- package/dist/typescript/module/src/errors-dir/warnings.d.ts +0 -5
- package/dist/typescript/module/src/errors-dir/warnings.d.ts.map +0 -1
- package/dist/typescript/module/src/index.d.ts +0 -5
- package/dist/typescript/module/src/index.d.ts.map +0 -1
- package/dist/typescript/module/src/internal.d.ts +0 -2
- package/dist/typescript/module/src/internal.d.ts.map +0 -1
- package/dist/typescript/module/src/plugin-dir/index.d.ts +0 -6
- package/dist/typescript/module/src/plugin-dir/index.d.ts.map +0 -1
- package/dist/typescript/module/src/plugin-dir/types.d.ts +0 -13
- package/dist/typescript/module/src/plugin-dir/types.d.ts.map +0 -1
- package/dist/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts +0 -13
- package/dist/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts.map +0 -1
- package/dist/typescript/module/src/plugin.d.ts +0 -2
- package/dist/typescript/module/src/plugin.d.ts.map +0 -1
- package/dist/typescript/module/src/provider/GTProvider.d.ts +0 -4
- package/dist/typescript/module/src/provider/GTProvider.d.ts.map +0 -1
- package/dist/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts +0 -4
- package/dist/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
- package/dist/typescript/module/src/provider/hooks/useRegionState.d.ts +0 -3
- package/dist/typescript/module/src/provider/hooks/useRegionState.d.ts.map +0 -1
- package/dist/typescript/module/src/tools/testLocalePolyfill.d.ts +0 -8
- package/dist/typescript/module/src/tools/testLocalePolyfill.d.ts.map +0 -1
- package/dist/typescript/module/src/types/config.d.ts +0 -30
- package/dist/typescript/module/src/types/config.d.ts.map +0 -1
- package/dist/typescript/module/src/utils/getNativeLocales.d.ts +0 -10
- package/dist/typescript/module/src/utils/getNativeLocales.d.ts.map +0 -1
- package/dist/typescript/module/src/utils/nativeStore.d.ts +0 -16
- package/dist/typescript/module/src/utils/nativeStore.d.ts.map +0 -1
- package/dist/typescript/module/src/utils/utils.d.ts +0 -3
- package/dist/typescript/module/src/utils/utils.d.ts.map +0 -1
- /package/dist/{typescript/commonjs/src → module}/NativeGtReactNative.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/errors-dir/constants.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/errors-dir/errors.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/index.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/internal.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/plugin-dir/index.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/plugin-dir/types.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/plugin-dir/utils/resolveLocales.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/plugin.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/provider/GTProvider.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/provider/hooks/locale/useDetermineLocale.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/provider/hooks/useRegionState.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/tools/testLocalePolyfill.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/types/config.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/utils/getNativeLocales.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/utils/nativeStore.d.ts +0 -0
- /package/dist/{typescript/commonjs/src → module}/utils/utils.d.ts +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"nativeStore.js","names":["Platform","ssrUnsupportedWarning","GtReactNative"],"sources":["../../../src/utils/nativeStore.ts"],"sourcesContent":["import { Platform } from 'react-native';\nimport GtReactNative from '../NativeGtReactNative';\nimport { ssrUnsupportedWarning } from '../errors-dir/warnings';\n\n/**\n * Native store interface, used to replace cookie behavior from gt-react\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":";;;;;;;;;;;;;;AAaA,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,QAAc,eAAe,IAAI;;;;;;;AAQ1C,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,QAAc,eAAe,KAAK,MAAM"}
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.readAuthFromEnv = readAuthFromEnv;
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region src/utils/utils.ts
|
|
7
3
|
function readAuthFromEnv(params) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
projectId: projectId || '',
|
|
14
|
-
devApiKey: devApiKey
|
|
15
|
-
};
|
|
4
|
+
const { projectId, devApiKey } = params;
|
|
5
|
+
return {
|
|
6
|
+
projectId: projectId || "",
|
|
7
|
+
devApiKey
|
|
8
|
+
};
|
|
16
9
|
}
|
|
10
|
+
//#endregion
|
|
11
|
+
exports.readAuthFromEnv = readAuthFromEnv;
|
|
12
|
+
|
|
17
13
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -0,0 +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;;AAED,wBAAuE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { TurboModuleRegistry } from "react-native";
|
|
2
|
+
//#region src/NativeGtReactNative.ts
|
|
3
|
+
var NativeGtReactNative_default = TurboModuleRegistry.getEnforcing("GtReactNative");
|
|
4
|
+
//#endregion
|
|
5
|
+
export { NativeGtReactNative_default as default };
|
|
2
6
|
|
|
3
|
-
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
-
export default TurboModuleRegistry.getEnforcing('GtReactNative');
|
|
5
7
|
//# sourceMappingURL=NativeGtReactNative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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 default TurboModuleRegistry.getEnforcing<Spec>('GtReactNative');\n"],"mappings":";;AASA,IAAA,8BAAe,oBAAoB,aAAmB,gBAAgB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../src/errors-dir/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/errors-dir/constants.ts"],"sourcesContent":["export const PACKAGE_NAME = 'gt-react-native';\n"],"mappings":";AAAA,MAAa,eAAe"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors-dir/errors.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,WAMxD,CAAC"}
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
import { PACKAGE_NAME } from "./constants.js";
|
|
4
|
-
|
|
2
|
+
import { createDiagnosticMessage } from "generaltranslation/internal";
|
|
3
|
+
//#region src/errors-dir/errors.ts
|
|
4
|
+
const failedToReadConfigFileError = (filePath) => createDiagnosticMessage({
|
|
5
|
+
source: PACKAGE_NAME,
|
|
6
|
+
severity: "Error",
|
|
7
|
+
whatHappened: `GT Config at ${filePath} could not be read`,
|
|
8
|
+
fix: "Check that the file exists and contains valid JSON"
|
|
9
|
+
});
|
|
10
|
+
//#endregion
|
|
11
|
+
export { failedToReadConfigFileError };
|
|
12
|
+
|
|
5
13
|
//# sourceMappingURL=errors.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"errors.js","names":[],"sources":["../../../src/errors-dir/errors.ts"],"sourcesContent":["import { createDiagnosticMessage } from 'generaltranslation/internal';\nimport { PACKAGE_NAME } from './constants';\n\nexport const failedToReadConfigFileError = (filePath: string) =>\n createDiagnosticMessage({\n source: PACKAGE_NAME,\n severity: 'Error',\n whatHappened: `GT Config at ${filePath} could not be read`,\n fix: 'Check that the file exists and contains valid JSON',\n });\n"],"mappings":";;;AAGA,MAAa,+BAA+B,aAC1C,wBAAwB;CACtB,QAAQ;CACR,UAAU;CACV,cAAc,gBAAgB,SAAS;CACvC,KAAK;CACN,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export declare const resolveLocalesFailedWarning: string;
|
|
2
2
|
export declare const couldNotLocateConfigWarning: (filePath: string) => string;
|
|
3
3
|
export declare const invalidLocalesWarning: (invalidLocales: string[]) => string;
|
|
4
|
-
export declare const ssrUnsupportedWarning
|
|
4
|
+
export declare const ssrUnsupportedWarning: string;
|
|
5
5
|
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","sourceRoot":"","sources":["../../../src/errors-dir/warnings.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,2BAA2B,QAMtC,CAAC;AAEH,eAAO,MAAM,2BAA2B,GAAI,UAAU,MAAM,WAMxD,CAAC;AAEL,eAAO,MAAM,qBAAqB,GAAI,gBAAgB,MAAM,EAAE,WAO1D,CAAC;AAEL,eAAO,MAAM,qBAAqB,QAKhC,CAAC"}
|
|
@@ -1,13 +1,33 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
4
1
|
import { PACKAGE_NAME } from "./constants.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
2
|
+
import { createDiagnosticMessage, libraryDefaultLocale } from "generaltranslation/internal";
|
|
3
|
+
//#region src/errors-dir/warnings.ts
|
|
4
|
+
const resolveLocalesFailedWarning = createDiagnosticMessage({
|
|
5
|
+
source: PACKAGE_NAME,
|
|
6
|
+
severity: "Warning",
|
|
7
|
+
whatHappened: "Locales for the polyfill could not be resolved",
|
|
8
|
+
fix: "Provide locales directly, pass your GT Config to the plugin, or provide the path to your GT Config file",
|
|
9
|
+
wayOut: `The library will fall back to ${libraryDefaultLocale}`
|
|
10
|
+
});
|
|
11
|
+
const couldNotLocateConfigWarning = (filePath) => createDiagnosticMessage({
|
|
12
|
+
source: PACKAGE_NAME,
|
|
13
|
+
severity: "Warning",
|
|
14
|
+
whatHappened: `GT Config could not be found at ${filePath}`,
|
|
15
|
+
fix: "Check the path or pass locales directly to the plugin"
|
|
16
|
+
});
|
|
17
|
+
const invalidLocalesWarning = (invalidLocales) => createDiagnosticMessage({
|
|
18
|
+
source: PACKAGE_NAME,
|
|
19
|
+
severity: "Warning",
|
|
20
|
+
whatHappened: "GT Config contains invalid locales",
|
|
21
|
+
fix: "Use valid BCP 47 locale codes or add custom mappings",
|
|
22
|
+
details: invalidLocales
|
|
23
|
+
});
|
|
24
|
+
const ssrUnsupportedWarning = createDiagnosticMessage({
|
|
25
|
+
source: PACKAGE_NAME,
|
|
26
|
+
severity: "Warning",
|
|
27
|
+
whatHappened: "Server-side environments are not explicitly supported",
|
|
28
|
+
wayOut: "Some features may not work as expected"
|
|
29
|
+
});
|
|
30
|
+
//#endregion
|
|
31
|
+
export { couldNotLocateConfigWarning, invalidLocalesWarning, resolveLocalesFailedWarning, ssrUnsupportedWarning };
|
|
32
|
+
|
|
13
33
|
//# sourceMappingURL=warnings.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"warnings.js","names":[],"sources":["../../../src/errors-dir/warnings.ts"],"sourcesContent":["import {\n createDiagnosticMessage,\n libraryDefaultLocale,\n} from 'generaltranslation/internal';\nimport { PACKAGE_NAME } from './constants';\n\nexport const resolveLocalesFailedWarning = createDiagnosticMessage({\n source: PACKAGE_NAME,\n severity: 'Warning',\n whatHappened: 'Locales for the polyfill could not be resolved',\n fix: 'Provide locales directly, pass your GT Config to the plugin, or provide the path to your GT Config file',\n wayOut: `The library will fall back to ${libraryDefaultLocale}`,\n});\n\nexport const couldNotLocateConfigWarning = (filePath: string) =>\n createDiagnosticMessage({\n source: PACKAGE_NAME,\n severity: 'Warning',\n whatHappened: `GT Config could not be found at ${filePath}`,\n fix: 'Check the path or pass locales directly to the plugin',\n });\n\nexport const invalidLocalesWarning = (invalidLocales: string[]) =>\n createDiagnosticMessage({\n source: PACKAGE_NAME,\n severity: 'Warning',\n whatHappened: 'GT Config contains invalid locales',\n fix: 'Use valid BCP 47 locale codes or add custom mappings',\n details: invalidLocales,\n });\n\nexport const ssrUnsupportedWarning = createDiagnosticMessage({\n source: PACKAGE_NAME,\n severity: 'Warning',\n whatHappened: 'Server-side environments are not explicitly supported',\n wayOut: 'Some features may not work as expected',\n});\n"],"mappings":";;;AAMA,MAAa,8BAA8B,wBAAwB;CACjE,QAAQ;CACR,UAAU;CACV,cAAc;CACd,KAAK;CACL,QAAQ,iCAAiC;CAC1C,CAAC;AAEF,MAAa,+BAA+B,aAC1C,wBAAwB;CACtB,QAAQ;CACR,UAAU;CACV,cAAc,mCAAmC;CACjD,KAAK;CACN,CAAC;AAEJ,MAAa,yBAAyB,mBACpC,wBAAwB;CACtB,QAAQ;CACR,UAAU;CACV,cAAc;CACd,KAAK;CACL,SAAS;CACV,CAAC;AAEJ,MAAa,wBAAwB,wBAAwB;CAC3D,QAAQ;CACR,UAAU;CACV,cAAc;CACd,QAAQ;CACT,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAEnD,OAAO,EACL,CAAC,EACD,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,EACN,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,YAAY,EACZ,UAAU,EACV,mBAAmB,EACnB,iBAAiB,EACjB,kBAAkB,EAClB,WAAW,EACX,GAAG,EACH,SAAS,EACT,aAAa,EACb,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,UAAU,EACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EACV,4BAA4B,EAC5B,wBAAwB,EACxB,yBAAyB,EAC1B,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EACL,MAAM,EACN,GAAG,EACH,GAAG,EACH,QAAQ,EACR,QAAQ,EACR,CAAC,EACD,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,eAAe,EACf,gBAAgB,EAChB,SAAS,EACT,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,SAAS,EACT,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,YAAY,EACZ,KAAK,4BAA4B,EACjC,KAAK,wBAAwB,EAC7B,KAAK,yBAAyB,EAC9B,GAAG,EACH,SAAS,EACT,aAAa,EACb,WAAW,EACX,UAAU,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,UAAU,GACX,CAAC"}
|
package/dist/module/index.js
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
import { GTProvider } from "./provider/GTProvider.js";
|
|
4
|
-
import {
|
|
5
|
-
export {
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
2
|
+
import { Branch, Currency, DateTime, Num, Plural, Static, T, Var, declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, gtFallback, mFallback, msg, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useSetLocale, useTranslations, useVersionId } from "@generaltranslation/react-core";
|
|
3
|
+
export { Branch, Currency, DateTime, GTProvider, Num, Plural, Static, T, Var, declareStatic, declareVar, decodeMsg, decodeOptions, decodeVars, gtFallback, mFallback, msg, useDefaultLocale, useGT, useGTClass, useLocale, useLocaleDirection, useLocaleProperties, useLocaleSelector, useLocales, useMessages, useRegion, useRegionSelector, useSetLocale, useTranslations, useVersionId };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../../src/internal.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/module/internal.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugin-dir/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAA+B,KAAK,aAAa,EAAE,MAAM,SAAS,CAAC;AAG1E,MAAM,CAAC,OAAO,WACZ,KAAK,EAAE;IAAE,KAAK,EAAE,OAAO,KAAK,CAAA;CAAE,EAC9B,EACE,OAAO,EACP,MAAM,EACN,cAAc,EACd,kBAAkE,EAClE,gBAAqB,GACtB,EAAE,aAAa,GACf,SAAS,CAuDX"}
|
|
@@ -1,49 +1,32 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import * as path from 'path';
|
|
4
1
|
import { LOCALE_POLYFILLS, POLYFILLS } from "./types.js";
|
|
5
2
|
import { resolveLocales } from "./utils/resolveLocales.js";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// TODO: smart imports based on if the polyfill is required, do this as a wrapper around AppRegistry.registerComponent()
|
|
33
|
-
const imports = [...POLYFILLS.filter(polyfill => !excludePolyfills.includes(polyfill)), ...resolvedLocales.flatMap(locale => LOCALE_POLYFILLS.map(localeData => `${localeData}/${locale}`))];
|
|
34
|
-
const existingImports = new Set();
|
|
35
|
-
programPath.node.body.forEach(node => {
|
|
36
|
-
if (t.isImportDeclaration(node) && typeof node.source.value === 'string' && imports.includes(node.source.value)) {
|
|
37
|
-
existingImports.add(node.source.value);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
const importsToAdd = imports.filter(imp => !existingImports.has(imp));
|
|
41
|
-
if (importsToAdd.length > 0) {
|
|
42
|
-
const newImports = importsToAdd.map(importPath => t.importDeclaration([], t.stringLiteral(importPath)));
|
|
43
|
-
programPath.node.body.unshift(...newImports);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
};
|
|
3
|
+
import * as path$1 from "path";
|
|
4
|
+
//#region src/plugin-dir/index.ts
|
|
5
|
+
function plugin_dir_default(babel, { locales, config, configFilePath, entryPointFilePath = path$1.resolve(process.cwd(), "src", "App.tsx"), excludePolyfills = [] }) {
|
|
6
|
+
const { types: t } = babel;
|
|
7
|
+
return {
|
|
8
|
+
name: "gt-react-native/plugin",
|
|
9
|
+
visitor: { Program(programPath, state) {
|
|
10
|
+
if (path$1.resolve(state.filename || state.file.opts.filename || "") !== entryPointFilePath) return;
|
|
11
|
+
const resolvedLocales = resolveLocales({
|
|
12
|
+
locales,
|
|
13
|
+
config,
|
|
14
|
+
configFilePath
|
|
15
|
+
});
|
|
16
|
+
const imports = [...POLYFILLS.filter((polyfill) => !excludePolyfills.includes(polyfill)), ...resolvedLocales.flatMap((locale) => LOCALE_POLYFILLS.map((localeData) => `${localeData}/${locale}`))];
|
|
17
|
+
const existingImports = /* @__PURE__ */ new Set();
|
|
18
|
+
programPath.node.body.forEach((node) => {
|
|
19
|
+
if (t.isImportDeclaration(node) && typeof node.source.value === "string" && imports.includes(node.source.value)) existingImports.add(node.source.value);
|
|
20
|
+
});
|
|
21
|
+
const importsToAdd = imports.filter((imp) => !existingImports.has(imp));
|
|
22
|
+
if (importsToAdd.length > 0) {
|
|
23
|
+
const newImports = importsToAdd.map((importPath) => t.importDeclaration([], t.stringLiteral(importPath)));
|
|
24
|
+
programPath.node.body.unshift(...newImports);
|
|
25
|
+
}
|
|
26
|
+
} }
|
|
27
|
+
};
|
|
48
28
|
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { plugin_dir_default as default };
|
|
31
|
+
|
|
49
32
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["path","
|
|
1
|
+
{"version":3,"file":"index.js","names":["path"],"sources":["../../../src/plugin-dir/index.ts"],"sourcesContent":["import * as path from 'path';\nimport type { PluginObj, types } from '@babel/core';\nimport { LOCALE_POLYFILLS, POLYFILLS, type PluginOptions } from './types';\nimport { resolveLocales } from './utils/resolveLocales';\n\nexport default function (\n babel: { types: typeof types },\n {\n locales,\n config,\n configFilePath,\n entryPointFilePath = path.resolve(process.cwd(), 'src', 'App.tsx'),\n excludePolyfills = [],\n }: PluginOptions\n): PluginObj {\n const { types: t } = babel;\n\n return {\n name: 'gt-react-native/plugin',\n visitor: {\n Program(programPath, state) {\n const currentFilePath = path.resolve(\n state.filename || state.file.opts.filename || ''\n );\n\n // Only apply polyfills to files that import gt-react-native or generaltranslation\n if (currentFilePath !== entryPointFilePath) {\n return;\n }\n\n const resolvedLocales = resolveLocales({\n locales,\n config,\n configFilePath,\n });\n\n // TODO: smart imports based on if the polyfill is required, do this as a wrapper around AppRegistry.registerComponent()\n const imports = [\n ...POLYFILLS.filter(\n (polyfill) => !excludePolyfills.includes(polyfill)\n ),\n ...resolvedLocales.flatMap((locale) =>\n LOCALE_POLYFILLS.map((localeData) => `${localeData}/${locale}`)\n ),\n ];\n\n const existingImports = new Set<string>();\n programPath.node.body.forEach((node) => {\n if (\n t.isImportDeclaration(node) &&\n typeof node.source.value === 'string' &&\n imports.includes(node.source.value)\n ) {\n existingImports.add(node.source.value);\n }\n });\n\n const importsToAdd = imports.filter((imp) => !existingImports.has(imp));\n\n if (importsToAdd.length > 0) {\n const newImports = importsToAdd.map((importPath) =>\n t.importDeclaration([], t.stringLiteral(importPath))\n );\n\n programPath.node.body.unshift(...newImports);\n }\n },\n },\n };\n}\n"],"mappings":";;;;AAKA,SAAA,mBACE,OACA,EACE,SACA,QACA,gBACA,qBAAqBA,OAAK,QAAQ,QAAQ,KAAK,EAAE,OAAO,UAAU,EAClE,mBAAmB,EAAE,IAEZ;CACX,MAAM,EAAE,OAAO,MAAM;AAErB,QAAO;EACL,MAAM;EACN,SAAS,EACP,QAAQ,aAAa,OAAO;AAM1B,OALwBA,OAAK,QAC3B,MAAM,YAAY,MAAM,KAAK,KAAK,YAAY,GAI7B,KAAK,mBACtB;GAGF,MAAM,kBAAkB,eAAe;IACrC;IACA;IACA;IACD,CAAC;GAGF,MAAM,UAAU,CACd,GAAG,UAAU,QACV,aAAa,CAAC,iBAAiB,SAAS,SAAS,CACnD,EACD,GAAG,gBAAgB,SAAS,WAC1B,iBAAiB,KAAK,eAAe,GAAG,WAAW,GAAG,SAAS,CAChE,CACF;GAED,MAAM,kCAAkB,IAAI,KAAa;AACzC,eAAY,KAAK,KAAK,SAAS,SAAS;AACtC,QACE,EAAE,oBAAoB,KAAK,IAC3B,OAAO,KAAK,OAAO,UAAU,YAC7B,QAAQ,SAAS,KAAK,OAAO,MAAM,CAEnC,iBAAgB,IAAI,KAAK,OAAO,MAAM;KAExC;GAEF,MAAM,eAAe,QAAQ,QAAQ,QAAQ,CAAC,gBAAgB,IAAI,IAAI,CAAC;AAEvE,OAAI,aAAa,SAAS,GAAG;IAC3B,MAAM,aAAa,aAAa,KAAK,eACnC,EAAE,kBAAkB,EAAE,EAAE,EAAE,cAAc,WAAW,CAAC,CACrD;AAED,gBAAY,KAAK,KAAK,QAAQ,GAAG,WAAW;;KAGjD;EACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugin-dir/types.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,mYAUZ,CAAC;AAEX,eAAO,MAAM,gBAAgB,kRAOnB,CAAC;AAEX,MAAM,WAAW,aAAa;IAE5B,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IAEnB,MAAM,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,MAAM,CAC5D,MAAM,EACN,OAAO,CACR,CAAC;IAEF,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B,gBAAgB,CAAC,EAAE,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC;CACjD"}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/plugin-dir/types.ts
|
|
2
|
+
const POLYFILLS = [
|
|
3
|
+
"@formatjs/intl-getcanonicallocales/polyfill",
|
|
4
|
+
"@formatjs/intl-locale/polyfill",
|
|
5
|
+
"@formatjs/intl-displaynames/polyfill",
|
|
6
|
+
"@formatjs/intl-listformat/polyfill",
|
|
7
|
+
"@formatjs/intl-pluralrules/polyfill-force",
|
|
8
|
+
"@formatjs/intl-numberformat/polyfill",
|
|
9
|
+
"@formatjs/intl-relativetimeformat/polyfill",
|
|
10
|
+
"@formatjs/intl-datetimeformat/polyfill",
|
|
11
|
+
"@formatjs/intl-datetimeformat/add-all-tz"
|
|
12
|
+
];
|
|
13
|
+
const LOCALE_POLYFILLS = [
|
|
14
|
+
`@formatjs/intl-displaynames/locale-data`,
|
|
15
|
+
`@formatjs/intl-listformat/locale-data`,
|
|
16
|
+
`@formatjs/intl-pluralrules/locale-data`,
|
|
17
|
+
`@formatjs/intl-numberformat/locale-data`,
|
|
18
|
+
`@formatjs/intl-relativetimeformat/locale-data`,
|
|
19
|
+
`@formatjs/intl-datetimeformat/locale-data`
|
|
20
|
+
];
|
|
21
|
+
//#endregion
|
|
22
|
+
export { LOCALE_POLYFILLS, POLYFILLS };
|
|
2
23
|
|
|
3
|
-
export const POLYFILLS = ['@formatjs/intl-getcanonicallocales/polyfill', '@formatjs/intl-locale/polyfill', '@formatjs/intl-displaynames/polyfill', '@formatjs/intl-listformat/polyfill', '@formatjs/intl-pluralrules/polyfill-force',
|
|
4
|
-
// https://github.com/formatjs/formatjs/issues/4463
|
|
5
|
-
'@formatjs/intl-numberformat/polyfill', '@formatjs/intl-relativetimeformat/polyfill', '@formatjs/intl-datetimeformat/polyfill', '@formatjs/intl-datetimeformat/add-all-tz'];
|
|
6
|
-
export const LOCALE_POLYFILLS = [`@formatjs/intl-displaynames/locale-data`, `@formatjs/intl-listformat/locale-data`, `@formatjs/intl-pluralrules/locale-data`, `@formatjs/intl-numberformat/locale-data`, `@formatjs/intl-relativetimeformat/locale-data`, `@formatjs/intl-datetimeformat/locale-data`];
|
|
7
24
|
//# sourceMappingURL=types.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/plugin-dir/types.ts"],"sourcesContent":["export const POLYFILLS = [\n '@formatjs/intl-getcanonicallocales/polyfill',\n '@formatjs/intl-locale/polyfill',\n '@formatjs/intl-displaynames/polyfill',\n '@formatjs/intl-listformat/polyfill',\n '@formatjs/intl-pluralrules/polyfill-force', // https://github.com/formatjs/formatjs/issues/4463\n '@formatjs/intl-numberformat/polyfill',\n '@formatjs/intl-relativetimeformat/polyfill',\n '@formatjs/intl-datetimeformat/polyfill',\n '@formatjs/intl-datetimeformat/add-all-tz',\n] as const;\n\nexport const LOCALE_POLYFILLS = [\n `@formatjs/intl-displaynames/locale-data`,\n `@formatjs/intl-listformat/locale-data`,\n `@formatjs/intl-pluralrules/locale-data`,\n `@formatjs/intl-numberformat/locale-data`,\n `@formatjs/intl-relativetimeformat/locale-data`,\n `@formatjs/intl-datetimeformat/locale-data`,\n] as const;\n\nexport interface PluginOptions {\n /* List of locales to polyfill */\n locales?: string[];\n /* Gt config object */\n config?: { defaultLocale: string; locales: string[] } & Record<\n string,\n unknown\n >;\n /* Path to the gt config file */\n configFilePath?: string;\n /* Resolved from package.json */\n entryPointFilePath?: string;\n /* Polyfills to exclude */\n excludePolyfills?: (typeof POLYFILLS)[number][];\n}\n"],"mappings":";AAAA,MAAa,YAAY;CACvB;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;AAED,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACD"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolveLocales.d.ts","sourceRoot":"","sources":["../../../../src/plugin-dir/utils/resolveLocales.ts"],"names":[],"mappings":"AAgBA;;;GAGG;AACH,wBAAgB,cAAc,CAAC,EAC7B,OAAO,EACP,MAAM,EACN,cAAc,GACf,EAAE;IACD,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,MAAM,CAAC,EAAE;QAAE,aAAa,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,GAAG,MAAM,CAC5D,MAAM,EACN,OAAO,CACR,CAAC;IACF,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,GAAG,MAAM,EAAE,CA0BX"}
|
|
@@ -1,70 +1,54 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import fs from 'fs';
|
|
4
1
|
import { couldNotLocateConfigWarning, invalidLocalesWarning, resolveLocalesFailedWarning } from "../../errors-dir/warnings.js";
|
|
5
|
-
import { libraryDefaultLocale } from 'generaltranslation/internal';
|
|
6
2
|
import { failedToReadConfigFileError } from "../../errors-dir/errors.js";
|
|
7
|
-
import {
|
|
8
|
-
import path from
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import { libraryDefaultLocale } from "generaltranslation/internal";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import fs from "fs";
|
|
6
|
+
import { getSupportedLocale } from "@generaltranslation/supported-locales";
|
|
7
|
+
//#region src/plugin-dir/utils/resolveLocales.ts
|
|
8
|
+
const DEFAULT_CONFIG_FILE_PATHS = [path.join(process.cwd(), "gt.config.json"), path.join(process.cwd(), ".locadex", "gt.config.json")];
|
|
11
9
|
/**
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// Validate the result
|
|
32
|
-
const invalidLocales = result.filter(locale => !getSupportedLocale(locale));
|
|
33
|
-
if (invalidLocales.length) {
|
|
34
|
-
console.warn(invalidLocalesWarning(invalidLocales));
|
|
35
|
-
result = result.filter(locale => !invalidLocales.includes(locale));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// Fallback to default locale if no locales were found
|
|
39
|
-
if (result.length === 0) {
|
|
40
|
-
console.warn(resolveLocalesFailedWarning);
|
|
41
|
-
result = [libraryDefaultLocale];
|
|
42
|
-
}
|
|
43
|
-
return result;
|
|
10
|
+
* Given a list of locales or a config object or a path to a config file, return a list of locales to polyfill.
|
|
11
|
+
* Preference order: locales > config > configFilePaths > library default locale
|
|
12
|
+
*/
|
|
13
|
+
function resolveLocales({ locales, config, configFilePath }) {
|
|
14
|
+
let result = [];
|
|
15
|
+
if (locales) result = Array.from(new Set(locales));
|
|
16
|
+
else if (config) result = Array.from(new Set([config.defaultLocale, ...config.locales]));
|
|
17
|
+
else result = resolveLocalesFromConfig(configFilePath);
|
|
18
|
+
const invalidLocales = result.filter((locale) => !getSupportedLocale(locale));
|
|
19
|
+
if (invalidLocales.length) {
|
|
20
|
+
console.warn(invalidLocalesWarning(invalidLocales));
|
|
21
|
+
result = result.filter((locale) => !invalidLocales.includes(locale));
|
|
22
|
+
}
|
|
23
|
+
if (result.length === 0) {
|
|
24
|
+
console.warn(resolveLocalesFailedWarning);
|
|
25
|
+
result = [libraryDefaultLocale];
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
44
28
|
}
|
|
45
|
-
|
|
46
29
|
/**
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
30
|
+
* Resolve locales from a config file
|
|
31
|
+
* @param configFilePath - The path to the config file
|
|
32
|
+
* @returns A list of locales
|
|
33
|
+
*/
|
|
51
34
|
function resolveLocalesFromConfig(configFilePath) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
return result;
|
|
35
|
+
const configFilePaths = [...configFilePath ? [configFilePath] : [], ...DEFAULT_CONFIG_FILE_PATHS];
|
|
36
|
+
let result = [];
|
|
37
|
+
for (const filePath of configFilePaths) try {
|
|
38
|
+
if (!fs.existsSync(filePath)) {
|
|
39
|
+
console.warn(couldNotLocateConfigWarning(filePath));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
const resolvedConfig = JSON.parse(fs.readFileSync(filePath, "utf8"));
|
|
43
|
+
result = Array.from(new Set([...resolvedConfig.defaultLocale ? [resolvedConfig.defaultLocale] : [], ...resolvedConfig.locales || []]));
|
|
44
|
+
break;
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(failedToReadConfigFileError(filePath), error);
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
69
50
|
}
|
|
51
|
+
//#endregion
|
|
52
|
+
export { resolveLocales };
|
|
53
|
+
|
|
70
54
|
//# sourceMappingURL=resolveLocales.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"resolveLocales.js","names":[],"sources":["../../../../src/plugin-dir/utils/resolveLocales.ts"],"sourcesContent":["import fs from 'fs';\nimport {\n couldNotLocateConfigWarning,\n invalidLocalesWarning,\n resolveLocalesFailedWarning,\n} from '../../errors-dir/warnings';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport { failedToReadConfigFileError } from '../../errors-dir/errors';\nimport { getSupportedLocale } from '@generaltranslation/supported-locales';\nimport path from 'path';\n\nconst DEFAULT_CONFIG_FILE_PATHS = [\n path.join(process.cwd(), 'gt.config.json'),\n path.join(process.cwd(), '.locadex', 'gt.config.json'),\n];\n\n/**\n * Given a list of locales or a config object or a path to a config file, return a list of locales to polyfill.\n * Preference order: locales > config > configFilePaths > library default locale\n */\nexport function resolveLocales({\n locales,\n config,\n configFilePath,\n}: {\n locales?: string[];\n config?: { defaultLocale: string; locales: string[] } & Record<\n string,\n unknown\n >;\n configFilePath?: string;\n}): string[] {\n let result: string[] = [];\n\n // Resolve locales from the given options\n if (locales) {\n result = Array.from(new Set(locales));\n } else if (config) {\n result = Array.from(new Set([config.defaultLocale, ...config.locales]));\n } else {\n result = resolveLocalesFromConfig(configFilePath);\n }\n\n // Validate the result\n const invalidLocales = result.filter((locale) => !getSupportedLocale(locale));\n if (invalidLocales.length) {\n console.warn(invalidLocalesWarning(invalidLocales));\n result = result.filter((locale) => !invalidLocales.includes(locale));\n }\n\n // Fallback to default locale if no locales were found\n if (result.length === 0) {\n console.warn(resolveLocalesFailedWarning);\n result = [libraryDefaultLocale];\n }\n\n return result;\n}\n\n/**\n * Resolve locales from a config file\n * @param configFilePath - The path to the config file\n * @returns A list of locales\n */\nfunction resolveLocalesFromConfig(configFilePath: string | undefined) {\n const configFilePaths = [\n ...(configFilePath ? [configFilePath] : []),\n ...DEFAULT_CONFIG_FILE_PATHS,\n ];\n let result: string[] = [];\n\n for (const filePath of configFilePaths) {\n try {\n if (!fs.existsSync(filePath)) {\n console.warn(couldNotLocateConfigWarning(filePath));\n continue;\n }\n\n const resolvedConfig = JSON.parse(fs.readFileSync(filePath, 'utf8')) as {\n defaultLocale?: string;\n locales?: string[];\n };\n\n result = Array.from(\n new Set([\n ...(resolvedConfig.defaultLocale\n ? [resolvedConfig.defaultLocale]\n : []),\n ...(resolvedConfig.locales || []),\n ])\n );\n break;\n } catch (error) {\n console.error(failedToReadConfigFileError(filePath), error);\n break;\n }\n }\n return result;\n}\n"],"mappings":";;;;;;;AAWA,MAAM,4BAA4B,CAChC,KAAK,KAAK,QAAQ,KAAK,EAAE,iBAAiB,EAC1C,KAAK,KAAK,QAAQ,KAAK,EAAE,YAAY,iBAAiB,CACvD;;;;;AAMD,SAAgB,eAAe,EAC7B,SACA,QACA,kBAQW;CACX,IAAI,SAAmB,EAAE;AAGzB,KAAI,QACF,UAAS,MAAM,KAAK,IAAI,IAAI,QAAQ,CAAC;UAC5B,OACT,UAAS,MAAM,KAAK,IAAI,IAAI,CAAC,OAAO,eAAe,GAAG,OAAO,QAAQ,CAAC,CAAC;KAEvE,UAAS,yBAAyB,eAAe;CAInD,MAAM,iBAAiB,OAAO,QAAQ,WAAW,CAAC,mBAAmB,OAAO,CAAC;AAC7E,KAAI,eAAe,QAAQ;AACzB,UAAQ,KAAK,sBAAsB,eAAe,CAAC;AACnD,WAAS,OAAO,QAAQ,WAAW,CAAC,eAAe,SAAS,OAAO,CAAC;;AAItE,KAAI,OAAO,WAAW,GAAG;AACvB,UAAQ,KAAK,4BAA4B;AACzC,WAAS,CAAC,qBAAqB;;AAGjC,QAAO;;;;;;;AAQT,SAAS,yBAAyB,gBAAoC;CACpE,MAAM,kBAAkB,CACtB,GAAI,iBAAiB,CAAC,eAAe,GAAG,EAAE,EAC1C,GAAG,0BACJ;CACD,IAAI,SAAmB,EAAE;AAEzB,MAAK,MAAM,YAAY,gBACrB,KAAI;AACF,MAAI,CAAC,GAAG,WAAW,SAAS,EAAE;AAC5B,WAAQ,KAAK,4BAA4B,SAAS,CAAC;AACnD;;EAGF,MAAM,iBAAiB,KAAK,MAAM,GAAG,aAAa,UAAU,OAAO,CAAC;AAKpE,WAAS,MAAM,KACb,IAAI,IAAI,CACN,GAAI,eAAe,gBACf,CAAC,eAAe,cAAc,GAC9B,EAAE,EACN,GAAI,eAAe,WAAW,EAAE,CACjC,CAAC,CACH;AACD;UACO,OAAO;AACd,UAAQ,MAAM,4BAA4B,SAAS,EAAE,MAAM;AAC3D;;AAGJ,QAAO"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../../src/plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC"}
|
package/dist/module/plugin.js
CHANGED
|
@@ -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"}
|
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
1
|
import { useDetermineLocale } from "./hooks/locale/useDetermineLocale.js";
|
|
4
|
-
import { GTProvider as _GTProvider } from '@generaltranslation/react-core';
|
|
5
2
|
import { readAuthFromEnv } from "../utils/utils.js";
|
|
6
3
|
import { useRegionState } from "./hooks/useRegionState.js";
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
4
|
+
import { GTProvider as GTProvider$1 } from "@generaltranslation/react-core";
|
|
5
|
+
import { jsx } from "react/jsx-runtime";
|
|
6
|
+
//#region src/provider/GTProvider.tsx
|
|
7
|
+
function GTProvider(props) {
|
|
8
|
+
return /* @__PURE__ */ jsx(GTProvider$1, {
|
|
9
|
+
ssr: false,
|
|
10
|
+
environment: __DEV__ ? "development" : "production",
|
|
11
|
+
...props,
|
|
12
|
+
readAuthFromEnv,
|
|
13
|
+
useDetermineLocale,
|
|
14
|
+
useRegionState
|
|
15
|
+
});
|
|
17
16
|
}
|
|
18
|
-
|
|
17
|
+
//#endregion
|
|
18
|
+
export { GTProvider, GTProvider as default };
|
|
19
|
+
|
|
19
20
|
//# sourceMappingURL=GTProvider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useDetermineLocale.d.ts","sourceRoot":"","sources":["../../../../../src/provider/hooks/locale/useDetermineLocale.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACV,wBAAwB,EACxB,wBAAwB,EACzB,MAAM,sCAAsC,CAAC;AAM9C,wBAAgB,kBAAkB,CAAC,EACjC,MAAM,EAAE,OAAY,EACpB,aAAoC,EACpC,OAAY,EACZ,gBAA8C,EAC9C,GAAW,EAAE,eAAe;AAC5B,aAAa,EACb,UAAU,GACX,EAAE,wBAAwB,GAAG,wBAAwB,CAiErD"}
|