gt-react-native 0.0.2 → 0.0.4

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 (147) hide show
  1. package/lib/commonjs/NativeGtReactNative.js +9 -0
  2. package/lib/commonjs/NativeGtReactNative.js.map +1 -0
  3. package/lib/commonjs/errors-dir/constants.js +8 -0
  4. package/lib/commonjs/errors-dir/constants.js.map +1 -0
  5. package/lib/commonjs/errors-dir/errors.js +10 -0
  6. package/lib/commonjs/errors-dir/errors.js.map +1 -0
  7. package/lib/commonjs/errors-dir/warnings.js +18 -0
  8. package/lib/commonjs/errors-dir/warnings.js.map +1 -0
  9. package/lib/commonjs/index.js +158 -0
  10. package/lib/commonjs/index.js.map +1 -0
  11. package/lib/commonjs/internal.js +13 -0
  12. package/lib/commonjs/internal.js.map +1 -0
  13. package/lib/commonjs/package.json +1 -0
  14. package/lib/commonjs/plugin-dir/index.js +54 -0
  15. package/lib/commonjs/plugin-dir/index.js.map +1 -0
  16. package/lib/commonjs/plugin-dir/types.js +11 -0
  17. package/lib/commonjs/plugin-dir/types.js.map +1 -0
  18. package/lib/commonjs/plugin-dir/utils/resolveLocales.js +74 -0
  19. package/lib/commonjs/plugin-dir/utils/resolveLocales.js.map +1 -0
  20. package/lib/commonjs/plugin.js +14 -0
  21. package/lib/commonjs/plugin.js.map +1 -0
  22. package/lib/commonjs/provider/GTProvider.js +24 -0
  23. package/lib/commonjs/provider/GTProvider.js.map +1 -0
  24. package/lib/commonjs/provider/hooks/locale/useDetermineLocale.js +146 -0
  25. package/lib/commonjs/provider/hooks/locale/useDetermineLocale.js.map +1 -0
  26. package/lib/commonjs/provider/hooks/useRegionState.js +47 -0
  27. package/lib/commonjs/provider/hooks/useRegionState.js.map +1 -0
  28. package/lib/commonjs/tools/testLocalePolyfill.js +182 -0
  29. package/lib/commonjs/tools/testLocalePolyfill.js.map +1 -0
  30. package/lib/commonjs/types/config.js +6 -0
  31. package/lib/commonjs/types/config.js.map +1 -0
  32. package/lib/commonjs/utils/getNativeLocales.js +58 -0
  33. package/lib/commonjs/utils/getNativeLocales.js.map +1 -0
  34. package/lib/commonjs/utils/nativeStore.js +39 -0
  35. package/lib/commonjs/utils/nativeStore.js.map +1 -0
  36. package/lib/commonjs/utils/utils.js +17 -0
  37. package/lib/commonjs/utils/utils.js.map +1 -0
  38. package/lib/module/plugin-dir/index.js +4 -4
  39. package/lib/module/plugin-dir/index.js.map +1 -1
  40. package/lib/module/plugin-dir/types.js +5 -0
  41. package/lib/module/plugin-dir/types.js.map +1 -1
  42. package/lib/module/tools/testLocalePolyfill.js +125 -11
  43. package/lib/module/tools/testLocalePolyfill.js.map +1 -1
  44. package/lib/typescript/commonjs/package.json +1 -0
  45. package/lib/typescript/commonjs/src/NativeGtReactNative.d.ts.map +1 -0
  46. package/lib/typescript/commonjs/src/errors-dir/constants.d.ts.map +1 -0
  47. package/lib/typescript/commonjs/src/errors-dir/errors.d.ts.map +1 -0
  48. package/lib/typescript/commonjs/src/errors-dir/warnings.d.ts.map +1 -0
  49. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  50. package/lib/typescript/commonjs/src/internal.d.ts.map +1 -0
  51. package/lib/typescript/commonjs/src/plugin-dir/index.d.ts +6 -0
  52. package/lib/typescript/commonjs/src/plugin-dir/index.d.ts.map +1 -0
  53. package/lib/typescript/commonjs/src/plugin-dir/types.d.ts +13 -0
  54. package/lib/typescript/commonjs/src/plugin-dir/types.d.ts.map +1 -0
  55. package/lib/typescript/commonjs/src/plugin-dir/utils/resolveLocales.d.ts.map +1 -0
  56. package/lib/typescript/commonjs/src/plugin.d.ts.map +1 -0
  57. package/lib/typescript/commonjs/src/provider/GTProvider.d.ts.map +1 -0
  58. package/lib/typescript/commonjs/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
  59. package/lib/typescript/commonjs/src/provider/hooks/useRegionState.d.ts.map +1 -0
  60. package/lib/typescript/commonjs/src/tools/testLocalePolyfill.d.ts +8 -0
  61. package/lib/typescript/commonjs/src/tools/testLocalePolyfill.d.ts.map +1 -0
  62. package/lib/typescript/commonjs/src/types/config.d.ts.map +1 -0
  63. package/lib/typescript/commonjs/src/utils/getNativeLocales.d.ts.map +1 -0
  64. package/lib/typescript/commonjs/src/utils/nativeStore.d.ts.map +1 -0
  65. package/lib/typescript/commonjs/src/utils/utils.d.ts.map +1 -0
  66. package/lib/typescript/commonjs/vitest.config.d.ts.map +1 -0
  67. package/lib/typescript/module/src/NativeGtReactNative.d.ts +10 -0
  68. package/lib/typescript/module/src/NativeGtReactNative.d.ts.map +1 -0
  69. package/lib/typescript/module/src/errors-dir/constants.d.ts +2 -0
  70. package/lib/typescript/module/src/errors-dir/constants.d.ts.map +1 -0
  71. package/lib/typescript/module/src/errors-dir/errors.d.ts +2 -0
  72. package/lib/typescript/module/src/errors-dir/errors.d.ts.map +1 -0
  73. package/lib/typescript/module/src/errors-dir/warnings.d.ts +4 -0
  74. package/lib/typescript/module/src/errors-dir/warnings.d.ts.map +1 -0
  75. package/lib/typescript/module/src/index.d.ts +6 -0
  76. package/lib/typescript/module/src/index.d.ts.map +1 -0
  77. package/lib/typescript/module/src/internal.d.ts +2 -0
  78. package/lib/typescript/module/src/internal.d.ts.map +1 -0
  79. package/lib/typescript/module/src/plugin-dir/index.d.ts +6 -0
  80. package/lib/typescript/module/src/plugin-dir/index.d.ts.map +1 -0
  81. package/lib/typescript/module/src/plugin-dir/types.d.ts +13 -0
  82. package/lib/typescript/module/src/plugin-dir/types.d.ts.map +1 -0
  83. package/lib/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts +13 -0
  84. package/lib/typescript/module/src/plugin-dir/utils/resolveLocales.d.ts.map +1 -0
  85. package/lib/typescript/module/src/plugin.d.ts +2 -0
  86. package/lib/typescript/module/src/plugin.d.ts.map +1 -0
  87. package/lib/typescript/module/src/provider/GTProvider.d.ts +4 -0
  88. package/lib/typescript/module/src/provider/GTProvider.d.ts.map +1 -0
  89. package/lib/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts +4 -0
  90. package/lib/typescript/module/src/provider/hooks/locale/useDetermineLocale.d.ts.map +1 -0
  91. package/lib/typescript/module/src/provider/hooks/useRegionState.d.ts +3 -0
  92. package/lib/typescript/module/src/provider/hooks/useRegionState.d.ts.map +1 -0
  93. package/lib/typescript/module/src/tools/testLocalePolyfill.d.ts +8 -0
  94. package/lib/typescript/module/src/tools/testLocalePolyfill.d.ts.map +1 -0
  95. package/lib/typescript/module/src/types/config.d.ts +30 -0
  96. package/lib/typescript/module/src/types/config.d.ts.map +1 -0
  97. package/lib/typescript/module/src/utils/getNativeLocales.d.ts +10 -0
  98. package/lib/typescript/module/src/utils/getNativeLocales.d.ts.map +1 -0
  99. package/lib/typescript/module/src/utils/nativeStore.d.ts +16 -0
  100. package/lib/typescript/module/src/utils/nativeStore.d.ts.map +1 -0
  101. package/lib/typescript/module/src/utils/utils.d.ts +3 -0
  102. package/lib/typescript/module/src/utils/utils.d.ts.map +1 -0
  103. package/lib/typescript/module/vitest.config.d.ts +3 -0
  104. package/lib/typescript/module/vitest.config.d.ts.map +1 -0
  105. package/package.json +11 -6
  106. package/src/plugin-dir/index.ts +6 -16
  107. package/src/plugin-dir/types.ts +23 -0
  108. package/src/tools/testLocalePolyfill.ts +170 -15
  109. package/lib/typescript/src/NativeGtReactNative.d.ts.map +0 -1
  110. package/lib/typescript/src/errors-dir/constants.d.ts.map +0 -1
  111. package/lib/typescript/src/errors-dir/errors.d.ts.map +0 -1
  112. package/lib/typescript/src/errors-dir/warnings.d.ts.map +0 -1
  113. package/lib/typescript/src/index.d.ts.map +0 -1
  114. package/lib/typescript/src/internal.d.ts.map +0 -1
  115. package/lib/typescript/src/plugin-dir/index.d.ts +0 -6
  116. package/lib/typescript/src/plugin-dir/index.d.ts.map +0 -1
  117. package/lib/typescript/src/plugin-dir/types.d.ts +0 -10
  118. package/lib/typescript/src/plugin-dir/types.d.ts.map +0 -1
  119. package/lib/typescript/src/plugin-dir/utils/resolveLocales.d.ts.map +0 -1
  120. package/lib/typescript/src/plugin.d.ts.map +0 -1
  121. package/lib/typescript/src/provider/GTProvider.d.ts.map +0 -1
  122. package/lib/typescript/src/provider/hooks/locale/useDetermineLocale.d.ts.map +0 -1
  123. package/lib/typescript/src/provider/hooks/useRegionState.d.ts.map +0 -1
  124. package/lib/typescript/src/tools/testLocalePolyfill.d.ts +0 -12
  125. package/lib/typescript/src/tools/testLocalePolyfill.d.ts.map +0 -1
  126. package/lib/typescript/src/types/config.d.ts.map +0 -1
  127. package/lib/typescript/src/utils/getNativeLocales.d.ts.map +0 -1
  128. package/lib/typescript/src/utils/nativeStore.d.ts.map +0 -1
  129. package/lib/typescript/src/utils/utils.d.ts.map +0 -1
  130. package/lib/typescript/vitest.config.d.ts.map +0 -1
  131. /package/lib/typescript/{src → commonjs/src}/NativeGtReactNative.d.ts +0 -0
  132. /package/lib/typescript/{src → commonjs/src}/errors-dir/constants.d.ts +0 -0
  133. /package/lib/typescript/{src → commonjs/src}/errors-dir/errors.d.ts +0 -0
  134. /package/lib/typescript/{src → commonjs/src}/errors-dir/warnings.d.ts +0 -0
  135. /package/lib/typescript/{src → commonjs/src}/index.d.ts +0 -0
  136. /package/lib/typescript/{src → commonjs/src}/internal.d.ts +0 -0
  137. /package/lib/typescript/{src → commonjs/src}/plugin-dir/utils/resolveLocales.d.ts +0 -0
  138. /package/lib/typescript/{src → commonjs/src}/plugin.d.ts +0 -0
  139. /package/lib/typescript/{src → commonjs/src}/provider/GTProvider.d.ts +0 -0
  140. /package/lib/typescript/{src → commonjs/src}/provider/hooks/locale/useDetermineLocale.d.ts +0 -0
  141. /package/lib/typescript/{src → commonjs/src}/provider/hooks/useRegionState.d.ts +0 -0
  142. /package/lib/typescript/{src → commonjs/src}/types/config.d.ts +0 -0
  143. /package/lib/typescript/{src → commonjs/src}/utils/getNativeLocales.d.ts +0 -0
  144. /package/lib/typescript/{src → commonjs/src}/utils/nativeStore.d.ts +0 -0
  145. /package/lib/typescript/{src → commonjs/src}/utils/utils.d.ts +0 -0
  146. /package/lib/typescript/{vitest.config.d.ts → commonjs/vitest.config.d.ts} +0 -0
  147. /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,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.PACKAGE_NAME = void 0;
7
+ const PACKAGE_NAME = exports.PACKAGE_NAME = 'gt-react-native';
8
+ //# sourceMappingURL=constants.js.map
@@ -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 _types = require("./types");
9
+ var _resolveLocales = require("./utils/resolveLocales");
10
+ 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); }
11
+ function _default(babel, {
12
+ locales,
13
+ config,
14
+ configFilePath,
15
+ entryPointFilePath = path.resolve(process.cwd(), 'src', 'App.tsx'),
16
+ excludePolyfills = []
17
+ }) {
18
+ const {
19
+ types: t
20
+ } = babel;
21
+ return {
22
+ name: 'gt-react-native/plugin',
23
+ visitor: {
24
+ Program(programPath, state) {
25
+ const currentFilePath = path.resolve(state.filename || state.file.opts.filename || '');
26
+
27
+ // Only apply polyfills to files that import gt-react-native or generaltranslation
28
+ if (currentFilePath !== entryPointFilePath) {
29
+ return;
30
+ }
31
+ const resolvedLocales = (0, _resolveLocales.resolveLocales)({
32
+ locales,
33
+ config,
34
+ configFilePath
35
+ });
36
+
37
+ // TODO: smart imports based on if the polyfill is required, do this as a wrapper around AppRegistry.registerComponent()
38
+ const imports = [..._types.POLYFILLS.filter(polyfill => !excludePolyfills.includes(polyfill)), ...resolvedLocales.flatMap(locale => [..._types.LOCALE_POLYFILLS.map(localeData => `${localeData}/${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","_types","_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","excludePolyfills","types","name","visitor","Program","programPath","state","currentFilePath","filename","file","opts","resolvedLocales","resolveLocales","imports","POLYFILLS","filter","polyfill","includes","flatMap","locale","LOCALE_POLYFILLS","map","localeData","existingImports","Set","node","body","forEach","isImportDeclaration","source","value","add","importsToAdd","imp","length","newImports","importPath","importDeclaration","stringLiteral","unshift"],"sourceRoot":"../../../src","sources":["plugin-dir/index.ts"],"mappings":";;;;;;AAAA,IAAAA,IAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,eAAA,GAAAF,OAAA;AAAwD,SAAAD,wBAAAI,CAAA,EAAAC,CAAA,6BAAA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AGH,YAAY,CAACX,GAAG,CAAEe,UAAU,IAC7C/D,CAAC,CAACgE,iBAAiB,CAAC,EAAE,EAAEhE,CAAC,CAACiE,aAAa,CAACF,UAAU,CAAC,CACrD,CAAC;UAED/B,WAAW,CAACoB,IAAI,CAACC,IAAI,CAACa,OAAO,CAAC,GAAGJ,UAAU,CAAC;QAC9C;MACF;IACF;EACF,CAAC;AACH","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.POLYFILLS = exports.LOCALE_POLYFILLS = void 0;
7
+ const POLYFILLS = exports.POLYFILLS = ['@formatjs/intl-getcanonicallocales/polyfill', '@formatjs/intl-locale/polyfill', '@formatjs/intl-displaynames/polyfill', '@formatjs/intl-listformat/polyfill', '@formatjs/intl-pluralrules/polyfill-force',
8
+ // https://github.com/formatjs/formatjs/issues/4463
9
+ '@formatjs/intl-numberformat/polyfill', '@formatjs/intl-relativetimeformat/polyfill', '@formatjs/intl-datetimeformat/polyfill', '@formatjs/intl-datetimeformat/add-all-tz'];
10
+ const LOCALE_POLYFILLS = exports.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`];
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["POLYFILLS","exports","LOCALE_POLYFILLS"],"sourceRoot":"../../../src","sources":["plugin-dir/types.ts"],"mappings":";;;;;;AAAO,MAAMA,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,CACvB,6CAA6C,EAC7C,gCAAgC,EAChC,sCAAsC,EACtC,oCAAoC,EACpC,2CAA2C;AAAE;AAC7C,sCAAsC,EACtC,4CAA4C,EAC5C,wCAAwC,EACxC,0CAA0C,CAClC;AAEH,MAAME,gBAAgB,GAAAD,OAAA,CAAAC,gBAAA,GAAG,CAC9B,yCAAyC,EACzC,uCAAuC,EACvC,wCAAwC,EACxC,yCAAyC,EACzC,+CAA+C,EAC/C,2CAA2C,CACnC","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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zCf,MAAM,GAAG,CAACgB,8BAAoB,CAAC;EACjC;EAEA,OAAOhB,MAAM;AACf;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASK,wBAAwBA,CAACN,cAAkC,EAAE;EACpE,MAAMkB,eAAe,GAAG,CACtB,IAAIlB,cAAc,GAAG,CAACA,cAAc,CAAC,GAAG,EAAE,CAAC,EAC3C,GAAGR,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,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