gt-react-native 0.0.2 → 0.0.3
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/lib/commonjs/NativeGtReactNative.js +9 -0
- package/lib/commonjs/NativeGtReactNative.js.map +1 -0
- package/lib/commonjs/errors-dir/constants.js +8 -0
- package/lib/commonjs/errors-dir/constants.js.map +1 -0
- package/lib/commonjs/errors-dir/errors.js +10 -0
- package/lib/commonjs/errors-dir/errors.js.map +1 -0
- package/lib/commonjs/errors-dir/warnings.js +18 -0
- package/lib/commonjs/errors-dir/warnings.js.map +1 -0
- package/lib/commonjs/index.js +158 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/internal.js +13 -0
- package/lib/commonjs/internal.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/plugin-dir/index.js +54 -0
- package/lib/commonjs/plugin-dir/index.js.map +1 -0
- package/lib/commonjs/plugin-dir/types.js +2 -0
- package/lib/commonjs/plugin-dir/types.js.map +1 -0
- package/lib/commonjs/plugin-dir/utils/resolveLocales.js +74 -0
- package/lib/commonjs/plugin-dir/utils/resolveLocales.js.map +1 -0
- package/lib/commonjs/plugin.js +14 -0
- package/lib/commonjs/plugin.js.map +1 -0
- package/lib/commonjs/provider/GTProvider.js +24 -0
- package/lib/commonjs/provider/GTProvider.js.map +1 -0
- package/lib/commonjs/provider/hooks/locale/useDetermineLocale.js +146 -0
- package/lib/commonjs/provider/hooks/locale/useDetermineLocale.js.map +1 -0
- package/lib/commonjs/provider/hooks/useRegionState.js +47 -0
- package/lib/commonjs/provider/hooks/useRegionState.js.map +1 -0
- package/lib/commonjs/tools/testLocalePolyfill.js +68 -0
- package/lib/commonjs/tools/testLocalePolyfill.js.map +1 -0
- package/lib/commonjs/types/config.js +6 -0
- package/lib/commonjs/types/config.js.map +1 -0
- package/lib/commonjs/utils/getNativeLocales.js +58 -0
- package/lib/commonjs/utils/getNativeLocales.js.map +1 -0
- package/lib/commonjs/utils/nativeStore.js +39 -0
- package/lib/commonjs/utils/nativeStore.js.map +1 -0
- package/lib/commonjs/utils/utils.js +17 -0
- package/lib/commonjs/utils/utils.js.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/src/NativeGtReactNative.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/errors-dir/constants.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/errors-dir/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/errors-dir/warnings.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/internal.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/plugin-dir/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/plugin-dir/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/plugin-dir/utils/resolveLocales.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/plugin.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/provider/GTProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/provider/hooks/useRegionState.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/tools/testLocalePolyfill.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/types/config.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/getNativeLocales.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/nativeStore.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -0
- package/lib/typescript/commonjs/vitest.config.d.ts.map +1 -0
- package/lib/typescript/module/src/NativeGtReactNative.d.ts +10 -0
- package/lib/typescript/module/src/NativeGtReactNative.d.ts.map +1 -0
- package/lib/typescript/module/src/errors-dir/constants.d.ts +2 -0
- package/lib/typescript/module/src/errors-dir/constants.d.ts.map +1 -0
- package/lib/typescript/module/src/errors-dir/errors.d.ts +2 -0
- package/lib/typescript/module/src/errors-dir/errors.d.ts.map +1 -0
- package/lib/typescript/module/src/errors-dir/warnings.d.ts +4 -0
- package/lib/typescript/module/src/errors-dir/warnings.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +6 -0
- package/lib/typescript/module/src/index.d.ts.map +1 -0
- package/lib/typescript/module/src/internal.d.ts +2 -0
- package/lib/typescript/module/src/internal.d.ts.map +1 -0
- package/lib/typescript/module/src/plugin-dir/index.d.ts +6 -0
- package/lib/typescript/module/src/plugin-dir/index.d.ts.map +1 -0
- package/lib/typescript/module/src/plugin-dir/types.d.ts +10 -0
- package/lib/typescript/module/src/plugin-dir/types.d.ts.map +1 -0
- package/lib/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts +13 -0
- package/lib/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts.map +1 -0
- package/lib/typescript/module/src/plugin.d.ts +2 -0
- package/lib/typescript/module/src/plugin.d.ts.map +1 -0
- package/lib/typescript/module/src/provider/GTProvider.d.ts +4 -0
- package/lib/typescript/module/src/provider/GTProvider.d.ts.map +1 -0
- package/lib/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts +4 -0
- package/lib/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
- package/lib/typescript/module/src/provider/hooks/useRegionState.d.ts +3 -0
- package/lib/typescript/module/src/provider/hooks/useRegionState.d.ts.map +1 -0
- package/lib/typescript/module/src/tools/testLocalePolyfill.d.ts +12 -0
- package/lib/typescript/module/src/tools/testLocalePolyfill.d.ts.map +1 -0
- package/lib/typescript/module/src/types/config.d.ts +30 -0
- package/lib/typescript/module/src/types/config.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/getNativeLocales.d.ts +10 -0
- package/lib/typescript/module/src/utils/getNativeLocales.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/nativeStore.d.ts +16 -0
- package/lib/typescript/module/src/utils/nativeStore.d.ts.map +1 -0
- package/lib/typescript/module/src/utils/utils.d.ts +3 -0
- package/lib/typescript/module/src/utils/utils.d.ts.map +1 -0
- package/lib/typescript/module/vitest.config.d.ts +3 -0
- package/lib/typescript/module/vitest.config.d.ts.map +1 -0
- package/package.json +11 -6
- package/lib/typescript/src/NativeGtReactNative.d.ts.map +0 -1
- package/lib/typescript/src/errors-dir/constants.d.ts.map +0 -1
- package/lib/typescript/src/errors-dir/errors.d.ts.map +0 -1
- package/lib/typescript/src/errors-dir/warnings.d.ts.map +0 -1
- package/lib/typescript/src/index.d.ts.map +0 -1
- package/lib/typescript/src/internal.d.ts.map +0 -1
- package/lib/typescript/src/plugin-dir/index.d.ts.map +0 -1
- package/lib/typescript/src/plugin-dir/types.d.ts.map +0 -1
- package/lib/typescript/src/plugin-dir/utils/resolveLocales.d.ts.map +0 -1
- package/lib/typescript/src/plugin.d.ts.map +0 -1
- package/lib/typescript/src/provider/GTProvider.d.ts.map +0 -1
- package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
- package/lib/typescript/src/provider/hooks/useRegionState.d.ts.map +0 -1
- package/lib/typescript/src/tools/testLocalePolyfill.d.ts.map +0 -1
- package/lib/typescript/src/types/config.d.ts.map +0 -1
- package/lib/typescript/src/utils/getNativeLocales.d.ts.map +0 -1
- package/lib/typescript/src/utils/nativeStore.d.ts.map +0 -1
- package/lib/typescript/src/utils/utils.d.ts.map +0 -1
- package/lib/typescript/vitest.config.d.ts.map +0 -1
- /package/lib/typescript/{src → commonjs/src}/NativeGtReactNative.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/errors-dir/constants.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/errors-dir/errors.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/errors-dir/warnings.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/index.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/internal.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/plugin-dir/index.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/plugin-dir/types.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/plugin-dir/utils/resolveLocales.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/plugin.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/provider/GTProvider.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/provider/hooks/locale/useDetermineLocale.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/provider/hooks/useRegionState.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/tools/testLocalePolyfill.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/types/config.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/getNativeLocales.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/nativeStore.d.ts +0 -0
- /package/lib/typescript/{src → commonjs/src}/utils/utils.d.ts +0 -0
- /package/lib/typescript/{vitest.config.d.ts → commonjs/vitest.config.d.ts} +0 -0
- /package/lib/typescript/{package.json → module/package.json} +0 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _reactNative = require("react-native");
|
|
8
|
+
var _default = exports.default = _reactNative.TurboModuleRegistry.getEnforcing('GtReactNative');
|
|
9
|
+
//# sourceMappingURL=NativeGtReactNative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_reactNative","require","_default","exports","default","TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeGtReactNative.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAAmD,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAQpCC,gCAAmB,CAACC,YAAY,CAAO,eAAe,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PACKAGE_NAME","exports"],"sourceRoot":"../../../src","sources":["errors-dir/constants.ts"],"mappings":";;;;;;AAAO,MAAMA,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,iBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.failedToReadConfigFileError = void 0;
|
|
7
|
+
var _constants = require("./constants");
|
|
8
|
+
const failedToReadConfigFileError = filePath => `${_constants.PACKAGE_NAME} Error: Failed to read GT Config at ${filePath}.`;
|
|
9
|
+
exports.failedToReadConfigFileError = failedToReadConfigFileError;
|
|
10
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_constants","require","failedToReadConfigFileError","filePath","PACKAGE_NAME","exports"],"sourceRoot":"../../../src","sources":["errors-dir/errors.ts"],"mappings":";;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA;AACO,MAAMC,2BAA2B,GAAIC,QAAgB,IAC1D,GAAGC,uBAAY,uCAAuCD,QAAQ,GAAG;AAACE,OAAA,CAAAH,2BAAA,GAAAA,2BAAA","ignoreList":[]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveLocalesFailedWarning = exports.invalidLocalesWarning = exports.couldNotLocateConfigWarning = void 0;
|
|
7
|
+
var _internal = require("generaltranslation/internal");
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
const resolveLocalesFailedWarning = exports.resolveLocalesFailedWarning = `${_constants.PACKAGE_NAME}: Failed to resolve locales for polyfill. Falling back to ${_internal.libraryDefaultLocale}.
|
|
10
|
+
Specify a list of locales for the gt-react-native babel plugin by:
|
|
11
|
+
(1) Providing a list of locales
|
|
12
|
+
(2) Providing your GT Config to the plugin
|
|
13
|
+
(3) Providing the path to your GT Config file.`;
|
|
14
|
+
const couldNotLocateConfigWarning = filePath => `${_constants.PACKAGE_NAME}: Could not locate GT Config at ${filePath}.`;
|
|
15
|
+
exports.couldNotLocateConfigWarning = couldNotLocateConfigWarning;
|
|
16
|
+
const invalidLocalesWarning = invalidLocales => `${_constants.PACKAGE_NAME}: Invalid locales found in GT Config: ${invalidLocales.join(', ')}.`;
|
|
17
|
+
exports.invalidLocalesWarning = invalidLocalesWarning;
|
|
18
|
+
//# sourceMappingURL=warnings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_internal","require","_constants","resolveLocalesFailedWarning","exports","PACKAGE_NAME","libraryDefaultLocale","couldNotLocateConfigWarning","filePath","invalidLocalesWarning","invalidLocales","join"],"sourceRoot":"../../../src","sources":["errors-dir/warnings.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,UAAA,GAAAD,OAAA;AAEO,MAAME,2BAA2B,GAAAC,OAAA,CAAAD,2BAAA,GAAG,GAAGE,uBAAY,6DAA6DC,8BAAoB;AAC3I;AACA;AACA;AACA,+CAA+C;AAExC,MAAMC,2BAA2B,GAAIC,QAAgB,IAC1D,GAAGH,uBAAY,mCAAmCG,QAAQ,GAAG;AAACJ,OAAA,CAAAG,2BAAA,GAAAA,2BAAA;AAEzD,MAAME,qBAAqB,GAAIC,cAAwB,IAC5D,GAAGL,uBAAY,yCAAyCK,cAAc,CAACC,IAAI,CAAC,IAAI,CAAC,GAAG;AAACP,OAAA,CAAAK,qBAAA,GAAAA,qBAAA","ignoreList":[]}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Branch", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _reactCore.Branch;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "Currency", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _reactCore.Currency;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "DateTime", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _reactCore.DateTime;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "GTProvider", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _GTProvider.GTProvider;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "Num", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _reactCore.Num;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "Plural", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _reactCore.Plural;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "T", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _reactCore.T;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "Var", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _reactCore.Var;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "decodeMsg", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _reactCore.decodeMsg;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "decodeOptions", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _reactCore.decodeOptions;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "msg", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _reactCore.msg;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
exports.multiply = multiply;
|
|
73
|
+
Object.defineProperty(exports, "useDefaultLocale", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return _reactCore.useDefaultLocale;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "useGT", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () {
|
|
82
|
+
return _reactCore.useGT;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "useGTClass", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return _reactCore.useGTClass;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "useLocale", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return _reactCore.useLocale;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "useLocaleDirection", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return _reactCore.useLocaleDirection;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "useLocaleProperties", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return _reactCore.useLocaleProperties;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "useLocaleSelector", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _reactCore.useLocaleSelector;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, "useLocales", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return _reactCore.useLocales;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, "useMessages", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return _reactCore.useMessages;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, "useRegion", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return _reactCore.useRegion;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, "useRegionSelector", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () {
|
|
136
|
+
return _reactCore.useRegionSelector;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, "useSetLocale", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function () {
|
|
142
|
+
return _reactCore.useSetLocale;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
Object.defineProperty(exports, "useTranslations", {
|
|
146
|
+
enumerable: true,
|
|
147
|
+
get: function () {
|
|
148
|
+
return _reactCore.useTranslations;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
var _NativeGtReactNative = _interopRequireDefault(require("./NativeGtReactNative"));
|
|
152
|
+
var _GTProvider = require("./provider/GTProvider");
|
|
153
|
+
var _reactCore = require("@generaltranslation/react-core");
|
|
154
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
155
|
+
function multiply(a, b) {
|
|
156
|
+
return _NativeGtReactNative.default.multiply(a, b);
|
|
157
|
+
}
|
|
158
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_NativeGtReactNative","_interopRequireDefault","require","_GTProvider","_reactCore","e","__esModule","default","multiply","a","b","GtReactNative"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,oBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,WAAA,GAAAD,OAAA;AAKA,IAAAE,UAAA,GAAAF,OAAA;AAwBwC,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AA5BjC,SAASG,QAAQA,CAACC,CAAS,EAAEC,CAAS,EAAU;EACrD,OAAOC,4BAAa,CAACH,QAAQ,CAACC,CAAC,EAAEC,CAAC,CAAC;AACrC","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "testLocalePolyfill", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _testLocalePolyfill.testLocalePolyfill;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _testLocalePolyfill = require("./tools/testLocalePolyfill");
|
|
13
|
+
//# sourceMappingURL=internal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_testLocalePolyfill","require"],"sourceRoot":"../../src","sources":["internal.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = _default;
|
|
7
|
+
var path = _interopRequireWildcard(require("path"));
|
|
8
|
+
var _resolveLocales = require("./utils/resolveLocales");
|
|
9
|
+
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
|
|
10
|
+
function _default(babel, {
|
|
11
|
+
locales,
|
|
12
|
+
config,
|
|
13
|
+
configFilePath,
|
|
14
|
+
entryPointFilePath = path.resolve(process.cwd(), 'src', 'App.tsx')
|
|
15
|
+
}) {
|
|
16
|
+
const {
|
|
17
|
+
types: t
|
|
18
|
+
} = babel;
|
|
19
|
+
return {
|
|
20
|
+
name: 'gt-react-native/plugin',
|
|
21
|
+
visitor: {
|
|
22
|
+
Program(programPath, state) {
|
|
23
|
+
const currentFilePath = path.resolve(state.filename || state.file.opts.filename || '');
|
|
24
|
+
|
|
25
|
+
// Only apply polyfills to files that import gt-react-native or generaltranslation
|
|
26
|
+
if (currentFilePath !== entryPointFilePath) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const resolvedLocales = (0, _resolveLocales.resolveLocales)({
|
|
30
|
+
locales,
|
|
31
|
+
config,
|
|
32
|
+
configFilePath
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// TODO: smart imports based on if the polyfill is required, do this as a wrapper around AppRegistry.registerComponent()
|
|
36
|
+
const imports = ['@formatjs/intl-getcanonicallocales/polyfill', '@formatjs/intl-locale/polyfill', '@formatjs/intl-displaynames/polyfill', '@formatjs/intl-listformat/polyfill', '@formatjs/intl-pluralrules/polyfill-force',
|
|
37
|
+
// https://github.com/formatjs/formatjs/issues/4463
|
|
38
|
+
'@formatjs/intl-numberformat/polyfill', '@formatjs/intl-relativetimeformat/polyfill', '@formatjs/intl-datetimeformat/polyfill', '@formatjs/intl-datetimeformat/add-all-tz', ...resolvedLocales.flatMap(locale => [`@formatjs/intl-displaynames/locale-data/${locale}`, `@formatjs/intl-listformat/locale-data/${locale}`, `@formatjs/intl-pluralrules/locale-data/${locale}`, `@formatjs/intl-numberformat/locale-data/${locale}`, `@formatjs/intl-relativetimeformat/locale-data/${locale}`, `@formatjs/intl-datetimeformat/locale-data/${locale}`])];
|
|
39
|
+
const existingImports = new Set();
|
|
40
|
+
programPath.node.body.forEach(node => {
|
|
41
|
+
if (t.isImportDeclaration(node) && typeof node.source.value === 'string' && imports.includes(node.source.value)) {
|
|
42
|
+
existingImports.add(node.source.value);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const importsToAdd = imports.filter(imp => !existingImports.has(imp));
|
|
46
|
+
if (importsToAdd.length > 0) {
|
|
47
|
+
const newImports = importsToAdd.map(importPath => t.importDeclaration([], t.stringLiteral(importPath)));
|
|
48
|
+
programPath.node.body.unshift(...newImports);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["path","_interopRequireWildcard","require","_resolveLocales","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","_default","babel","locales","config","configFilePath","entryPointFilePath","resolve","process","cwd","types","name","visitor","Program","programPath","state","currentFilePath","filename","file","opts","resolvedLocales","resolveLocales","imports","flatMap","locale","existingImports","Set","node","body","forEach","isImportDeclaration","source","value","includes","add","importsToAdd","filter","imp","length","newImports","map","importPath","importDeclaration","stringLiteral","unshift"],"sourceRoot":"../../../src","sources":["plugin-dir/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ACC,KAAK,CAAC;UACxC;QACF,CAAC,CAAC;QAEF,MAAMG,YAAY,GAAGb,OAAO,CAACc,MAAM,CAAEC,GAAG,IAAK,CAACZ,eAAe,CAAChC,GAAG,CAAC4C,GAAG,CAAC,CAAC;QAEvE,IAAIF,YAAY,CAACG,MAAM,GAAG,CAAC,EAAE;UAC3B,MAAMC,UAAU,GAAGJ,YAAY,CAACK,GAAG,CAAEC,UAAU,IAC7C1D,CAAC,CAAC2D,iBAAiB,CAAC,EAAE,EAAE3D,CAAC,CAAC4D,aAAa,CAACF,UAAU,CAAC,CACrD,CAAC;UAED3B,WAAW,CAACa,IAAI,CAACC,IAAI,CAACgB,OAAO,CAAC,GAAGL,UAAU,CAAC;QAC9C;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["plugin-dir/types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.resolveLocales = resolveLocales;
|
|
7
|
+
var _fs = _interopRequireDefault(require("fs"));
|
|
8
|
+
var _warnings = require("../../errors-dir/warnings");
|
|
9
|
+
var _internal = require("generaltranslation/internal");
|
|
10
|
+
var _errors = require("../../errors-dir/errors");
|
|
11
|
+
var _supportedLocales = require("@generaltranslation/supported-locales");
|
|
12
|
+
var _path = _interopRequireDefault(require("path"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
const DEFAULT_CONFIG_FILE_PATHS = [_path.default.join(process.cwd(), 'gt.config.json'), _path.default.join(process.cwd(), '.locadex', 'gt.config.json')];
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Given a list of locales or a config object or a path to a config file, return a list of locales to polyfill.
|
|
18
|
+
* Preference order: locales > config > configFilePaths > library default locale
|
|
19
|
+
*/
|
|
20
|
+
function resolveLocales({
|
|
21
|
+
locales,
|
|
22
|
+
config,
|
|
23
|
+
configFilePath
|
|
24
|
+
}) {
|
|
25
|
+
let result = [];
|
|
26
|
+
|
|
27
|
+
// Resolve locales from the given options
|
|
28
|
+
if (locales) {
|
|
29
|
+
result = Array.from(new Set(locales));
|
|
30
|
+
} else if (config) {
|
|
31
|
+
result = Array.from(new Set([config.defaultLocale, ...config.locales]));
|
|
32
|
+
} else {
|
|
33
|
+
result = resolveLocalesFromConfig(configFilePath);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Validate the result
|
|
37
|
+
const invalidLocales = result.filter(locale => !(0, _supportedLocales.getSupportedLocale)(locale));
|
|
38
|
+
if (invalidLocales.length) {
|
|
39
|
+
console.warn((0, _warnings.invalidLocalesWarning)(invalidLocales));
|
|
40
|
+
result = result.filter(locale => !invalidLocales.includes(locale));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Fallback to default locale if no locales were found
|
|
44
|
+
if (result.length === 0) {
|
|
45
|
+
console.warn(_warnings.resolveLocalesFailedWarning);
|
|
46
|
+
result = [_internal.libraryDefaultLocale];
|
|
47
|
+
}
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Resolve locales from a config file
|
|
53
|
+
* @param configFilePath - The path to the config file
|
|
54
|
+
* @returns A list of locales
|
|
55
|
+
*/
|
|
56
|
+
function resolveLocalesFromConfig(configFilePath) {
|
|
57
|
+
const configFilePaths = [...(configFilePath ? [configFilePath] : []), ...DEFAULT_CONFIG_FILE_PATHS];
|
|
58
|
+
let result = [];
|
|
59
|
+
for (const filePath of configFilePaths) {
|
|
60
|
+
try {
|
|
61
|
+
if (!_fs.default.existsSync(filePath)) {
|
|
62
|
+
console.warn((0, _warnings.couldNotLocateConfigWarning)(filePath));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const resolvedConfig = JSON.parse(_fs.default.readFileSync(filePath, 'utf8'));
|
|
66
|
+
result = Array.from(new Set([...(resolvedConfig.defaultLocale ? [resolvedConfig.defaultLocale] : []), ...(resolvedConfig.locales || [])]));
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.error((0, _errors.failedToReadConfigFileError)(filePath), error);
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=resolveLocales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_fs","_interopRequireDefault","require","_warnings","_internal","_errors","_supportedLocales","_path","e","__esModule","default","DEFAULT_CONFIG_FILE_PATHS","path","join","process","cwd","resolveLocales","locales","config","configFilePath","result","Array","from","Set","defaultLocale","resolveLocalesFromConfig","invalidLocales","filter","locale","getSupportedLocale","length","console","warn","invalidLocalesWarning","includes","resolveLocalesFailedWarning","libraryDefaultLocale","configFilePaths","filePath","fs","existsSync","couldNotLocateConfigWarning","resolvedConfig","JSON","parse","readFileSync","error","failedToReadConfigFileError"],"sourceRoot":"../../../../src","sources":["plugin-dir/utils/resolveLocales.ts"],"mappings":";;;;;;AAAA,IAAAA,GAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,iBAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAN,sBAAA,CAAAC,OAAA;AAAwB,SAAAD,uBAAAO,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAExB,MAAMG,yBAAyB,GAAG,CAChCC,aAAI,CAACC,IAAI,CAACC,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,gBAAgB,CAAC,EAC1CH,aAAI,CAACC,IAAI,CAACC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GR,yBAAyB,CAC7B;EACD,IAAIS,MAAgB,GAAG,EAAE;EAEzB,KAAK,MAAMkB,QAAQ,IAAID,eAAe,EAAE;IACtC,IAAI;MACF,IAAI,CAACE,WAAE,CAACC,UAAU,CAACF,QAAQ,CAAC,EAAE;QAC5BP,OAAO,CAACC,IAAI,CAAC,IAAAS,qCAA2B,EAACH,QAAQ,CAAC,CAAC;QACnD;MACF;MAEA,MAAMI,cAAc,GAAGC,IAAI,CAACC,KAAK,CAACL,WAAE,CAACM,YAAY,CAACP,QAAQ,EAAE,MAAM,CAAC,CAGlE;MAEDlB,MAAM,GAAGC,KAAK,CAACC,IAAI,CACjB,IAAIC,GAAG,CAAC,CACN,IAAImB,cAAc,CAAClB,aAAa,GAC5B,CAACkB,cAAc,CAAClB,aAAa,CAAC,GAC9B,EAAE,CAAC,EACP,IAAIkB,cAAc,CAACzB,OAAO,IAAI,EAAE,CAAC,CAClC,CACH,CAAC;IACH,CAAC,CAAC,OAAO6B,KAAK,EAAE;MACdf,OAAO,CAACe,KAAK,CAAC,IAAAC,mCAA2B,EAACT,QAAQ,CAAC,EAAEQ,KAAK,CAAC;MAC3D;IACF;EACF;EACA,OAAO1B,MAAM;AACf","ignoreList":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "default", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _pluginDir.default;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _pluginDir = _interopRequireDefault(require("./plugin-dir"));
|
|
13
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
|
+
//# sourceMappingURL=plugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_pluginDir","_interopRequireDefault","require","e","__esModule","default"],"sourceRoot":"../../src","sources":["plugin.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAAuC,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA","ignoreList":[]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GTProvider = GTProvider;
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _useDetermineLocale = require("./hooks/locale/useDetermineLocale");
|
|
9
|
+
var _reactCore = require("@generaltranslation/react-core");
|
|
10
|
+
var _utils = require("../utils/utils");
|
|
11
|
+
var _useRegionState = require("./hooks/useRegionState");
|
|
12
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
13
|
+
function GTProvider(props) {
|
|
14
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactCore.GTProvider, {
|
|
15
|
+
ssr: false,
|
|
16
|
+
environment: __DEV__ ? 'development' : 'production',
|
|
17
|
+
...props,
|
|
18
|
+
readAuthFromEnv: _utils.readAuthFromEnv,
|
|
19
|
+
useDetermineLocale: _useDetermineLocale.useDetermineLocale,
|
|
20
|
+
useRegionState: _useRegionState.useRegionState
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
var _default = exports.default = GTProvider;
|
|
24
|
+
//# sourceMappingURL=GTProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_useDetermineLocale","require","_reactCore","_utils","_useRegionState","_jsxRuntime","GTProvider","props","jsx","ssr","environment","__DEV__","readAuthFromEnv","useDetermineLocale","useRegionState","_default","exports","default"],"sourceRoot":"../../../src","sources":["provider/GTProvider.tsx"],"mappings":";;;;;;;AAAA,IAAAA,mBAAA,GAAAC,OAAA;AAEA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,eAAA,GAAAH,OAAA;AAAwD,IAAAI,WAAA,GAAAJ,OAAA;AAEjD,SAASK,UAAUA,CAACC,KAAsB,EAAqB;EACpE,oBACE,IAAAF,WAAA,CAAAG,GAAA,EAACN,UAAA,CAAAI,UAAW;IACVG,GAAG,EAAE,KAAM;IACXC,WAAW,EAAEC,OAAO,GAAG,aAAa,GAAG,YAAa;IAAA,GAChDJ,KAAK;IACTK,eAAe,EAAEA,sBAAgB;IACjCC,kBAAkB,EAAEA,sCAAmB;IACvCC,cAAc,EAAEA;EAAe,CAChC,CAAC;AAEN;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcX,UAAU","ignoreList":[]}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useDetermineLocale = useDetermineLocale;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _generaltranslation = require("generaltranslation");
|
|
9
|
+
var _internal = require("generaltranslation/internal");
|
|
10
|
+
var _getNativeLocales = require("../../../utils/getNativeLocales");
|
|
11
|
+
var _nativeStore = require("../../../utils/nativeStore");
|
|
12
|
+
function useDetermineLocale({
|
|
13
|
+
locale: _locale = '',
|
|
14
|
+
defaultLocale = _internal.libraryDefaultLocale,
|
|
15
|
+
locales = [],
|
|
16
|
+
localeCookieName = 'generaltranslation.locale',
|
|
17
|
+
ssr = false,
|
|
18
|
+
// not relevant
|
|
19
|
+
customMapping
|
|
20
|
+
}) {
|
|
21
|
+
// resolve alias locale
|
|
22
|
+
_locale = (0, _generaltranslation.resolveAliasLocale)(_locale, customMapping);
|
|
23
|
+
locales = locales.map(locale => (0, _generaltranslation.resolveAliasLocale)(locale, customMapping));
|
|
24
|
+
const initializeLocale = () => {
|
|
25
|
+
const result = (0, _generaltranslation.resolveAliasLocale)(ssr ? _locale ? (0, _generaltranslation.determineLocale)(_locale, locales, customMapping) || '' : '' : getNewLocale({
|
|
26
|
+
_locale,
|
|
27
|
+
locale: _locale,
|
|
28
|
+
locales,
|
|
29
|
+
defaultLocale,
|
|
30
|
+
localeCookieName,
|
|
31
|
+
customMapping
|
|
32
|
+
}), customMapping);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// maintaining the state of locale
|
|
37
|
+
const [locale, _setLocale] = (0, _react.useState)(initializeLocale());
|
|
38
|
+
|
|
39
|
+
// Functions for setting internal locale state
|
|
40
|
+
const [setLocale, setLocaleWithoutPersist] = createSetLocale({
|
|
41
|
+
locale,
|
|
42
|
+
locales,
|
|
43
|
+
defaultLocale,
|
|
44
|
+
localeCookieName,
|
|
45
|
+
_setLocale,
|
|
46
|
+
customMapping
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// check browser for locales
|
|
50
|
+
(0, _react.useEffect)(() => {
|
|
51
|
+
const newLocale = getNewLocale({
|
|
52
|
+
_locale,
|
|
53
|
+
locale,
|
|
54
|
+
locales,
|
|
55
|
+
defaultLocale,
|
|
56
|
+
localeCookieName,
|
|
57
|
+
customMapping
|
|
58
|
+
});
|
|
59
|
+
setLocaleWithoutPersist(newLocale);
|
|
60
|
+
}, [_locale, locale, locales, defaultLocale, localeCookieName, customMapping, setLocaleWithoutPersist]);
|
|
61
|
+
return [locale, setLocale];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// ----- HELPER FUNCTIONS ---- //
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Choose a locale to use
|
|
68
|
+
* (1) use provided locale
|
|
69
|
+
* (2) use cookie locale
|
|
70
|
+
* (3) use preferred locale
|
|
71
|
+
* (5) fallback to defaultLocale
|
|
72
|
+
* Update the cookie locale to be correct
|
|
73
|
+
*/
|
|
74
|
+
function getNewLocale({
|
|
75
|
+
_locale,
|
|
76
|
+
locale,
|
|
77
|
+
locales,
|
|
78
|
+
defaultLocale,
|
|
79
|
+
localeCookieName,
|
|
80
|
+
customMapping
|
|
81
|
+
}) {
|
|
82
|
+
// No change, return
|
|
83
|
+
if (_locale && _locale === locale && (0, _generaltranslation.determineLocale)(_locale, locales, customMapping) === locale) {
|
|
84
|
+
return (0, _generaltranslation.resolveAliasLocale)(_locale, customMapping);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Check for locale in native store
|
|
88
|
+
let storedLocale = (0, _nativeStore.nativeStoreGet)(localeCookieName);
|
|
89
|
+
if (storedLocale) {
|
|
90
|
+
storedLocale = (0, _generaltranslation.resolveAliasLocale)(storedLocale, customMapping);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// check user's configured locales
|
|
94
|
+
let preferredLocales = (0, _getNativeLocales.getNativeLocales)();
|
|
95
|
+
if (preferredLocales.length === 0) preferredLocales = [defaultLocale];
|
|
96
|
+
preferredLocales = preferredLocales.map(l => (0, _generaltranslation.resolveAliasLocale)(l, customMapping));
|
|
97
|
+
|
|
98
|
+
// determine locale
|
|
99
|
+
let newLocale = (0, _generaltranslation.determineLocale)([...(_locale ? [_locale] : []),
|
|
100
|
+
// prefer user passed locale
|
|
101
|
+
...(storedLocale ? [storedLocale] : []),
|
|
102
|
+
// then prefer stored locale
|
|
103
|
+
...preferredLocales // then prefer browser locale
|
|
104
|
+
], locales, customMapping) || defaultLocale;
|
|
105
|
+
if (newLocale) {
|
|
106
|
+
newLocale = (0, _generaltranslation.resolveAliasLocale)(newLocale, customMapping);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// if stored locale not valid, change it back to whatever we use for fallback
|
|
110
|
+
if (storedLocale && storedLocale !== newLocale) {
|
|
111
|
+
(0, _nativeStore.nativeStoreSet)(localeCookieName, newLocale);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// return new locale
|
|
115
|
+
return newLocale;
|
|
116
|
+
}
|
|
117
|
+
function createSetLocale({
|
|
118
|
+
locale,
|
|
119
|
+
locales,
|
|
120
|
+
defaultLocale,
|
|
121
|
+
_setLocale,
|
|
122
|
+
localeCookieName,
|
|
123
|
+
customMapping
|
|
124
|
+
}) {
|
|
125
|
+
locale = (0, _generaltranslation.resolveAliasLocale)(locale, customMapping);
|
|
126
|
+
// Just update the internal state, don't persist it
|
|
127
|
+
const setLocaleWithoutPersist = newLocale => {
|
|
128
|
+
// validate locale
|
|
129
|
+
const validatedLocale = (0, _generaltranslation.resolveAliasLocale)((0, _generaltranslation.determineLocale)(newLocale, locales, customMapping) || locale || defaultLocale, customMapping);
|
|
130
|
+
if (validatedLocale !== newLocale) {
|
|
131
|
+
console.warn(`[gt-react-native] Unsupported locale: ${validatedLocale} -> ${newLocale}`);
|
|
132
|
+
}
|
|
133
|
+
// persist locale
|
|
134
|
+
_setLocale(validatedLocale);
|
|
135
|
+
return validatedLocale;
|
|
136
|
+
};
|
|
137
|
+
// update locale and persist it in native store
|
|
138
|
+
const setLocale = newLocale => {
|
|
139
|
+
newLocale = (0, _generaltranslation.resolveAliasLocale)(newLocale, customMapping);
|
|
140
|
+
setLocaleWithoutPersist(newLocale);
|
|
141
|
+
const validatedLocale = setLocaleWithoutPersist(newLocale);
|
|
142
|
+
(0, _nativeStore.nativeStoreSet)(localeCookieName, validatedLocale);
|
|
143
|
+
};
|
|
144
|
+
return [setLocale, setLocaleWithoutPersist];
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=useDetermineLocale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_generaltranslation","_internal","_getNativeLocales","_nativeStore","useDetermineLocale","locale","_locale","defaultLocale","libraryDefaultLocale","locales","localeCookieName","ssr","customMapping","resolveAliasLocale","map","initializeLocale","result","determineLocale","getNewLocale","_setLocale","useState","setLocale","setLocaleWithoutPersist","createSetLocale","useEffect","newLocale","storedLocale","nativeStoreGet","preferredLocales","getNativeLocales","length","l","nativeStoreSet","validatedLocale","console","warn"],"sourceRoot":"../../../../../src","sources":["provider/hooks/locale/useDetermineLocale.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,mBAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AAMA,IAAAG,iBAAA,GAAAH,OAAA;AACA,IAAAI,YAAA,GAAAJ,OAAA;AAEO,SAASK,kBAAkBA,CAAC;EACjCC,MAAM,EAAEC,OAAO,GAAG,EAAE;EACpBC,aAAa,GAAGC,8BAAoB;EACpCC,OAAO,GAAG,EAAE;EACZC,gBAAgB,GAAG,2BAA2B;EAC9CC,GAAG,GAAG,KAAK;EAAE;EACbC;AACwB,CAAC,EAA4B;EACrD;EACAN,OAAO,GAAG,IAAAO,sCAAkB,EAACP,OAAO,EAAEM,aAAa,CAAC;EACpDH,OAAO,GAAGA,OAAO,CAACK,GAAG,CAAET,MAAM,IAAK,IAAAQ,sCAAkB,EAACR,MAAM,EAAEO,aAAa,CAAC,CAAC;EAE5E,MAAMG,gBAAgB,GAAGA,CAAA,KAAM;IAC7B,MAAMC,MAAM,GAAG,IAAAH,sCAAkB,EAC/BF,GAAG,GACCL,OAAO,GACL,IAAAW,mCAAe,EAACX,OAAO,EAAEG,OAAO,EAAEG,aAAa,CAAC,IAAI,EAAE,GACtD,EAAE,GACJM,YAAY,CAAC;MACXZ,OAAO;MACPD,MAAM,EAAEC,OAAO;MACfG,OAAO;MACPF,aAAa;MACbG,gBAAgB;MAChBE;IACF,CAAC,CAAC,EACNA,aACF,CAAC;IACD,OAAOI,MAAM;EACf,CAAC;;EAED;EACA,MAAM,CAACX,MAAM,EAAEc,UAAU,CAAC,GAAG,IAAAC,eAAQ,EAASL,gBAAgB,CAAC,CAAC,CAAC;;EAEjE;EACA,MAAM,CAACM,SAAS,EAAEC,uBAAuB,CAAC,GAAGC,eAAe,CAAC;IAC3DlB,MAAM;IACNI,OAAO;IACPF,aAAa;IACbG,gBAAgB;IAChBS,UAAU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B,CAACG,SAAS,CAAC;IAC1D,IAAAO,2BAAc,EAACtB,gBAAgB,EAAEuB,eAAe,CAAC;EACnD,CAAC;EACD,OAAO,CAACZ,SAAS,EAAEC,uBAAuB,CAAC;AAC7C","ignoreList":[]}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useRegionState = useRegionState;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _nativeStore = require("../../utils/nativeStore");
|
|
9
|
+
function getNewRegion({
|
|
10
|
+
_region,
|
|
11
|
+
regionCookieName
|
|
12
|
+
}) {
|
|
13
|
+
// Check for region in native store
|
|
14
|
+
const cookieRegion = (0, _nativeStore.nativeStoreGet)(regionCookieName) || undefined;
|
|
15
|
+
const newRegion = _region || cookieRegion;
|
|
16
|
+
|
|
17
|
+
// if state not valid, change it to newRegion
|
|
18
|
+
if (cookieRegion && cookieRegion !== newRegion) {
|
|
19
|
+
(0, _nativeStore.nativeStoreSet)(regionCookieName, newRegion || '');
|
|
20
|
+
}
|
|
21
|
+
return newRegion;
|
|
22
|
+
}
|
|
23
|
+
function useRegionState({
|
|
24
|
+
_region,
|
|
25
|
+
ssr,
|
|
26
|
+
regionCookieName
|
|
27
|
+
}) {
|
|
28
|
+
const [region, _setRegion] = (0, _react.useState)(ssr ? undefined : getNewRegion({
|
|
29
|
+
_region,
|
|
30
|
+
regionCookieName
|
|
31
|
+
}));
|
|
32
|
+
const setRegion = newRegion => {
|
|
33
|
+
_setRegion(newRegion);
|
|
34
|
+
(0, _nativeStore.nativeStoreSet)(regionCookieName, newRegion || '');
|
|
35
|
+
};
|
|
36
|
+
(0, _react.useEffect)(() => {
|
|
37
|
+
_setRegion(getNewRegion({
|
|
38
|
+
_region,
|
|
39
|
+
regionCookieName
|
|
40
|
+
}));
|
|
41
|
+
}, [_region, regionCookieName]);
|
|
42
|
+
return {
|
|
43
|
+
region,
|
|
44
|
+
setRegion
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=useRegionState.js.map
|