gt-react-native 10.19.15 → 10.19.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/dist/commonjs/NativeGtReactNative.js +9 -7
  2. package/dist/commonjs/NativeGtReactNative.js.map +1 -1
  3. package/dist/commonjs/_virtual/_rolldown/runtime.js +23 -0
  4. package/dist/commonjs/errors-dir/constants.js +5 -6
  5. package/dist/commonjs/errors-dir/constants.js.map +1 -1
  6. package/dist/commonjs/errors-dir/errors.js +12 -7
  7. package/dist/commonjs/errors-dir/errors.js.map +1 -1
  8. package/dist/commonjs/errors-dir/warnings.js +34 -15
  9. package/dist/commonjs/errors-dir/warnings.js.map +1 -1
  10. package/dist/commonjs/index.js +35 -194
  11. package/dist/commonjs/internal.js +3 -13
  12. package/dist/commonjs/plugin-dir/index.js +35 -51
  13. package/dist/commonjs/plugin-dir/index.js.map +1 -1
  14. package/dist/commonjs/plugin-dir/types.js +24 -9
  15. package/dist/commonjs/plugin-dir/types.js.map +1 -1
  16. package/dist/commonjs/plugin-dir/utils/resolveLocales.js +52 -69
  17. package/dist/commonjs/plugin-dir/utils/resolveLocales.js.map +1 -1
  18. package/dist/commonjs/plugin.js +5 -13
  19. package/dist/commonjs/provider/GTProvider.js +22 -20
  20. package/dist/commonjs/provider/GTProvider.js.map +1 -1
  21. package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js +96 -160
  22. package/dist/commonjs/provider/hooks/locale/useDetermineLocale.js.map +1 -1
  23. package/dist/commonjs/provider/hooks/useRegionState.js +32 -44
  24. package/dist/commonjs/provider/hooks/useRegionState.js.map +1 -1
  25. package/dist/commonjs/tools/testLocalePolyfill.js +125 -146
  26. package/dist/commonjs/tools/testLocalePolyfill.js.map +1 -1
  27. package/dist/commonjs/types/config.js +1 -6
  28. package/dist/commonjs/utils/getNativeLocales.js +36 -51
  29. package/dist/commonjs/utils/getNativeLocales.js.map +1 -1
  30. package/dist/commonjs/utils/nativeStore.js +37 -42
  31. package/dist/commonjs/utils/nativeStore.js.map +1 -1
  32. package/dist/commonjs/utils/utils.js +10 -14
  33. package/dist/commonjs/utils/utils.js.map +1 -1
  34. package/dist/module/NativeGtReactNative.d.ts.map +1 -0
  35. package/dist/module/NativeGtReactNative.js +5 -3
  36. package/dist/module/NativeGtReactNative.js.map +1 -1
  37. package/dist/module/errors-dir/constants.d.ts.map +1 -0
  38. package/dist/module/errors-dir/constants.js +4 -2
  39. package/dist/module/errors-dir/constants.js.map +1 -1
  40. package/dist/module/errors-dir/errors.d.ts.map +1 -0
  41. package/dist/module/errors-dir/errors.js +11 -3
  42. package/dist/module/errors-dir/errors.js.map +1 -1
  43. package/dist/{typescript/commonjs/src → module}/errors-dir/warnings.d.ts +1 -1
  44. package/dist/module/errors-dir/warnings.d.ts.map +1 -0
  45. package/dist/module/errors-dir/warnings.js +31 -11
  46. package/dist/module/errors-dir/warnings.js.map +1 -1
  47. package/dist/module/index.d.ts.map +1 -0
  48. package/dist/module/index.js +2 -5
  49. package/dist/module/internal.d.ts.map +1 -0
  50. package/dist/module/internal.js +2 -4
  51. package/dist/module/plugin-dir/index.d.ts.map +1 -0
  52. package/dist/module/plugin-dir/index.js +28 -45
  53. package/dist/module/plugin-dir/index.js.map +1 -1
  54. package/dist/{typescript/commonjs/src → module}/plugin-dir/types.d.ts +1 -1
  55. package/dist/module/plugin-dir/types.d.ts.map +1 -0
  56. package/dist/module/plugin-dir/types.js +22 -5
  57. package/dist/module/plugin-dir/types.js.map +1 -1
  58. package/dist/{typescript/commonjs/src → module}/plugin-dir/utils/resolveLocales.d.ts +1 -1
  59. package/dist/module/plugin-dir/utils/resolveLocales.d.ts.map +1 -0
  60. package/dist/module/plugin-dir/utils/resolveLocales.js +46 -62
  61. package/dist/module/plugin-dir/utils/resolveLocales.js.map +1 -1
  62. package/dist/module/plugin.d.ts.map +1 -0
  63. package/dist/module/plugin.js +2 -4
  64. package/dist/module/provider/GTProvider.d.ts.map +1 -0
  65. package/dist/module/provider/GTProvider.js +15 -14
  66. package/dist/module/provider/GTProvider.js.map +1 -1
  67. package/dist/module/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
  68. package/dist/module/provider/hooks/locale/useDetermineLocale.js +91 -153
  69. package/dist/module/provider/hooks/locale/useDetermineLocale.js.map +1 -1
  70. package/dist/module/provider/hooks/useRegionState.d.ts.map +1 -0
  71. package/dist/module/provider/hooks/useRegionState.js +29 -39
  72. package/dist/module/provider/hooks/useRegionState.js.map +1 -1
  73. package/dist/module/tools/testLocalePolyfill.d.ts.map +1 -0
  74. package/dist/module/tools/testLocalePolyfill.js +124 -143
  75. package/dist/module/tools/testLocalePolyfill.js.map +1 -1
  76. package/dist/{typescript/commonjs/src → module}/types/config.d.ts +4 -4
  77. package/dist/module/types/config.d.ts.map +1 -0
  78. package/dist/module/types/config.js +0 -3
  79. package/dist/module/utils/getNativeLocales.d.ts.map +1 -0
  80. package/dist/module/utils/getNativeLocales.js +35 -48
  81. package/dist/module/utils/getNativeLocales.js.map +1 -1
  82. package/dist/module/utils/nativeStore.d.ts.map +1 -0
  83. package/dist/module/utils/nativeStore.js +35 -38
  84. package/dist/module/utils/nativeStore.js.map +1 -1
  85. package/dist/module/utils/utils.d.ts.map +1 -0
  86. package/dist/module/utils/utils.js +10 -11
  87. package/dist/module/utils/utils.js.map +1 -1
  88. package/package.json +15 -36
  89. package/src/errors-dir/errors.ts +8 -1
  90. package/src/errors-dir/warnings.ts +30 -9
  91. package/src/plugin-dir/types.ts +4 -1
  92. package/src/plugin-dir/utils/resolveLocales.ts +4 -1
  93. package/src/provider/hooks/locale/useDetermineLocale.ts +7 -3
  94. package/src/types/config.ts +4 -3
  95. package/src/utils/getNativeLocales.ts +7 -2
  96. package/dist/commonjs/index.js.map +0 -1
  97. package/dist/commonjs/internal.js.map +0 -1
  98. package/dist/commonjs/package.json +0 -1
  99. package/dist/commonjs/plugin.js.map +0 -1
  100. package/dist/commonjs/types/config.js.map +0 -1
  101. package/dist/module/index.js.map +0 -1
  102. package/dist/module/internal.js.map +0 -1
  103. package/dist/module/package.json +0 -1
  104. package/dist/module/plugin.js.map +0 -1
  105. package/dist/module/types/config.js.map +0 -1
  106. package/dist/typescript/commonjs/package.json +0 -1
  107. package/dist/typescript/commonjs/src/NativeGtReactNative.d.ts.map +0 -1
  108. package/dist/typescript/commonjs/src/errors-dir/constants.d.ts.map +0 -1
  109. package/dist/typescript/commonjs/src/errors-dir/errors.d.ts.map +0 -1
  110. package/dist/typescript/commonjs/src/errors-dir/warnings.d.ts.map +0 -1
  111. package/dist/typescript/commonjs/src/index.d.ts.map +0 -1
  112. package/dist/typescript/commonjs/src/internal.d.ts.map +0 -1
  113. package/dist/typescript/commonjs/src/plugin-dir/index.d.ts.map +0 -1
  114. package/dist/typescript/commonjs/src/plugin-dir/types.d.ts.map +0 -1
  115. package/dist/typescript/commonjs/src/plugin-dir/utils/resolveLocales.d.ts.map +0 -1
  116. package/dist/typescript/commonjs/src/plugin.d.ts.map +0 -1
  117. package/dist/typescript/commonjs/src/provider/GTProvider.d.ts.map +0 -1
  118. package/dist/typescript/commonjs/src/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
  119. package/dist/typescript/commonjs/src/provider/hooks/useRegionState.d.ts.map +0 -1
  120. package/dist/typescript/commonjs/src/tools/testLocalePolyfill.d.ts.map +0 -1
  121. package/dist/typescript/commonjs/src/types/config.d.ts.map +0 -1
  122. package/dist/typescript/commonjs/src/utils/getNativeLocales.d.ts.map +0 -1
  123. package/dist/typescript/commonjs/src/utils/nativeStore.d.ts.map +0 -1
  124. package/dist/typescript/commonjs/src/utils/utils.d.ts.map +0 -1
  125. package/dist/typescript/module/package.json +0 -1
  126. package/dist/typescript/module/src/NativeGtReactNative.d.ts +0 -10
  127. package/dist/typescript/module/src/NativeGtReactNative.d.ts.map +0 -1
  128. package/dist/typescript/module/src/errors-dir/constants.d.ts +0 -2
  129. package/dist/typescript/module/src/errors-dir/constants.d.ts.map +0 -1
  130. package/dist/typescript/module/src/errors-dir/errors.d.ts +0 -2
  131. package/dist/typescript/module/src/errors-dir/errors.d.ts.map +0 -1
  132. package/dist/typescript/module/src/errors-dir/warnings.d.ts +0 -5
  133. package/dist/typescript/module/src/errors-dir/warnings.d.ts.map +0 -1
  134. package/dist/typescript/module/src/index.d.ts +0 -5
  135. package/dist/typescript/module/src/index.d.ts.map +0 -1
  136. package/dist/typescript/module/src/internal.d.ts +0 -2
  137. package/dist/typescript/module/src/internal.d.ts.map +0 -1
  138. package/dist/typescript/module/src/plugin-dir/index.d.ts +0 -6
  139. package/dist/typescript/module/src/plugin-dir/index.d.ts.map +0 -1
  140. package/dist/typescript/module/src/plugin-dir/types.d.ts +0 -13
  141. package/dist/typescript/module/src/plugin-dir/types.d.ts.map +0 -1
  142. package/dist/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts +0 -13
  143. package/dist/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts.map +0 -1
  144. package/dist/typescript/module/src/plugin.d.ts +0 -2
  145. package/dist/typescript/module/src/plugin.d.ts.map +0 -1
  146. package/dist/typescript/module/src/provider/GTProvider.d.ts +0 -4
  147. package/dist/typescript/module/src/provider/GTProvider.d.ts.map +0 -1
  148. package/dist/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts +0 -4
  149. package/dist/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
  150. package/dist/typescript/module/src/provider/hooks/useRegionState.d.ts +0 -3
  151. package/dist/typescript/module/src/provider/hooks/useRegionState.d.ts.map +0 -1
  152. package/dist/typescript/module/src/tools/testLocalePolyfill.d.ts +0 -8
  153. package/dist/typescript/module/src/tools/testLocalePolyfill.d.ts.map +0 -1
  154. package/dist/typescript/module/src/types/config.d.ts +0 -30
  155. package/dist/typescript/module/src/types/config.d.ts.map +0 -1
  156. package/dist/typescript/module/src/utils/getNativeLocales.d.ts +0 -10
  157. package/dist/typescript/module/src/utils/getNativeLocales.d.ts.map +0 -1
  158. package/dist/typescript/module/src/utils/nativeStore.d.ts +0 -16
  159. package/dist/typescript/module/src/utils/nativeStore.d.ts.map +0 -1
  160. package/dist/typescript/module/src/utils/utils.d.ts +0 -3
  161. package/dist/typescript/module/src/utils/utils.d.ts.map +0 -1
  162. /package/dist/{typescript/commonjs/src → module}/NativeGtReactNative.d.ts +0 -0
  163. /package/dist/{typescript/commonjs/src → module}/errors-dir/constants.d.ts +0 -0
  164. /package/dist/{typescript/commonjs/src → module}/errors-dir/errors.d.ts +0 -0
  165. /package/dist/{typescript/commonjs/src → module}/index.d.ts +0 -0
  166. /package/dist/{typescript/commonjs/src → module}/internal.d.ts +0 -0
  167. /package/dist/{typescript/commonjs/src → module}/plugin-dir/index.d.ts +0 -0
  168. /package/dist/{typescript/commonjs/src → module}/plugin.d.ts +0 -0
  169. /package/dist/{typescript/commonjs/src → module}/provider/GTProvider.d.ts +0 -0
  170. /package/dist/{typescript/commonjs/src → module}/provider/hooks/locale/useDetermineLocale.d.ts +0 -0
  171. /package/dist/{typescript/commonjs/src → module}/provider/hooks/useRegionState.d.ts +0 -0
  172. /package/dist/{typescript/commonjs/src → module}/tools/testLocalePolyfill.d.ts +0 -0
  173. /package/dist/{typescript/commonjs/src → module}/utils/getNativeLocales.d.ts +0 -0
  174. /package/dist/{typescript/commonjs/src → module}/utils/nativeStore.d.ts +0 -0
  175. /package/dist/{typescript/commonjs/src → module}/utils/utils.d.ts +0 -0
@@ -1,75 +1,58 @@
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
-
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_runtime = require("../../_virtual/_rolldown/runtime.js");
3
+ const require_errors_dir_warnings = require("../../errors-dir/warnings.js");
4
+ const require_errors_dir_errors = require("../../errors-dir/errors.js");
5
+ let generaltranslation_internal = require("generaltranslation/internal");
6
+ let path = require("path");
7
+ path = require_runtime.__toESM(path);
8
+ let fs = require("fs");
9
+ fs = require_runtime.__toESM(fs);
10
+ let _generaltranslation_supported_locales = require("@generaltranslation/supported-locales");
11
+ //#region src/plugin-dir/utils/resolveLocales.ts
12
+ const DEFAULT_CONFIG_FILE_PATHS = [path.default.join(process.cwd(), "gt.config.json"), path.default.join(process.cwd(), ".locadex", "gt.config.json")];
16
13
  /**
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;
14
+ * Given a list of locales or a config object or a path to a config file, return a list of locales to polyfill.
15
+ * Preference order: locales > config > configFilePaths > library default locale
16
+ */
17
+ function resolveLocales({ locales, config, configFilePath }) {
18
+ let result = [];
19
+ if (locales) result = Array.from(new Set(locales));
20
+ else if (config) result = Array.from(new Set([config.defaultLocale, ...config.locales]));
21
+ else result = resolveLocalesFromConfig(configFilePath);
22
+ const invalidLocales = result.filter((locale) => !(0, _generaltranslation_supported_locales.getSupportedLocale)(locale));
23
+ if (invalidLocales.length) {
24
+ console.warn(require_errors_dir_warnings.invalidLocalesWarning(invalidLocales));
25
+ result = result.filter((locale) => !invalidLocales.includes(locale));
26
+ }
27
+ if (result.length === 0) {
28
+ console.warn(require_errors_dir_warnings.resolveLocalesFailedWarning);
29
+ result = [generaltranslation_internal.libraryDefaultLocale];
30
+ }
31
+ return result;
49
32
  }
50
-
51
33
  /**
52
- * Resolve locales from a config file
53
- * @param configFilePath - The path to the config file
54
- * @returns A list of locales
55
- */
34
+ * Resolve locales from a config file
35
+ * @param configFilePath - The path to the config file
36
+ * @returns A list of locales
37
+ */
56
38
  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
- break;
68
- } catch (error) {
69
- console.error((0, _errors.failedToReadConfigFileError)(filePath), error);
70
- break;
71
- }
72
- }
73
- return result;
39
+ const configFilePaths = [...configFilePath ? [configFilePath] : [], ...DEFAULT_CONFIG_FILE_PATHS];
40
+ let result = [];
41
+ for (const filePath of configFilePaths) try {
42
+ if (!fs.default.existsSync(filePath)) {
43
+ console.warn(require_errors_dir_warnings.couldNotLocateConfigWarning(filePath));
44
+ continue;
45
+ }
46
+ const resolvedConfig = JSON.parse(fs.default.readFileSync(filePath, "utf8"));
47
+ result = Array.from(new Set([...resolvedConfig.defaultLocale ? [resolvedConfig.defaultLocale] : [], ...resolvedConfig.locales || []]));
48
+ break;
49
+ } catch (error) {
50
+ console.error(require_errors_dir_errors.failedToReadConfigFileError(filePath), error);
51
+ break;
52
+ }
53
+ return result;
74
54
  }
55
+ //#endregion
56
+ exports.resolveLocales = resolveLocales;
57
+
75
58
  //# sourceMappingURL=resolveLocales.js.map
@@ -1 +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,OAAO,CAACC,GAAG,CAAC,CAAC,EAAE,UAAU,EAAE,gBAA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zB,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;MACD;IACF,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":[]}
1
+ {"version":3,"file":"resolveLocales.js","names":["invalidLocalesWarning","resolveLocalesFailedWarning","libraryDefaultLocale","couldNotLocateConfigWarning","failedToReadConfigFileError"],"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,KAAA,QAAK,KAAK,QAAQ,KAAK,EAAE,iBAAiB,EAC1C,KAAA,QAAK,KAAK,QAAQ,KAAK,EAAE,YAAY,iBAAiB,CACvD;;;;;AAMD,SAAgB,eAA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defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
5
4
  });
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
5
+ const require_plugin_dir_index = require("./plugin-dir/index.js");
6
+ exports.default = require_plugin_dir_index.default;
@@ -1,24 +1,26 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
1
+ Object.defineProperties(exports, {
2
+ __esModule: { value: true },
3
+ [Symbol.toStringTag]: { value: "Module" }
5
4
  });
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");
5
+ require("../_virtual/_rolldown/runtime.js");
6
+ const require_provider_hooks_locale_useDetermineLocale = require("./hooks/locale/useDetermineLocale.js");
7
+ const require_utils_utils = require("../utils/utils.js");
8
+ const require_provider_hooks_useRegionState = require("./hooks/useRegionState.js");
9
+ let _generaltranslation_react_core = require("@generaltranslation/react-core");
10
+ let react_jsx_runtime = require("react/jsx-runtime");
11
+ //#region src/provider/GTProvider.tsx
13
12
  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
- });
13
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_generaltranslation_react_core.GTProvider, {
14
+ ssr: false,
15
+ environment: __DEV__ ? "development" : "production",
16
+ ...props,
17
+ readAuthFromEnv: require_utils_utils.readAuthFromEnv,
18
+ useDetermineLocale: require_provider_hooks_locale_useDetermineLocale.useDetermineLocale,
19
+ useRegionState: require_provider_hooks_useRegionState.useRegionState
20
+ });
22
21
  }
23
- var _default = exports.default = GTProvider;
22
+ //#endregion
23
+ exports.GTProvider = GTProvider;
24
+ exports.default = GTProvider;
25
+
24
26
  //# sourceMappingURL=GTProvider.js.map
@@ -1 +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":[]}
1
+ {"version":3,"file":"GTProvider.js","names":["_GTProvider","readAuthFromEnv","useDetermineLocale","useRegionState"],"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,iBAAA,GAAA,kBAAA,KAACA,+BAAAA,YAAD;EACE,KAAK;EACL,aAAa,UAAU,gBAAgB;EACvC,GAAI;EACJ,iBAAiBC,oBAAAA;EACjB,oBAAoBC,iDAAAA;EACpB,gBAAgBC,sCAAAA;EAChB,CAAA"}
@@ -1,165 +1,101 @@
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 _errors = require("@generaltranslation/react-core/errors");
11
- var _constants = require("../../../errors-dir/constants");
12
- var _getNativeLocales = require("../../../utils/getNativeLocales");
13
- var _nativeStore = require("../../../utils/nativeStore");
14
- function useDetermineLocale({
15
- locale: _locale = '',
16
- defaultLocale = _internal.libraryDefaultLocale,
17
- locales = [],
18
- localeCookieName = 'generaltranslation.locale',
19
- ssr = false,
20
- // not relevant
21
- customMapping,
22
- enableI18n
23
- }) {
24
- // resolve alias locale
25
- _locale = (0, _generaltranslation.resolveAliasLocale)(_locale, customMapping);
26
- locales = locales.map(locale => (0, _generaltranslation.resolveAliasLocale)(locale, customMapping));
27
- const initializeLocale = () => {
28
- if (!enableI18n) {
29
- return defaultLocale;
30
- }
31
- const result = (0, _generaltranslation.resolveAliasLocale)(ssr ? _locale ? (0, _generaltranslation.determineLocale)(_locale, locales, customMapping) || '' : '' : getNewLocale({
32
- _locale,
33
- locale: _locale,
34
- locales,
35
- defaultLocale,
36
- localeCookieName,
37
- customMapping,
38
- enableI18n
39
- }), customMapping);
40
- return result;
41
- };
42
-
43
- // maintaining the state of locale
44
- const [locale, _setLocale] = (0, _react.useState)(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
- enableI18n
55
- });
56
-
57
- // check browser for locales
58
- (0, _react.useEffect)(() => {
59
- const newLocale = getNewLocale({
60
- _locale,
61
- locale,
62
- locales,
63
- defaultLocale,
64
- localeCookieName,
65
- customMapping,
66
- enableI18n
67
- });
68
- setLocaleWithoutPersist(newLocale);
69
- }, [_locale, locale, locales, defaultLocale, localeCookieName, customMapping, enableI18n]);
70
- return [locale, setLocale];
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ require("../../../_virtual/_rolldown/runtime.js");
3
+ const require_errors_dir_constants = require("../../../errors-dir/constants.js");
4
+ const require_utils_getNativeLocales = require("../../../utils/getNativeLocales.js");
5
+ const require_utils_nativeStore = require("../../../utils/nativeStore.js");
6
+ let react = require("react");
7
+ let _generaltranslation_format = require("@generaltranslation/format");
8
+ let generaltranslation_internal = require("generaltranslation/internal");
9
+ let _generaltranslation_react_core_errors = require("@generaltranslation/react-core/errors");
10
+ //#region src/provider/hooks/locale/useDetermineLocale.ts
11
+ function useDetermineLocale({ locale: _locale = "", defaultLocale = generaltranslation_internal.libraryDefaultLocale, locales = [], localeCookieName = "generaltranslation.locale", ssr = false, customMapping, enableI18n }) {
12
+ _locale = (0, _generaltranslation_format.resolveAliasLocale)(_locale, customMapping);
13
+ locales = locales.map((locale) => (0, _generaltranslation_format.resolveAliasLocale)(locale, customMapping));
14
+ const initializeLocale = () => {
15
+ if (!enableI18n) return defaultLocale;
16
+ return (0, _generaltranslation_format.resolveAliasLocale)(ssr ? _locale ? (0, _generaltranslation_format.determineLocale)(_locale, locales, customMapping) || "" : "" : getNewLocale({
17
+ _locale,
18
+ locale: _locale,
19
+ locales,
20
+ defaultLocale,
21
+ localeCookieName,
22
+ customMapping,
23
+ enableI18n
24
+ }), customMapping);
25
+ };
26
+ const [locale, _setLocale] = (0, react.useState)(initializeLocale());
27
+ const [setLocale, setLocaleWithoutPersist] = createSetLocale({
28
+ locale,
29
+ locales,
30
+ defaultLocale,
31
+ localeCookieName,
32
+ _setLocale,
33
+ customMapping,
34
+ enableI18n
35
+ });
36
+ (0, react.useEffect)(() => {
37
+ setLocaleWithoutPersist(getNewLocale({
38
+ _locale,
39
+ locale,
40
+ locales,
41
+ defaultLocale,
42
+ localeCookieName,
43
+ customMapping,
44
+ enableI18n
45
+ }));
46
+ }, [
47
+ _locale,
48
+ locale,
49
+ locales,
50
+ defaultLocale,
51
+ localeCookieName,
52
+ customMapping,
53
+ enableI18n
54
+ ]);
55
+ return [locale, setLocale];
71
56
  }
72
-
73
- // ----- HELPER FUNCTIONS ---- //
74
-
75
57
  /**
76
- * Choose a locale to use
77
- * (1) use provided locale
78
- * (2) use cookie locale
79
- * (3) use preferred locale
80
- * (5) fallback to defaultLocale
81
- * Update the cookie locale to be correct
82
- */
83
- function getNewLocale({
84
- _locale,
85
- locale,
86
- locales,
87
- defaultLocale,
88
- localeCookieName,
89
- customMapping,
90
- enableI18n
91
- }) {
92
- if (!enableI18n) {
93
- return defaultLocale;
94
- }
95
- // No change, return
96
- if (_locale && _locale === locale && (0, _generaltranslation.determineLocale)(_locale, locales, customMapping) === locale) {
97
- return (0, _generaltranslation.resolveAliasLocale)(_locale, customMapping);
98
- }
99
-
100
- // Check for locale in native store
101
- let storedLocale = (0, _nativeStore.nativeStoreGet)(localeCookieName);
102
- if (storedLocale) {
103
- storedLocale = (0, _generaltranslation.resolveAliasLocale)(storedLocale, customMapping);
104
- }
105
-
106
- // check user's configured locales
107
- let preferredLocales = (0, _getNativeLocales.getNativeLocales)();
108
- if (preferredLocales.length === 0) preferredLocales = [defaultLocale];
109
- preferredLocales = preferredLocales.map(l => (0, _generaltranslation.resolveAliasLocale)(l, customMapping));
110
-
111
- // determine locale
112
- let newLocale = (0, _generaltranslation.determineLocale)([...(_locale ? [_locale] : []),
113
- // prefer user passed locale
114
- ...(storedLocale ? [storedLocale] : []),
115
- // then prefer stored locale
116
- ...preferredLocales // then prefer browser locale
117
- ], locales, customMapping) || defaultLocale;
118
- if (newLocale) {
119
- newLocale = (0, _generaltranslation.resolveAliasLocale)(newLocale, customMapping);
120
- }
121
-
122
- // if stored locale not valid, change it back to whatever we use for fallback
123
- if (storedLocale && storedLocale !== newLocale) {
124
- (0, _nativeStore.nativeStoreSet)(localeCookieName, newLocale);
125
- }
126
-
127
- // return new locale
128
- return newLocale;
58
+ * Choose a locale to use
59
+ * (1) use provided locale
60
+ * (2) use cookie locale
61
+ * (3) use preferred locale
62
+ * (5) fallback to defaultLocale
63
+ * Update the cookie locale to be correct
64
+ */
65
+ function getNewLocale({ _locale, locale, locales, defaultLocale, localeCookieName, customMapping, enableI18n }) {
66
+ if (!enableI18n) return defaultLocale;
67
+ if (_locale && _locale === locale && (0, _generaltranslation_format.determineLocale)(_locale, locales, customMapping) === locale) return (0, _generaltranslation_format.resolveAliasLocale)(_locale, customMapping);
68
+ let storedLocale = require_utils_nativeStore.nativeStoreGet(localeCookieName);
69
+ if (storedLocale) storedLocale = (0, _generaltranslation_format.resolveAliasLocale)(storedLocale, customMapping);
70
+ let preferredLocales = require_utils_getNativeLocales.getNativeLocales();
71
+ if (preferredLocales.length === 0) preferredLocales = [defaultLocale];
72
+ preferredLocales = preferredLocales.map((l) => (0, _generaltranslation_format.resolveAliasLocale)(l, customMapping));
73
+ let newLocale = (0, _generaltranslation_format.determineLocale)([
74
+ ..._locale ? [_locale] : [],
75
+ ...storedLocale ? [storedLocale] : [],
76
+ ...preferredLocales
77
+ ], locales, customMapping) || defaultLocale;
78
+ if (newLocale) newLocale = (0, _generaltranslation_format.resolveAliasLocale)(newLocale, customMapping);
79
+ if (storedLocale && storedLocale !== newLocale) require_utils_nativeStore.nativeStoreSet(localeCookieName, newLocale);
80
+ return newLocale;
129
81
  }
130
- function createSetLocale({
131
- locale,
132
- locales,
133
- defaultLocale,
134
- _setLocale,
135
- localeCookieName,
136
- customMapping,
137
- enableI18n
138
- }) {
139
- locale = (0, _generaltranslation.resolveAliasLocale)(locale, customMapping);
140
- // Just update the internal state, don't persist it
141
- const setLocaleWithoutPersist = newLocale => {
142
- if (!enableI18n) {
143
- return defaultLocale;
144
- }
145
- // validate locale
146
- const validatedLocale = (0, _generaltranslation.resolveAliasLocale)((0, _generaltranslation.determineLocale)(newLocale, locales, customMapping) || locale || defaultLocale, customMapping);
147
- if (validatedLocale !== newLocale) {
148
- console.warn((0, _errors.createUnsupportedLocaleWarning)(validatedLocale, newLocale, _constants.PACKAGE_NAME));
149
- }
150
- // persist locale
151
- _setLocale(validatedLocale);
152
- return validatedLocale;
153
- };
154
- // update locale and persist it in native store
155
- const setLocale = newLocale => {
156
- if (!enableI18n) {
157
- return;
158
- }
159
- newLocale = (0, _generaltranslation.resolveAliasLocale)(newLocale, customMapping);
160
- const validatedLocale = setLocaleWithoutPersist(newLocale);
161
- (0, _nativeStore.nativeStoreSet)(localeCookieName, validatedLocale);
162
- };
163
- return [setLocale, setLocaleWithoutPersist];
82
+ function createSetLocale({ locale, locales, defaultLocale, _setLocale, localeCookieName, customMapping, enableI18n }) {
83
+ locale = (0, _generaltranslation_format.resolveAliasLocale)(locale, customMapping);
84
+ const setLocaleWithoutPersist = (newLocale) => {
85
+ if (!enableI18n) return defaultLocale;
86
+ const validatedLocale = (0, _generaltranslation_format.resolveAliasLocale)((0, _generaltranslation_format.determineLocale)(newLocale, locales, customMapping) || locale || defaultLocale, customMapping);
87
+ if (validatedLocale !== newLocale) console.warn((0, _generaltranslation_react_core_errors.createUnsupportedLocaleWarning)(validatedLocale, newLocale, require_errors_dir_constants.PACKAGE_NAME));
88
+ _setLocale(validatedLocale);
89
+ return validatedLocale;
90
+ };
91
+ const setLocale = (newLocale) => {
92
+ if (!enableI18n) return;
93
+ newLocale = (0, _generaltranslation_format.resolveAliasLocale)(newLocale, customMapping);
94
+ require_utils_nativeStore.nativeStoreSet(localeCookieName, setLocaleWithoutPersist(newLocale));
95
+ };
96
+ return [setLocale, setLocaleWithoutPersist];
164
97
  }
98
+ //#endregion
99
+ exports.useDetermineLocale = useDetermineLocale;
100
+
165
101
  //# sourceMappingURL=useDetermineLocale.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_generaltranslation","_internal","_errors","_constants","_getNativeLocales","_nativeStore","useDetermineLocale","locale","_locale","defaultLocale","libraryDefaultLocale","locales","localeCookieName","ssr","customMapping","enableI18n","resolveAliasLocale","map","initializeLocale","result","determineLocale","getNewLocale","_setLocale","useState","setLocale","setLocaleWithoutPersist","createSetLocale","useEffect","newLocale","storedLocale","nativeStoreGet","preferredLocales","getNativeLocales","length","l","nativeStoreSet","validatedLocale","console","warn","createUnsupportedLocaleWarning","PACKAGE_NAME"],"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,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AACA,IAAAM,YAAA,GAAAN,OAAA;AAEO,SAASO,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,aAAa;EACbC;AACwB,CAAC,EAA4B;EACrD;EACAP,OAAO,GAAG,IAAAQ,sCAAkB,EAACR,OAAO,EAAEM,aAA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AAKD,SAAS,EAAE;IAC9C,IAAAO,2BAAc,EAACvB,gBAAgB,EAAEgB,SAAS,CAAC;EAC7C;;EAEA;EACA,OAAOA,SAAS;AAClB;AAEA,SAASF,eAAeA,CAAC;EACvBnB,MAAM;EACNI,OAAO;EACPF,aAAa;EACba,UAAU;EACVV,gBAAgB;EAChBE,aAAa;EACbC;AASF,CAAC,EAA8D;EAC7DR,MAAM,GAAG,IAAAS,sCAAkB,EAACT,MAAM,EAAEO,aAAa,CAAC;EAClD;EACA,MAAMW,uBAAuB,GAAIG,SAAiB,IAAa;IAC7D,IAAI,CAACb,UAAU,EAAE;MACf,OAAON,aAAa;IACtB;IACA;IACA,MAAM2B,eAAe,GAAG,IAAApB,sCAAkB,EACxC,IAAAI,mCAAe,EAACQ,SAAS,EAAEjB,OAAO,EAAEG,aAAa,CAAC,IAChDP,MAAM,IACNE,aAAa,EACfK,aACF,CAAC;IACD,IAAIsB,eAAe,KAAKR,SAAS,EAAE;MACjCS,OAAO,CAACC,IAAI,CACV,IAAAC,sCAA8B,EAACH,eAAe,EAAER,SAAS,EAAEY,uBAAY,CACzE,CAAC;IACH;IACA;IACAlB,UAAU,CAACc,eAAe,CAAC;IAE3B,OAAOA,eAAe;EACxB,CAAC;EACD;EACA,MAAMZ,SAAS,GAAII,SAAiB,IAAW;IAC7C,IAAI,CAACb,UAAU,EAAE;MACf;IACF;IACAa,SAAS,GAAG,IAAAZ,sCAAkB,EAACY,SAAS,EAAEd,aAAa,CAAC;IACxD,MAAMsB,eAAe,GAAGX,uBAAuB,CAACG,SAAS,CAAC;IAC1D,IAAAO,2BAAc,EAACvB,gBAAgB,EAAEwB,eAAe,CAAC;EACnD,CAAC;EACD,OAAO,CAACZ,SAAS,EAAEC,uBAAuB,CAAC;AAC7C","ignoreList":[]}
1
+ {"version":3,"file":"useDetermineLocale.js","names":["libraryDefaultLocale","nativeStoreGet","getNativeLocales","PACKAGE_NAME"],"sources":["../../../../../src/provider/hooks/locale/useDetermineLocale.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { Dispatch, SetStateAction } from 'react';\nimport {\n determineLocale,\n resolveAliasLocale,\n} from '@generaltranslation/format';\nimport { libraryDefaultLocale } from 'generaltranslation/internal';\nimport type { CustomMapping } from '@generaltranslation/format/types';\nimport type {\n UseDetermineLocaleParams,\n UseDetermineLocaleReturn,\n} from '@generaltranslation/react-core/types';\nimport { createUnsupportedLocaleWarning } from '@generaltranslation/react-core/errors';\nimport { PACKAGE_NAME } from '../../../errors-dir/constants';\nimport { getNativeLocales } from '../../../utils/getNativeLocales';\nimport { nativeStoreGet, nativeStoreSet } from '../../../utils/nativeStore';\n\nexport function useDetermineLocale({\n locale: _locale = '',\n defaultLocale = libraryDefaultLocale,\n locales = [],\n localeCookieName = 'generaltranslation.locale',\n ssr = false, // not relevant\n customMapping,\n enableI18n,\n}: UseDetermineLocaleParams): UseDetermineLocaleReturn {\n // resolve alias locale\n _locale = resolveAliasLocale(_locale, customMapping);\n locales = locales.map((locale) => resolveAliasLocale(locale, customMapping));\n\n const initializeLocale = () => {\n if (!enableI18n) {\n return defaultLocale;\n }\n const result = resolveAliasLocale(\n ssr\n ? _locale\n ? determineLocale(_locale, locales, customMapping) || ''\n : ''\n : getNewLocale({\n _locale,\n locale: _locale,\n locales,\n defaultLocale,\n localeCookieName,\n customMapping,\n enableI18n,\n }),\n customMapping\n );\n return result;\n };\n\n // maintaining the state of locale\n const [locale, _setLocale] = useState<string>(initializeLocale());\n\n // Functions for setting internal locale state\n const [setLocale, setLocaleWithoutPersist] = createSetLocale({\n locale,\n locales,\n defaultLocale,\n localeCookieName,\n _setLocale,\n customMapping,\n enableI18n,\n });\n\n // check browser for locales\n useEffect(() => {\n const newLocale = getNewLocale({\n _locale,\n locale,\n locales,\n defaultLocale,\n localeCookieName,\n customMapping,\n enableI18n,\n });\n setLocaleWithoutPersist(newLocale);\n }, [\n _locale,\n locale,\n locales,\n defaultLocale,\n localeCookieName,\n customMapping,\n enableI18n,\n ]);\n\n return [locale, setLocale];\n}\n\n// ----- HELPER FUNCTIONS ---- //\n\n/**\n * Choose a locale to use\n * (1) use provided locale\n * (2) use cookie locale\n * (3) use preferred locale\n * (5) fallback to defaultLocale\n * Update the cookie locale to be correct\n */\nfunction getNewLocale({\n _locale,\n locale,\n locales,\n defaultLocale,\n localeCookieName,\n customMapping,\n enableI18n,\n}: {\n _locale: string;\n locale: string;\n locales: string[];\n defaultLocale: string;\n localeCookieName: string;\n customMapping?: CustomMapping;\n enableI18n: boolean;\n}): string {\n if (!enableI18n) {\n return defaultLocale;\n }\n // No change, return\n if (\n _locale &&\n _locale === locale &&\n determineLocale(_locale, locales, customMapping) === locale\n ) {\n return resolveAliasLocale(_locale, customMapping);\n }\n\n // Check for locale in native store\n let storedLocale = nativeStoreGet(localeCookieName);\n if (storedLocale) {\n storedLocale = resolveAliasLocale(storedLocale, customMapping);\n }\n\n // check user's configured locales\n let preferredLocales = getNativeLocales();\n if (preferredLocales.length === 0) preferredLocales = [defaultLocale];\n preferredLocales = preferredLocales.map((l) =>\n resolveAliasLocale(l, customMapping)\n );\n\n // determine locale\n let newLocale =\n determineLocale(\n [\n ...(_locale ? [_locale] : []), // prefer user passed locale\n ...(storedLocale ? [storedLocale] : []), // then prefer stored locale\n ...preferredLocales, // then prefer browser locale\n ],\n locales,\n customMapping\n ) || defaultLocale;\n if (newLocale) {\n newLocale = resolveAliasLocale(newLocale, customMapping);\n }\n\n // if stored locale not valid, change it back to whatever we use for fallback\n if (storedLocale && storedLocale !== newLocale) {\n nativeStoreSet(localeCookieName, newLocale);\n }\n\n // return new locale\n return newLocale;\n}\n\nfunction createSetLocale({\n locale,\n locales,\n defaultLocale,\n _setLocale,\n localeCookieName,\n customMapping,\n enableI18n,\n}: {\n locale: string;\n locales: string[];\n defaultLocale: string;\n localeCookieName: string;\n _setLocale: Dispatch<SetStateAction<string>>;\n customMapping?: CustomMapping;\n enableI18n: boolean;\n}): [(newLocale: string) => void, (newLocale: string) => void] {\n locale = resolveAliasLocale(locale, customMapping);\n // Just update the internal state, don't persist it\n const setLocaleWithoutPersist = (newLocale: string): string => {\n if (!enableI18n) {\n return defaultLocale;\n }\n // validate locale\n const validatedLocale = resolveAliasLocale(\n determineLocale(newLocale, locales, customMapping) ||\n locale ||\n defaultLocale,\n customMapping\n );\n if (validatedLocale !== newLocale) {\n console.warn(\n createUnsupportedLocaleWarning(validatedLocale, newLocale, PACKAGE_NAME)\n );\n }\n // persist locale\n _setLocale(validatedLocale);\n\n return validatedLocale;\n };\n // update locale and persist it in native store\n const setLocale = (newLocale: string): void => {\n if (!enableI18n) {\n return;\n }\n newLocale = resolveAliasLocale(newLocale, customMapping);\n const validatedLocale = setLocaleWithoutPersist(newLocale);\n nativeStoreSet(localeCookieName, validatedLocale);\n };\n return [setLocale, setLocaleWithoutPersist];\n}\n"],"mappings":";;;;;;;;;;AAiBA,SAAgB,mBAAmB,EACjC,QAAQ,UAAU,IAClB,gBAAgBA,4BAAAA,sBAChB,UAAU,EAAE,EACZ,mBAAmB,6BACnB,MAAM,OACN,eACA,cACqD;AAErD,YAAA,GAAA,2BAAA,oBAA6B,SAAS,cAAc;AACpD,WAAU,QAAQ,KAAK,YAAA,GAAA,2BAAA,oBAA8B,QAAQ,cAAc,CAAC;CAE5E,MAAM,yBAAyB;AAC7B,MAAI,CAAC,WACH,QAAO;AAkBT,UAAA,GAAA,2BAAA,oBAfE,MACI,WAAA,GAAA,2BAAA,iBACkB,SAAS,SAAS,cAAc,IAAI,KACpD,KACF,aAAa;GACX;GACA,QAAQ;GACR;GACA;GACA;GACA;GACA;GACD,CAAC,EACN,cAEW;;CAIf,MAAM,CAAC,QAAQ,eAAA,GAAA,MAAA,UAA+B,kBAAkB,CAAC;CAGjE,MAAM,CAAC,WAAW,2BAA2B,gBAAgB;EAC3D;EACA;EACA;EACA;EACA;EACA;EACA;EACD,CAAC;AAGF,EAAA,GAAA,MAAA,iBAAgB;AAUd,0BATkB,aAAa;GAC7B;GACA;GACA;GAC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