@esgettext/runtime 1.0.0 → 1.2.0

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 (321) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +23 -25
  3. package/{lib-esm → dist}/core/browser-environment.d.ts +1 -0
  4. package/dist/core/browser-environment.d.ts.map +1 -0
  5. package/dist/core/catalog-cache.d.ts +22 -0
  6. package/dist/core/catalog-cache.d.ts.map +1 -0
  7. package/dist/core/catalog-cache.spec.d.ts +2 -0
  8. package/dist/core/catalog-cache.spec.d.ts.map +1 -0
  9. package/dist/core/catalog-format.spec.d.ts +2 -0
  10. package/dist/core/catalog-format.spec.d.ts.map +1 -0
  11. package/dist/core/catalog.d.ts +48 -0
  12. package/dist/core/catalog.d.ts.map +1 -0
  13. package/{lib → dist}/core/data-viewlet.d.ts +11 -0
  14. package/dist/core/data-viewlet.d.ts.map +1 -0
  15. package/dist/core/data-viewlet.spec.d.ts +2 -0
  16. package/dist/core/data-viewlet.spec.d.ts.map +1 -0
  17. package/{lib-esm → dist}/core/explode-locale.d.ts +1 -0
  18. package/dist/core/explode-locale.d.ts.map +1 -0
  19. package/dist/core/explode-locale.spec.d.ts +2 -0
  20. package/dist/core/explode-locale.spec.d.ts.map +1 -0
  21. package/{lib-esm → dist}/core/germanic-plural.d.ts +1 -0
  22. package/dist/core/germanic-plural.d.ts.map +1 -0
  23. package/{lib → dist}/core/gettext-impl.d.ts +1 -0
  24. package/dist/core/gettext-impl.d.ts.map +1 -0
  25. package/dist/core/gettext.spec.d.ts +2 -0
  26. package/dist/core/gettext.spec.d.ts.map +1 -0
  27. package/{lib-esm → dist}/core/index.d.ts +1 -0
  28. package/dist/core/index.d.ts.map +1 -0
  29. package/dist/core/locale-container.d.ts +32 -0
  30. package/dist/core/locale-container.d.ts.map +1 -0
  31. package/dist/core/platform.d.ts +3 -0
  32. package/dist/core/platform.d.ts.map +1 -0
  33. package/{lib → dist}/core/resolve-impl.d.ts +1 -0
  34. package/dist/core/resolve-impl.d.ts.map +1 -0
  35. package/dist/core/resolve.spec.d.ts +2 -0
  36. package/dist/core/resolve.spec.d.ts.map +1 -0
  37. package/{lib-esm → dist}/core/select-locale.d.ts +1 -0
  38. package/dist/core/select-locale.d.ts.map +1 -0
  39. package/dist/core/select-locale.spec.d.ts +2 -0
  40. package/dist/core/select-locale.spec.d.ts.map +1 -0
  41. package/dist/core/set-locale-browser.spec.d.ts +2 -0
  42. package/dist/core/set-locale-browser.spec.d.ts.map +1 -0
  43. package/dist/core/set-locale-node.spec.d.ts +2 -0
  44. package/dist/core/set-locale-node.spec.d.ts.map +1 -0
  45. package/{lib-esm → dist}/core/split-locale.d.ts +1 -0
  46. package/dist/core/split-locale.d.ts.map +1 -0
  47. package/dist/core/split-locale.spec.d.ts +2 -0
  48. package/dist/core/split-locale.spec.d.ts.map +1 -0
  49. package/dist/core/textdomain.d.ts +464 -0
  50. package/dist/core/textdomain.d.ts.map +1 -0
  51. package/dist/core/textdomain.spec.d.ts +2 -0
  52. package/dist/core/textdomain.spec.d.ts.map +1 -0
  53. package/{lib-esm → dist}/core/user-locales.d.ts +1 -0
  54. package/dist/core/user-locales.d.ts.map +1 -0
  55. package/dist/esgettext.cjs.js +1411 -0
  56. package/dist/esgettext.cjs.js.map +1 -0
  57. package/dist/esgettext.esm.js +1406 -0
  58. package/dist/esgettext.esm.js.map +1 -0
  59. package/dist/esgettext.js +1415 -0
  60. package/dist/esgettext.js.map +1 -0
  61. package/dist/esgettext.min.js +2 -0
  62. package/dist/esgettext.min.js.map +1 -0
  63. package/dist/index-browser.d.ts +3 -0
  64. package/dist/index-browser.d.ts.map +1 -0
  65. package/dist/index.d.ts +3 -0
  66. package/dist/index.d.ts.map +1 -0
  67. package/dist/parser/index.d.ts +4 -0
  68. package/dist/parser/index.d.ts.map +1 -0
  69. package/{lib-esm → dist}/parser/parse-json-catalog.d.ts +1 -0
  70. package/dist/parser/parse-json-catalog.d.ts.map +1 -0
  71. package/{lib-esm → dist}/parser/parse-mo-catalog.d.ts +1 -0
  72. package/dist/parser/parse-mo-catalog.d.ts.map +1 -0
  73. package/dist/parser/parse-mo-catalog.spec.d.ts +2 -0
  74. package/dist/parser/parse-mo-catalog.spec.d.ts.map +1 -0
  75. package/dist/parser/parse-mo-json-catalog.d.ts +4 -0
  76. package/dist/parser/parse-mo-json-catalog.d.ts.map +1 -0
  77. package/dist/parser/parse-mo-json-catalog.spec.d.ts +2 -0
  78. package/dist/parser/parse-mo-json-catalog.spec.d.ts.map +1 -0
  79. package/{lib/transport/fs.d.ts → dist/transport/fs-browser.d.ts} +2 -1
  80. package/dist/transport/fs-browser.d.ts.map +1 -0
  81. package/{lib-esm → dist}/transport/fs.d.ts +1 -0
  82. package/dist/transport/fs.d.ts.map +1 -0
  83. package/{lib-esm → dist}/transport/http.d.ts +1 -0
  84. package/dist/transport/http.d.ts.map +1 -0
  85. package/dist/transport/http.spec.d.ts +2 -0
  86. package/dist/transport/http.spec.d.ts.map +1 -0
  87. package/{lib → dist}/transport/index.d.ts +2 -1
  88. package/dist/transport/index.d.ts.map +1 -0
  89. package/{lib → dist}/transport/transport.interface.d.ts +1 -0
  90. package/dist/transport/transport.interface.d.ts.map +1 -0
  91. package/package.json +30 -14
  92. package/_bundles/runtime.js +0 -1356
  93. package/_bundles/runtime.js.map +0 -1
  94. package/_bundles/runtime.min.js +0 -2
  95. package/_bundles/runtime.min.js.map +0 -1
  96. package/api-docs/assets/highlight.css +0 -127
  97. package/api-docs/assets/main.js +0 -59
  98. package/api-docs/assets/navigation.js +0 -1
  99. package/api-docs/assets/search.js +0 -1
  100. package/api-docs/assets/style.css +0 -1414
  101. package/api-docs/classes/Textdomain.html +0 -364
  102. package/api-docs/index.html +0 -222
  103. package/api-docs/interfaces/Catalog.html +0 -20
  104. package/api-docs/interfaces/CatalogEntries.html +0 -11
  105. package/api-docs/interfaces/LocaleContainer.html +0 -19
  106. package/api-docs/interfaces/Placeholders.html +0 -9
  107. package/api-docs/modules.html +0 -6
  108. package/lib/core/browser-environment.d.ts +0 -1
  109. package/lib/core/browser-environment.js +0 -12
  110. package/lib/core/browser-environment.js.map +0 -1
  111. package/lib/core/catalog-cache.d.ts +0 -10
  112. package/lib/core/catalog-cache.js +0 -39
  113. package/lib/core/catalog-cache.js.map +0 -1
  114. package/lib/core/catalog-cache.spec.d.ts +0 -1
  115. package/lib/core/catalog-cache.spec.js +0 -24
  116. package/lib/core/catalog-cache.spec.js.map +0 -1
  117. package/lib/core/catalog-format.spec.d.ts +0 -1
  118. package/lib/core/catalog-format.spec.js +0 -35
  119. package/lib/core/catalog-format.spec.js.map +0 -1
  120. package/lib/core/catalog.d.ts +0 -9
  121. package/lib/core/catalog.js +0 -3
  122. package/lib/core/catalog.js.map +0 -1
  123. package/lib/core/data-viewlet.js +0 -57
  124. package/lib/core/data-viewlet.js.map +0 -1
  125. package/lib/core/data-viewlet.spec.d.ts +0 -1
  126. package/lib/core/data-viewlet.spec.js +0 -62
  127. package/lib/core/data-viewlet.spec.js.map +0 -1
  128. package/lib/core/explode-locale.d.ts +0 -3
  129. package/lib/core/explode-locale.js +0 -37
  130. package/lib/core/explode-locale.js.map +0 -1
  131. package/lib/core/explode-locale.spec.d.ts +0 -1
  132. package/lib/core/explode-locale.spec.js +0 -41
  133. package/lib/core/explode-locale.spec.js.map +0 -1
  134. package/lib/core/germanic-plural.d.ts +0 -1
  135. package/lib/core/germanic-plural.js +0 -8
  136. package/lib/core/germanic-plural.js.map +0 -1
  137. package/lib/core/gettext-impl.js +0 -38
  138. package/lib/core/gettext-impl.js.map +0 -1
  139. package/lib/core/gettext.spec.d.ts +0 -1
  140. package/lib/core/gettext.spec.js +0 -391
  141. package/lib/core/gettext.spec.js.map +0 -1
  142. package/lib/core/index.d.ts +0 -4
  143. package/lib/core/index.js +0 -21
  144. package/lib/core/index.js.map +0 -1
  145. package/lib/core/locale-container.d.ts +0 -8
  146. package/lib/core/locale-container.js +0 -3
  147. package/lib/core/locale-container.js.map +0 -1
  148. package/lib/core/path-separator.d.ts +0 -1
  149. package/lib/core/path-separator.js +0 -12
  150. package/lib/core/path-separator.js.map +0 -1
  151. package/lib/core/resolve-impl.js +0 -253
  152. package/lib/core/resolve-impl.js.map +0 -1
  153. package/lib/core/resolve.spec.d.ts +0 -1
  154. package/lib/core/resolve.spec.js +0 -345
  155. package/lib/core/resolve.spec.js.map +0 -1
  156. package/lib/core/select-locale.d.ts +0 -1
  157. package/lib/core/select-locale.js +0 -43
  158. package/lib/core/select-locale.js.map +0 -1
  159. package/lib/core/select-locale.spec.d.ts +0 -1
  160. package/lib/core/select-locale.spec.js +0 -27
  161. package/lib/core/select-locale.spec.js.map +0 -1
  162. package/lib/core/set-locale-browser.spec.d.ts +0 -1
  163. package/lib/core/set-locale-browser.spec.js +0 -17
  164. package/lib/core/set-locale-browser.spec.js.map +0 -1
  165. package/lib/core/set-locale-node.spec.d.ts +0 -1
  166. package/lib/core/set-locale-node.spec.js +0 -26
  167. package/lib/core/set-locale-node.spec.js.map +0 -1
  168. package/lib/core/split-locale.d.ts +0 -7
  169. package/lib/core/split-locale.js +0 -39
  170. package/lib/core/split-locale.js.map +0 -1
  171. package/lib/core/split-locale.spec.d.ts +0 -1
  172. package/lib/core/split-locale.spec.js +0 -59
  173. package/lib/core/split-locale.spec.js.map +0 -1
  174. package/lib/core/textdomain.d.ts +0 -55
  175. package/lib/core/textdomain.js +0 -277
  176. package/lib/core/textdomain.js.map +0 -1
  177. package/lib/core/textdomain.spec.d.ts +0 -1
  178. package/lib/core/textdomain.spec.js +0 -33
  179. package/lib/core/textdomain.spec.js.map +0 -1
  180. package/lib/core/user-locales.d.ts +0 -1
  181. package/lib/core/user-locales.js +0 -12
  182. package/lib/core/user-locales.js.map +0 -1
  183. package/lib/index-browser.d.ts +0 -2
  184. package/lib/index-browser.js +0 -44
  185. package/lib/index-browser.js.map +0 -1
  186. package/lib/index.d.ts +0 -2
  187. package/lib/index.js +0 -37
  188. package/lib/index.js.map +0 -1
  189. package/lib/parser/index.d.ts +0 -2
  190. package/lib/parser/index.js +0 -19
  191. package/lib/parser/index.js.map +0 -1
  192. package/lib/parser/parse-json-catalog.d.ts +0 -3
  193. package/lib/parser/parse-json-catalog.js +0 -37
  194. package/lib/parser/parse-json-catalog.js.map +0 -1
  195. package/lib/parser/parse-json-catalog.spec.d.ts +0 -1
  196. package/lib/parser/parse-json-catalog.spec.js +0 -41
  197. package/lib/parser/parse-json-catalog.spec.js.map +0 -1
  198. package/lib/parser/parse-mo-catalog.d.ts +0 -2
  199. package/lib/parser/parse-mo-catalog.js +0 -86
  200. package/lib/parser/parse-mo-catalog.js.map +0 -1
  201. package/lib/parser/parse-mo-catalog.spec.d.ts +0 -1
  202. package/lib/parser/parse-mo-catalog.spec.js +0 -115
  203. package/lib/parser/parse-mo-catalog.spec.js.map +0 -1
  204. package/lib/transport/fs.js +0 -18
  205. package/lib/transport/fs.js.map +0 -1
  206. package/lib/transport/http.d.ts +0 -4
  207. package/lib/transport/http.js +0 -27
  208. package/lib/transport/http.js.map +0 -1
  209. package/lib/transport/http.spec.d.ts +0 -1
  210. package/lib/transport/http.spec.js +0 -119
  211. package/lib/transport/http.spec.js.map +0 -1
  212. package/lib/transport/index.js +0 -20
  213. package/lib/transport/index.js.map +0 -1
  214. package/lib/transport/transport.interface.js +0 -3
  215. package/lib/transport/transport.interface.js.map +0 -1
  216. package/lib-esm/core/browser-environment.js +0 -8
  217. package/lib-esm/core/browser-environment.js.map +0 -1
  218. package/lib-esm/core/catalog-cache.d.ts +0 -10
  219. package/lib-esm/core/catalog-cache.js +0 -36
  220. package/lib-esm/core/catalog-cache.js.map +0 -1
  221. package/lib-esm/core/catalog-cache.spec.d.ts +0 -1
  222. package/lib-esm/core/catalog-cache.spec.js +0 -22
  223. package/lib-esm/core/catalog-cache.spec.js.map +0 -1
  224. package/lib-esm/core/catalog-format.spec.d.ts +0 -1
  225. package/lib-esm/core/catalog-format.spec.js +0 -33
  226. package/lib-esm/core/catalog-format.spec.js.map +0 -1
  227. package/lib-esm/core/catalog.d.ts +0 -9
  228. package/lib-esm/core/catalog.js +0 -2
  229. package/lib-esm/core/catalog.js.map +0 -1
  230. package/lib-esm/core/data-viewlet.d.ts +0 -11
  231. package/lib-esm/core/data-viewlet.js +0 -54
  232. package/lib-esm/core/data-viewlet.js.map +0 -1
  233. package/lib-esm/core/data-viewlet.spec.d.ts +0 -1
  234. package/lib-esm/core/data-viewlet.spec.js +0 -60
  235. package/lib-esm/core/data-viewlet.spec.js.map +0 -1
  236. package/lib-esm/core/explode-locale.js +0 -33
  237. package/lib-esm/core/explode-locale.js.map +0 -1
  238. package/lib-esm/core/explode-locale.spec.d.ts +0 -1
  239. package/lib-esm/core/explode-locale.spec.js +0 -39
  240. package/lib-esm/core/explode-locale.spec.js.map +0 -1
  241. package/lib-esm/core/germanic-plural.js +0 -4
  242. package/lib-esm/core/germanic-plural.js.map +0 -1
  243. package/lib-esm/core/gettext-impl.d.ts +0 -10
  244. package/lib-esm/core/gettext-impl.js +0 -34
  245. package/lib-esm/core/gettext-impl.js.map +0 -1
  246. package/lib-esm/core/gettext.spec.d.ts +0 -1
  247. package/lib-esm/core/gettext.spec.js +0 -389
  248. package/lib-esm/core/gettext.spec.js.map +0 -1
  249. package/lib-esm/core/index.js +0 -5
  250. package/lib-esm/core/index.js.map +0 -1
  251. package/lib-esm/core/locale-container.d.ts +0 -8
  252. package/lib-esm/core/locale-container.js +0 -2
  253. package/lib-esm/core/locale-container.js.map +0 -1
  254. package/lib-esm/core/path-separator.d.ts +0 -1
  255. package/lib-esm/core/path-separator.js +0 -8
  256. package/lib-esm/core/path-separator.js.map +0 -1
  257. package/lib-esm/core/resolve-impl.d.ts +0 -3
  258. package/lib-esm/core/resolve-impl.js +0 -249
  259. package/lib-esm/core/resolve-impl.js.map +0 -1
  260. package/lib-esm/core/resolve.spec.d.ts +0 -1
  261. package/lib-esm/core/resolve.spec.js +0 -340
  262. package/lib-esm/core/resolve.spec.js.map +0 -1
  263. package/lib-esm/core/select-locale.js +0 -39
  264. package/lib-esm/core/select-locale.js.map +0 -1
  265. package/lib-esm/core/select-locale.spec.d.ts +0 -1
  266. package/lib-esm/core/select-locale.spec.js +0 -25
  267. package/lib-esm/core/select-locale.spec.js.map +0 -1
  268. package/lib-esm/core/set-locale-browser.spec.d.ts +0 -1
  269. package/lib-esm/core/set-locale-browser.spec.js +0 -15
  270. package/lib-esm/core/set-locale-browser.spec.js.map +0 -1
  271. package/lib-esm/core/set-locale-node.spec.d.ts +0 -1
  272. package/lib-esm/core/set-locale-node.spec.js +0 -24
  273. package/lib-esm/core/set-locale-node.spec.js.map +0 -1
  274. package/lib-esm/core/split-locale.js +0 -35
  275. package/lib-esm/core/split-locale.js.map +0 -1
  276. package/lib-esm/core/split-locale.spec.d.ts +0 -1
  277. package/lib-esm/core/split-locale.spec.js +0 -57
  278. package/lib-esm/core/split-locale.spec.js.map +0 -1
  279. package/lib-esm/core/textdomain.d.ts +0 -55
  280. package/lib-esm/core/textdomain.js +0 -274
  281. package/lib-esm/core/textdomain.js.map +0 -1
  282. package/lib-esm/core/textdomain.spec.d.ts +0 -1
  283. package/lib-esm/core/textdomain.spec.js +0 -31
  284. package/lib-esm/core/textdomain.spec.js.map +0 -1
  285. package/lib-esm/core/user-locales.js +0 -8
  286. package/lib-esm/core/user-locales.js.map +0 -1
  287. package/lib-esm/index-browser.d.ts +0 -2
  288. package/lib-esm/index-browser.js +0 -26
  289. package/lib-esm/index-browser.js.map +0 -1
  290. package/lib-esm/index.d.ts +0 -2
  291. package/lib-esm/index.js +0 -19
  292. package/lib-esm/index.js.map +0 -1
  293. package/lib-esm/parser/index.d.ts +0 -2
  294. package/lib-esm/parser/index.js +0 -3
  295. package/lib-esm/parser/index.js.map +0 -1
  296. package/lib-esm/parser/parse-json-catalog.js +0 -32
  297. package/lib-esm/parser/parse-json-catalog.js.map +0 -1
  298. package/lib-esm/parser/parse-json-catalog.spec.d.ts +0 -1
  299. package/lib-esm/parser/parse-json-catalog.spec.js +0 -39
  300. package/lib-esm/parser/parse-json-catalog.spec.js.map +0 -1
  301. package/lib-esm/parser/parse-mo-catalog.js +0 -82
  302. package/lib-esm/parser/parse-mo-catalog.js.map +0 -1
  303. package/lib-esm/parser/parse-mo-catalog.spec.d.ts +0 -1
  304. package/lib-esm/parser/parse-mo-catalog.spec.js +0 -113
  305. package/lib-esm/parser/parse-mo-catalog.spec.js.map +0 -1
  306. package/lib-esm/transport/fs.js +0 -15
  307. package/lib-esm/transport/fs.js.map +0 -1
  308. package/lib-esm/transport/http.js +0 -24
  309. package/lib-esm/transport/http.js.map +0 -1
  310. package/lib-esm/transport/http.spec.d.ts +0 -1
  311. package/lib-esm/transport/http.spec.js +0 -114
  312. package/lib-esm/transport/http.spec.js.map +0 -1
  313. package/lib-esm/transport/index.d.ts +0 -3
  314. package/lib-esm/transport/index.js +0 -4
  315. package/lib-esm/transport/index.js.map +0 -1
  316. package/lib-esm/transport/transport.interface.d.ts +0 -3
  317. package/lib-esm/transport/transport.interface.js +0 -2
  318. package/lib-esm/transport/transport.interface.js.map +0 -1
  319. package/webpack.common.js +0 -38
  320. package/webpack.dev.js +0 -9
  321. package/webpack.prod.js +0 -8
@@ -0,0 +1,1406 @@
1
+ import { readFile } from 'fs';
2
+
3
+ let userLocalesSelected = ['C'];
4
+ /*
5
+ * Force an execution environment. By default, the environment (NodeJS or
6
+ * browser) is auto-detected. You can force the library to assume a certain
7
+ * environment with this function.
8
+ *
9
+ * @param browser - whether to assume a browser or not
10
+ * @returns the new setting.
11
+ */
12
+ function userLocales(locales) {
13
+ if (typeof locales !== 'undefined') {
14
+ userLocalesSelected = locales;
15
+ }
16
+ return userLocalesSelected;
17
+ }
18
+
19
+ /******************************************************************************
20
+ Copyright (c) Microsoft Corporation.
21
+
22
+ Permission to use, copy, modify, and/or distribute this software for any
23
+ purpose with or without fee is hereby granted.
24
+
25
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
26
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
27
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
28
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
29
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
30
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
31
+ PERFORMANCE OF THIS SOFTWARE.
32
+ ***************************************************************************** */
33
+ /* global Reflect, Promise, SuppressedError, Symbol */
34
+
35
+
36
+ function __awaiter(thisArg, _arguments, P, generator) {
37
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
38
+ return new (P || (P = Promise))(function (resolve, reject) {
39
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
40
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
41
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
42
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
43
+ });
44
+ }
45
+
46
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
47
+ var e = new Error(message);
48
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
49
+ };
50
+
51
+ /* eslint-disable @typescript-eslint/explicit-function-return-type */
52
+ class TransportHttp {
53
+ loadFile(url) {
54
+ return new Promise((resolve, reject) => {
55
+ const xhr = new XMLHttpRequest();
56
+ xhr.responseType = 'arraybuffer';
57
+ xhr.open('GET', url, true);
58
+ xhr.onload = () => {
59
+ if (xhr.readyState === 4 && xhr.status === 200) {
60
+ resolve(xhr.response);
61
+ }
62
+ else {
63
+ reject(new Error('get failed with status ' + xhr.status));
64
+ }
65
+ };
66
+ xhr.onerror = err => reject(err);
67
+ xhr.send();
68
+ });
69
+ }
70
+ }
71
+
72
+ class TransportFs {
73
+ loadFile(url) {
74
+ return new Promise((resolve, reject) => {
75
+ readFile(url, (err, data) => {
76
+ return err ? reject(err) : resolve(data);
77
+ });
78
+ });
79
+ }
80
+ }
81
+
82
+ /*
83
+ * Function for germanic plural. Returns singular (0) for 1 item, and
84
+ * 1 for everything else.
85
+ *
86
+ * @param numItems - number of items
87
+ * @returns the index into the plural translations
88
+ */
89
+ function germanicPlural(numItems) {
90
+ return numItems === 1 ? 0 : 1;
91
+ }
92
+
93
+ /*
94
+ * A minimalistic buffer implementation that can only read 32 bit unsigned
95
+ * integers and strings.
96
+ */
97
+ class DataViewlet {
98
+ /*
99
+ * Create a DataViewlet instance. All encodings that are supported by
100
+ * the runtime environments `TextDecoder` interface.
101
+ *
102
+ * @param array - a `Unit8Array` view on the binary buffer
103
+ * @param encoding - encoding of strings, defaults to utf-8
104
+ */
105
+ constructor(array, encoding = 'utf-8') {
106
+ this.array = array;
107
+ this.decoder = new TextDecoder(encoding);
108
+ this._encoding = encoding;
109
+ }
110
+ /**
111
+ * Get the encoding for strings.
112
+ *
113
+ * @returns the encoding in use
114
+ */
115
+ get encoding() {
116
+ return this._encoding;
117
+ }
118
+ /**
119
+ * Switch to a new encoding.
120
+ *
121
+ * @param encoding - new encoding to use
122
+ */
123
+ set encoding(encoding) {
124
+ this.decoder = new TextDecoder(encoding);
125
+ this._encoding = encoding;
126
+ }
127
+ /*
128
+ * Reads an unsigned 32-bit integer from the buffer at
129
+ * the specified offset as big-endian.
130
+ *
131
+ * @param offset - Number of bytes to skip before starting to read.
132
+ * Must satisfy `0 <= offset <= buf.length - 4`.
133
+ * Default: 0.
134
+ * @returns the 32-bit unsigned integer at position `offset`.s
135
+ */
136
+ readUInt32BE(offset = 0) {
137
+ if (offset + 4 > this.array.byteLength + this.array.byteOffset) {
138
+ throw new Error('read past array end');
139
+ }
140
+ return ((((this.array[offset] << 24) >>> 0) |
141
+ (this.array[offset + 1] << 16) |
142
+ (this.array[offset + 2] << 8) |
143
+ this.array[offset + 3]) >>>
144
+ 0);
145
+ }
146
+ /*
147
+ * Reads an unsigned 32-bit integer from the buffer at
148
+ * the specified offset as little-endian.
149
+ *
150
+ * @param offset - Number of bytes to skip before starting to read.
151
+ * Must satisfy `0 <= offset <= buf.length - 4`.
152
+ * Default: 0.
153
+ * @returns the 32-bit unsigned integer at position `offset`.s
154
+ */
155
+ readUInt32LE(offset = 0) {
156
+ if (offset + 4 > this.array.byteLength + this.array.byteOffset) {
157
+ throw new Error('read past array end');
158
+ }
159
+ return ((((this.array[offset + 3] << 24) >>> 0) |
160
+ (this.array[offset + 2] << 16) |
161
+ (this.array[offset + 1] << 8) |
162
+ this.array[offset]) >>>
163
+ 0);
164
+ }
165
+ /*
166
+ * Read a string at a specified offset.
167
+ *
168
+ * @param offset - to beginning of buffer in bytes
169
+ * @param length - of the string to read in bytes or to the end of the
170
+ * buffer if not specified.
171
+ */
172
+ readString(offset = 0, length) {
173
+ if (offset + length >
174
+ this.array.byteLength + this.array.byteOffset) {
175
+ throw new Error('read past array end');
176
+ }
177
+ if (typeof length === 'undefined') {
178
+ length = this.array.byteLength - offset;
179
+ }
180
+ return this.decoder.decode(this.array.slice(offset, offset + length));
181
+ }
182
+ }
183
+
184
+ /*
185
+ * Parse an MO file.
186
+ *
187
+ * An exception is thrown for invalid data.
188
+ *
189
+ * @param raw - The input as either a binary `String`, any `Array`-like byte
190
+ * storage (`Array`, `Uint8Array`, `Arguments`, `jQuery(Array)`, ...)
191
+ * @returns a Catalog
192
+ */
193
+ function parseMoCatalog(raw) {
194
+ const catalog = {
195
+ major: 0,
196
+ minor: 0,
197
+ entries: {},
198
+ pluralFunction: germanicPlural,
199
+ };
200
+ let offset = 0;
201
+ const blob = new DataViewlet(new Uint8Array(raw), 'ascii');
202
+ const magic = blob.readUInt32LE(offset);
203
+ let reader;
204
+ if (magic === 0x950412de) {
205
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
206
+ reader = (buf, off) => buf.readUInt32LE(off);
207
+ }
208
+ else if (magic === 0xde120495) {
209
+ /* eslint-disable-next-line @typescript-eslint/explicit-function-return-type */
210
+ reader = (buf, off) => buf.readUInt32BE(off);
211
+ }
212
+ else {
213
+ throw new Error(`invalid MO magic 0x${magic.toString(16)}`);
214
+ }
215
+ offset += 4;
216
+ // The revision is encoded in two shorts, major and minor. We don't care
217
+ // about the minor revision.
218
+ const major = reader(blob, offset) >> 16;
219
+ offset += 4;
220
+ if (major > 0) {
221
+ throw new Error(`unsupported major revision ${major}`);
222
+ }
223
+ const numStrings = reader(blob, offset);
224
+ offset += 4;
225
+ const msgidOffset = reader(blob, offset);
226
+ offset += 4;
227
+ const msgstrOffset = reader(blob, offset);
228
+ offset = msgidOffset;
229
+ const origTab = [];
230
+ for (let i = 0; i < numStrings; ++i) {
231
+ const l = reader(blob, offset);
232
+ offset += 4;
233
+ const stringOffset = reader(blob, offset);
234
+ offset += 4;
235
+ origTab.push([l, stringOffset]);
236
+ }
237
+ offset = msgstrOffset;
238
+ const transTab = [];
239
+ for (let i = 0; i < numStrings; ++i) {
240
+ const l = reader(blob, offset);
241
+ offset += 4;
242
+ const stringOffset = reader(blob, offset);
243
+ offset += 4;
244
+ transTab.push([l, stringOffset]);
245
+ }
246
+ const poHeader = {};
247
+ for (let i = 0; i < numStrings; ++i) {
248
+ const orig = origTab[i];
249
+ let l = orig[0];
250
+ offset = orig[1];
251
+ const msgid = blob.readString(offset, l).split('\u0000')[0];
252
+ const trans = transTab[i];
253
+ l = trans[0];
254
+ offset = trans[1];
255
+ const msgstr = blob.readString(offset, l).split('\u0000');
256
+ let pairs, kv;
257
+ if (i === 0 && msgid === '') {
258
+ pairs = msgstr[0].split('\n');
259
+ for (let j = 0; j < pairs.length; ++j) {
260
+ if (pairs[j] !== '') {
261
+ kv = pairs[j].split(/[ \t]*:[ \t]*/);
262
+ poHeader[kv[0].toLowerCase()] = kv[1];
263
+ }
264
+ }
265
+ if (poHeader['content-type'] !== undefined) {
266
+ const enc = poHeader['content-type'].replace(/.*=/, '');
267
+ if (enc !== poHeader['content-type']) {
268
+ blob.encoding = enc;
269
+ }
270
+ }
271
+ }
272
+ catalog.entries[msgid] = msgstr;
273
+ }
274
+ return catalog;
275
+ }
276
+
277
+ function validateMoJsonCatalog(udata) {
278
+ // We could use ajv but it results in almost 300 k minimized code
279
+ // for the browser bundle. This validator instead is absolutely
280
+ // minimalistic, and only avoids exceptions that can occur, when
281
+ // accessing entries.
282
+ if (udata === null || typeof udata === 'undefined') {
283
+ throw new Error('catalog is either null or undefined');
284
+ }
285
+ const data = udata;
286
+ if (data.constructor !== Object) {
287
+ throw new Error('catalog must be a dictionary');
288
+ }
289
+ // We don't care about major and minor because they are actually not
290
+ // used.
291
+ if (!Object.prototype.hasOwnProperty.call(data, 'entries')) {
292
+ throw new Error('catalog.entries does not exist');
293
+ }
294
+ const entries = data.entries;
295
+ if (entries === null || typeof entries === 'undefined') {
296
+ throw new Error('catalog.entries are not defined or null');
297
+ }
298
+ if (entries.constructor !== Object) {
299
+ throw new Error('catalog.entries must be a dictionary');
300
+ }
301
+ for (const [key, value] of Object.entries(entries)) {
302
+ if (!Array.isArray(value)) {
303
+ throw new Error(`catalog entry for key '${key}' is not an array`);
304
+ }
305
+ }
306
+ return data;
307
+ }
308
+ function parseMoJsonCatalog(json) {
309
+ const text = new TextDecoder().decode(json);
310
+ const data = JSON.parse(text);
311
+ return validateMoJsonCatalog(data);
312
+ }
313
+
314
+ function validateJsonCatalog(udata) {
315
+ // We could use ajv but it results in almost 300 k minimized code
316
+ // for the browser bundle. This validator instead is absolutely
317
+ // minimalistic, and only avoids exceptions that can occur, when
318
+ // accessing entries.
319
+ if (udata === null || typeof udata === 'undefined') {
320
+ throw new Error('catalog is either null or undefined');
321
+ }
322
+ const entries = udata;
323
+ if (entries.constructor !== Object) ;
324
+ // Convert to a regular catalog.
325
+ const catalog = {
326
+ major: 0,
327
+ minor: 1,
328
+ pluralFunction: () => 0,
329
+ entries: {},
330
+ };
331
+ for (const [msgid, msgstr] of Object.entries(entries)) {
332
+ // Just stringify all values but do not complain.
333
+ catalog.entries[msgid] = [msgstr.toString()];
334
+ }
335
+ return catalog;
336
+ }
337
+ function parseJsonCatalog(json) {
338
+ const text = new TextDecoder().decode(json);
339
+ const data = JSON.parse(text);
340
+ return validateJsonCatalog(data);
341
+ }
342
+
343
+ const tagHyphenRegex = new RegExp('^[a-z0-9]+(?:-[a-z0-9]+)*$', 'i');
344
+ const tagUnderscoreRegex = new RegExp('^[a-z0-9]+(?:_[a-z0-9]+)*$', 'i');
345
+ function splitLocale(locale) {
346
+ let charset = '', modifier = '';
347
+ const underscoreSeparator = locale.includes('_');
348
+ locale = locale.replace(/@([a-z]+)$/i, (_, match) => {
349
+ modifier = match;
350
+ return '';
351
+ });
352
+ locale = locale.replace(/\.([-0-9a-z]+)$/i, (_, match) => {
353
+ charset = match;
354
+ return '';
355
+ });
356
+ if (underscoreSeparator) {
357
+ if (!tagUnderscoreRegex.exec(locale)) {
358
+ return null;
359
+ }
360
+ }
361
+ else {
362
+ if (!tagHyphenRegex.exec(locale)) {
363
+ return null;
364
+ }
365
+ }
366
+ const separator = underscoreSeparator ? '_' : '-';
367
+ const tags = locale.split(separator);
368
+ const split = { tags: tags, underscoreSeparator };
369
+ if (charset.length) {
370
+ split.charset = charset;
371
+ }
372
+ if (modifier.length) {
373
+ split.modifier = modifier;
374
+ }
375
+ return split;
376
+ }
377
+
378
+ /*
379
+ * Caches catalog lookups by path, locale, and textdomain.
380
+ *
381
+ * Failed lookups are stored as null values.
382
+ *
383
+ * It is also possible to store a Promise. In that case, if a request is
384
+ * made to bind the textdomain, the promise is settled. Note that this
385
+ * mechanism is never used for message lookup but only for loading the
386
+ * catalog via resolve.
387
+ */
388
+ class CatalogCache {
389
+ constructor() {
390
+ /* Singleton. */
391
+ }
392
+ static getInstance() {
393
+ if (!CatalogCache.instance) {
394
+ CatalogCache.instance = new CatalogCache();
395
+ }
396
+ return CatalogCache.instance;
397
+ }
398
+ static clear() {
399
+ CatalogCache.cache = {};
400
+ }
401
+ /**
402
+ * Lookup a Catalog for a given base path, locale, and textdomain.
403
+ *
404
+ * The locale key is usually the locale identifier (e.g. de-DE or sr\@latin).
405
+ * But it can also be a colon separated list of such locale identifiers.
406
+ *
407
+ *
408
+ * @param localeKey - the locale key
409
+ * @param textdomain - the textdomain
410
+ * @returns the cached Catalog, a Promise or null for failure
411
+ */
412
+ static lookup(localeKey, textdomain) {
413
+ if (CatalogCache.cache[localeKey]) {
414
+ const ptr = CatalogCache.cache[localeKey];
415
+ if (Object.prototype.hasOwnProperty.call(ptr, textdomain)) {
416
+ return ptr[textdomain];
417
+ }
418
+ }
419
+ return null;
420
+ }
421
+ static store(localeKey, textdomain, entry) {
422
+ if (Promise.resolve(entry) !== entry) {
423
+ // Object.
424
+ entry = validateMoJsonCatalog(entry);
425
+ }
426
+ if (!CatalogCache.cache[localeKey]) {
427
+ CatalogCache.cache[localeKey] = {};
428
+ }
429
+ CatalogCache.cache[localeKey][textdomain] = entry;
430
+ }
431
+ }
432
+ CatalogCache.cache = {};
433
+
434
+ function explodeLocale(locale, vary) {
435
+ const retval = [];
436
+ const lsep = locale.underscoreSeparator ? '_' : '-';
437
+ let i = 0 ;
438
+ const hasCharset = typeof locale.charset !== 'undefined';
439
+ const hasModifier = typeof locale.modifier !== 'undefined';
440
+ const charsets = hasCharset ? [locale.charset] : [''];
441
+ if (hasCharset) {
442
+ const charset = locale.charset;
443
+ const ucCharset = charset.toUpperCase();
444
+ if (ucCharset !== charset) {
445
+ charsets.push(ucCharset);
446
+ }
447
+ charsets.push('');
448
+ }
449
+ for (; i < locale.tags.length; ++i) {
450
+ const lingua = locale.tags.slice(0, i + 1).join(lsep);
451
+ const ids = new Array();
452
+ charsets.forEach(charset => {
453
+ let id = charset.length ? lingua + '.' + charset : lingua;
454
+ if (hasModifier) {
455
+ id += '@' + locale.modifier;
456
+ }
457
+ ids.push(id);
458
+ });
459
+ retval.push(ids);
460
+ }
461
+ return retval;
462
+ }
463
+
464
+ function loadCatalog(url, format) {
465
+ return __awaiter(this, void 0, void 0, function* () {
466
+ let transportInstance;
467
+ {
468
+ let transport;
469
+ // Check whether this is a valid URL.
470
+ try {
471
+ const parsedURL = new URL(url);
472
+ if (parsedURL.protocol === 'https:' ||
473
+ parsedURL.protocol === 'http:' ||
474
+ parsedURL.protocol === 'file:') {
475
+ transport = 'http';
476
+ }
477
+ else {
478
+ throw new Error(`unsupported scheme ${parsedURL.protocol}`);
479
+ }
480
+ }
481
+ catch (e) {
482
+ {
483
+ transport = 'fs';
484
+ }
485
+ }
486
+ if (transport === 'http') {
487
+ transportInstance = new TransportHttp();
488
+ }
489
+ else {
490
+ transportInstance = new TransportFs();
491
+ }
492
+ }
493
+ let validator;
494
+ if ('mo.json' === format) {
495
+ validator = parseMoJsonCatalog;
496
+ }
497
+ else if ('.json' === format) {
498
+ validator = parseJsonCatalog;
499
+ }
500
+ else {
501
+ validator = parseMoCatalog;
502
+ }
503
+ try {
504
+ const data = yield transportInstance.loadFile(url);
505
+ return validator(data);
506
+ }
507
+ catch (_a) {
508
+ return null;
509
+ }
510
+ });
511
+ }
512
+ function assemblePath(base, id, domainname, extender) {
513
+ return `${base}/${id}/LC_MESSAGES/${domainname}.${extender}`;
514
+ }
515
+ function loadLanguageFromObject(ids, base, domainname) {
516
+ return __awaiter(this, void 0, void 0, function* () {
517
+ for (let i = 0; i < ids.length; ++i) {
518
+ const id = ids[i];
519
+ // Language exists?
520
+ if (!Object.prototype.hasOwnProperty.call(base, id)) {
521
+ continue;
522
+ }
523
+ // LC_MESSAGES?
524
+ if (!Object.prototype.hasOwnProperty.call(base[id], 'LC_MESSAGES')) {
525
+ continue;
526
+ }
527
+ // Textdomain?
528
+ if (!Object.prototype.hasOwnProperty.call(base[id].LC_MESSAGES, domainname)) {
529
+ continue;
530
+ }
531
+ return base[id].LC_MESSAGES[domainname];
532
+ }
533
+ return null;
534
+ });
535
+ }
536
+ /*
537
+ * First tries to load a catalog with the specified charset, then with the
538
+ * charset converted to uppercase (if it differs from the original charset),
539
+ * and finally without a charset.
540
+ */
541
+ function loadLanguage(ids, base, domainname, format) {
542
+ return __awaiter(this, void 0, void 0, function* () {
543
+ // Check if `base` is an object (LocaleContainer).
544
+ if (typeof base === 'object' && base !== null) {
545
+ return loadLanguageFromObject(ids, base, domainname);
546
+ }
547
+ for (const id of ids) {
548
+ const catalog = yield loadCatalog(assemblePath(base, id, domainname, format), format);
549
+ if (catalog) {
550
+ return catalog;
551
+ }
552
+ }
553
+ return null;
554
+ });
555
+ }
556
+ function loadDomain(exploded, localeKey, base, domainname, format) {
557
+ return __awaiter(this, void 0, void 0, function* () {
558
+ const entries = {};
559
+ const catalog = {
560
+ major: 0,
561
+ minor: 0,
562
+ pluralFunction: germanicPlural,
563
+ entries,
564
+ };
565
+ const cacheHit = yield CatalogCache.lookup(localeKey, domainname);
566
+ if (cacheHit !== null) {
567
+ return cacheHit;
568
+ }
569
+ for (const tries of exploded) {
570
+ const result = yield loadLanguage(tries, base, domainname, format);
571
+ if (result) {
572
+ catalog.major = result.major;
573
+ catalog.minor = result.minor;
574
+ catalog.entries = Object.assign(Object.assign({}, catalog.entries), result.entries);
575
+ }
576
+ }
577
+ return catalog;
578
+ });
579
+ }
580
+ function pluralExpression(str) {
581
+ const tokens = str
582
+ .replace(/[ \t\r\013\014]/g, '')
583
+ .replace(/;$/, '')
584
+ // Do NOT allow square brackets here. JSFuck!
585
+ .split(/[<>!=]=|&&|\|\||[-!*/%+<>=?:;]/);
586
+ for (let i = 0; i < tokens.length; ++i) {
587
+ const token = tokens[i].replace(/^\(+/, '').replace(/\)+$/, '');
588
+ if (token !== 'nplurals' &&
589
+ token !== 'plural' &&
590
+ token !== 'n' &&
591
+ // Does not catch invalid octal numbers but the compiler
592
+ // takes care of that.
593
+ null === /^[0-9]+$/.exec(token)) {
594
+ throw new Error('invalid plural function');
595
+ }
596
+ }
597
+ const code = 'var nplurals = 1, plural = 0;' + str + '; return 0 + plural';
598
+ // This may throw an exception!
599
+ // eslint-disable-next-line @typescript-eslint/no-implied-eval
600
+ return new Function('n', code);
601
+ }
602
+ function setPluralFunction(catalog) {
603
+ if (!Object.prototype.hasOwnProperty.call(catalog.entries, '')) {
604
+ return catalog;
605
+ }
606
+ const headers = catalog.entries[''][0].split('\n');
607
+ headers.forEach(header => {
608
+ const tokens = header.split(':');
609
+ if ('plural-forms' === tokens.shift().toLowerCase()) {
610
+ const code = tokens.join(':');
611
+ try {
612
+ catalog.pluralFunction = pluralExpression(code);
613
+ }
614
+ catch (_a) {
615
+ catalog.pluralFunction = germanicPlural;
616
+ }
617
+ }
618
+ });
619
+ return catalog;
620
+ }
621
+ function resolveImpl(domainname, path, format, localeKey) {
622
+ return __awaiter(this, void 0, void 0, function* () {
623
+ const defaultCatalog = {
624
+ major: 0,
625
+ minor: 0,
626
+ pluralFunction: germanicPlural,
627
+ entries: {},
628
+ };
629
+ if (localeKey === 'C' || localeKey === 'POSIX') {
630
+ return defaultCatalog;
631
+ }
632
+ const exploded = explodeLocale(splitLocale(localeKey));
633
+ const catalog = yield loadDomain(exploded, localeKey, path, domainname, format);
634
+ setPluralFunction(catalog);
635
+ CatalogCache.store(localeKey, domainname, catalog);
636
+ return catalog;
637
+ });
638
+ }
639
+
640
+ function gettextImpl(args) {
641
+ var _a;
642
+ const key = typeof args.msgctxt === 'undefined'
643
+ ? args.msgid
644
+ : args.msgctxt + '\u0004' + args.msgid;
645
+ const translations = args.catalog.entries[key];
646
+ const numItems = (_a = args.numItems) !== null && _a !== void 0 ? _a : 1;
647
+ if (translations && translations.length) {
648
+ if (typeof args.msgidPlural === 'undefined') {
649
+ return translations[0];
650
+ }
651
+ else {
652
+ let pluralForm = args.catalog.pluralFunction(numItems);
653
+ if (pluralForm >= translations.length) {
654
+ if (translations.length === 1) {
655
+ return translations[0];
656
+ }
657
+ else {
658
+ pluralForm = germanicPlural(numItems);
659
+ }
660
+ }
661
+ return translations[pluralForm];
662
+ }
663
+ }
664
+ else if (typeof args.msgidPlural !== 'undefined') {
665
+ const pluralform = args.catalog.pluralFunction(numItems);
666
+ if (pluralform === 1) {
667
+ return args.msgidPlural;
668
+ }
669
+ }
670
+ return args.msgid;
671
+ }
672
+
673
+ const isNode = typeof process !== 'undefined' &&
674
+ process.versions !== null &&
675
+ process.versions.node !== null;
676
+ const pathSeparator = isNode && process.platform === 'win32' ? '\\' : '/';
677
+
678
+ function tagsEqual(left, right) {
679
+ if (left.length !== right.length) {
680
+ return false;
681
+ }
682
+ for (let i = 0; i < left.length; ++i) {
683
+ if (left[i].toLowerCase() !== right[i].toLowerCase()) {
684
+ return false;
685
+ }
686
+ }
687
+ return true;
688
+ }
689
+ function selectLocale(supported, requested) {
690
+ let languageMatch = '';
691
+ for (let i = 0; i < requested.length; ++i) {
692
+ const wanted = splitLocale(requested[i]);
693
+ if (!wanted) {
694
+ continue;
695
+ }
696
+ for (let j = 0; j < supported.length; ++j) {
697
+ const got = splitLocale(supported[j]);
698
+ if (!got) {
699
+ continue;
700
+ }
701
+ if (tagsEqual(wanted.tags, got.tags)) {
702
+ return supported[j];
703
+ }
704
+ if (!languageMatch.length &&
705
+ wanted.tags[0].toLowerCase() === got.tags[0].toLowerCase()) {
706
+ languageMatch = supported[j];
707
+ }
708
+ }
709
+ }
710
+ if (languageMatch.length) {
711
+ return languageMatch;
712
+ }
713
+ return 'C';
714
+ }
715
+
716
+ /**
717
+ * A Textdomain is a container for an esgettext configuration and all loaded
718
+ * LocaleContainer for the textual domain selected.
719
+ *
720
+ * The actual translation methods have quite funny names like `_()` or
721
+ * `_x()`. The purpose of this naming convention is to make the
722
+ * internationalization of your programs as little obtrusive as possible.
723
+ * Most of the times you just have to exchange
724
+ *
725
+ * ```
726
+ * doSomething('Hello, world!');
727
+ * ```
728
+ *
729
+ * with
730
+ *
731
+ * ```
732
+ * doSomething(gtx._('Hello, world!'));
733
+ * ```
734
+ *
735
+ * Besides, depending on the string extractor you are using, it may be useful
736
+ * that the method names do not collide with method names from other packages.
737
+ */
738
+ class Textdomain {
739
+ /**
740
+ * Retrieve a translation for a string.
741
+ *
742
+ * @param msgid - the string to translate
743
+ *
744
+ * @returns the translated string
745
+ */
746
+ _(msgid) {
747
+ return gettextImpl({ msgid: msgid, catalog: this.catalog });
748
+ }
749
+ /**
750
+ * Retrieve a translation for a string containing a possible plural.
751
+ * You will almost always want to call {@link _nx} instead so that
752
+ * you can interpolate the number of items into the strings.
753
+ *
754
+ * @param msgid - the string in the singular
755
+ * @param msgidPlural - the string in the plural
756
+ * @param numItems - the number of items
757
+ *
758
+ * @returns the translated string
759
+ */
760
+ _n(msgid, msgidPlural, numItems) {
761
+ return gettextImpl({
762
+ msgid: msgid,
763
+ msgidPlural: msgidPlural,
764
+ numItems: numItems,
765
+ catalog: this.catalog,
766
+ });
767
+ }
768
+ /**
769
+ * Translate a string with a context.
770
+ *
771
+ * @param msgctxt - the message context
772
+ * @param msgid - the string to translate
773
+ *
774
+ * @returns the translated string
775
+ */
776
+ _p(msgctxt, msgid) {
777
+ return gettextImpl({
778
+ msgctxt: msgctxt,
779
+ msgid: msgid,
780
+ catalog: this.catalog,
781
+ });
782
+ }
783
+ /**
784
+ * The method `_np()` combines `_n()` with `_p()`.
785
+ * You will almost always want to call {@link _npx} instead so that
786
+ * you can interpolate the number of items into the strings.
787
+
788
+ *
789
+ * @param msgctxt - the message context
790
+ * @param msgid - the message id
791
+ * @param placeholders - a dictionary with placehoders
792
+ * @returns the translated string
793
+ */
794
+ _np(msgctxt, msgid, msgidPlural, numItems) {
795
+ return gettextImpl({
796
+ msgctxt: msgctxt,
797
+ msgid: msgid,
798
+ msgidPlural: msgidPlural,
799
+ numItems: numItems,
800
+ catalog: this.catalog,
801
+ });
802
+ }
803
+ /**
804
+ * Translate a string with placeholders. The placeholders should be
805
+ * wrapped into curly braces and must match the regular expression
806
+ * "[_a-zA-Z][_a-zA-Z0-9]*".
807
+ *
808
+ * @param msgid - the msgid to translate
809
+ * @param placeholders - an optional dictionary of placeholders
810
+ *
811
+ * @returns the translated string with placeholders expanded
812
+ */
813
+ _x(msgid, placeholders) {
814
+ return Textdomain.expand(gettextImpl({ msgid: msgid, catalog: this.catalog }), placeholders || {});
815
+ }
816
+ /**
817
+ * Translate a string with a plural expression with placeholders.
818
+ *
819
+ * @param msgid - the string in the singular
820
+ * @param msgidPlural - the string in the plural
821
+ * @param numItems - the number of items
822
+ * @param placeholders - an optional dictionary of placeholders
823
+ *
824
+ * @returns the translated string
825
+ */
826
+ _nx(msgid, msgidPlural, numItems, placeholders) {
827
+ return Textdomain.expand(gettextImpl({
828
+ msgid: msgid,
829
+ msgidPlural: msgidPlural,
830
+ numItems: numItems,
831
+ catalog: this.catalog,
832
+ }), placeholders || {});
833
+ }
834
+ /**
835
+ * The method `_px()` combines `_p()` with `_x()`.
836
+ *
837
+ * @param msgctxt - the message context
838
+ * @param msgid - the message id
839
+ * @param placeholders - an optional dictionary with placehoders
840
+ * @returns the translated string
841
+ */
842
+ _px(msgctxt, msgid, placeholders) {
843
+ return Textdomain.expand(gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: this.catalog }), placeholders || {});
844
+ }
845
+ /**
846
+ * The method `_npx()` brings it all together. It combines `_n()` and
847
+ * `_p()` and `_x()`.
848
+ *
849
+ * @param msgctxt - the message context
850
+ * @param msgid - the message id
851
+ * @param msgidPlural - the plural string
852
+ * @param numItems - the number of items
853
+ * @param placeholders - an optional dictionary with placehoders
854
+ * @returns the translated string
855
+ */
856
+ _npx(msgctxt, msgid, msgidPlural, numItems, placeholders) {
857
+ return Textdomain.expand(gettextImpl({
858
+ msgctxt: msgctxt,
859
+ msgid: msgid,
860
+ msgidPlural: msgidPlural,
861
+ numItems: numItems,
862
+ catalog: this.catalog,
863
+ }), placeholders || {});
864
+ }
865
+ static getCatalog(locale, textdomain) {
866
+ const catalog = CatalogCache.lookup(locale, textdomain);
867
+ if (!catalog || Promise.resolve(catalog) === catalog) {
868
+ return {
869
+ major: 0,
870
+ minor: 0,
871
+ pluralFunction: germanicPlural,
872
+ entries: {},
873
+ };
874
+ }
875
+ return catalog;
876
+ }
877
+ /**
878
+ * Retrieve a translation for a string with a fixed locale.
879
+ *
880
+ * @param locale - the locale identifier
881
+ * @param msgid - the string to translate
882
+ *
883
+ * @returns the translated string
884
+ */
885
+ _l(locale, msgid) {
886
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
887
+ return gettextImpl({ msgid: msgid, catalog: catalog });
888
+ }
889
+ /**
890
+ * Retrieve a translation for a string containing a possible plural with
891
+ * a fixed locale.
892
+ * You will almost always want to call {@link _nx} instead so that
893
+ * you can interpolate the number of items into the strings.
894
+ *
895
+ * @param locale - the locale identifier
896
+ * @param msgid - the string in the singular
897
+ * @param msgidPlural - the string in the plural
898
+ * @param numItems - the number of items
899
+ *
900
+ * @returns the translated string
901
+ */
902
+ _ln(locale, msgid, msgidPlural, numItems) {
903
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
904
+ return gettextImpl({
905
+ msgid: msgid,
906
+ msgidPlural: msgidPlural,
907
+ numItems: numItems,
908
+ catalog: catalog,
909
+ });
910
+ }
911
+ /**
912
+ * Translate a string with a context with a fixed locale.
913
+ *
914
+ * @param locale - the locale identifier
915
+ * @param msgctxt - the message context
916
+ * @param msgid - the string to translate
917
+ *
918
+ * @returns the translated string
919
+ */
920
+ _lp(locale, msgctxt, msgid) {
921
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
922
+ return gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: catalog });
923
+ }
924
+ /**
925
+ * The method `_lnp()` combines `_ln()` with `_lp()`.
926
+ * You will almost always want to call {@link _npx} instead so that
927
+ * you can interpolate the number of items into the strings.
928
+
929
+ *
930
+ * @param locale - the locale identifier
931
+ * @param msgctxt - the message context
932
+ * @param msgid - the message id
933
+ * @param placeholders - a dictionary with placehoders
934
+ * @returns the translated string
935
+ */
936
+ _lnp(locale, msgctxt, msgid, msgidPlural, numItems) {
937
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
938
+ return gettextImpl({
939
+ msgctxt: msgctxt,
940
+ msgid: msgid,
941
+ msgidPlural: msgidPlural,
942
+ numItems: numItems,
943
+ catalog: catalog,
944
+ });
945
+ }
946
+ /**
947
+ * Translate a string with placeholders for a fixed locale.
948
+ * The placeholders should be
949
+ * wrapped into curly braces and must match the regular expression
950
+ * "[_a-zA-Z][_a-zA-Z0-9]*".
951
+ *
952
+ * @param locale - the locale identifier
953
+ * @param msgid - the msgid to translate
954
+ * @param placeholders - an optional dictionary of placeholders
955
+ *
956
+ * @returns the translated string with placeholders expanded
957
+ */
958
+ _lx(locale, msgid, placeholders) {
959
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
960
+ return Textdomain.expand(gettextImpl({ msgid: msgid, catalog: catalog }), placeholders || {});
961
+ }
962
+ /**
963
+ * Translate a string with a plural expression with placeholders into a
964
+ * fixed locale.
965
+ *
966
+ * @param locale - the locale identifier
967
+ * @param msgid - the string in the singular
968
+ * @param msgidPlural - the string in the plural
969
+ * @param numItems - the number of items
970
+ * @param placeholders - an optional dictionary of placeholders
971
+ *
972
+ * @returns the translated string
973
+ */
974
+ _lnx(locale, msgid, msgidPlural, numItems, placeholders) {
975
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
976
+ return Textdomain.expand(gettextImpl({
977
+ msgid: msgid,
978
+ msgidPlural: msgidPlural,
979
+ numItems: numItems,
980
+ catalog: catalog,
981
+ }), placeholders || {});
982
+ }
983
+ /**
984
+ * The method `_lpx()` combines `_lp()` with `_lx()`.
985
+ *
986
+ * @param locale - the locale identifier
987
+ * @param msgctxt - the message context
988
+ * @param msgid - the message id
989
+ * @param placeholders - an optional dictionary with placehoders
990
+ * @returns the translated string
991
+ */
992
+ _lpx(locale, msgctxt, msgid, placeholders) {
993
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
994
+ return Textdomain.expand(gettextImpl({ msgctxt: msgctxt, msgid: msgid, catalog: catalog }), placeholders || {});
995
+ }
996
+ /**
997
+ * The method `_lnpx()` brings it all together. It combines `_ln()` and
998
+ * `_lp()` and `_lx()`.
999
+ *
1000
+ * @param locale - the locale identifier
1001
+ * @param msgctxt - the message context
1002
+ * @param msgid - the message id
1003
+ * @param msgidPlural - the plural string
1004
+ * @param numItems - the number of items
1005
+ * @param placeholders - an optional dictionary with placehoders
1006
+ * @returns the translated string
1007
+ */
1008
+ _lnpx(locale, msgctxt, msgid, msgidPlural, numItems, placeholders) {
1009
+ const catalog = Textdomain.getCatalog(locale, this.textdomain());
1010
+ return Textdomain.expand(gettextImpl({
1011
+ msgctxt: msgctxt,
1012
+ msgid: msgid,
1013
+ msgidPlural: msgidPlural,
1014
+ numItems: numItems,
1015
+ catalog: catalog,
1016
+ }), placeholders || {});
1017
+ }
1018
+ static expand(msg, placeholders) {
1019
+ return msg.replace(/\{([a-zA-Z][0-9a-zA-Z]*)\}/g, (_, match) => {
1020
+ if (Object.prototype.hasOwnProperty.call(placeholders, match)) {
1021
+ return placeholders[match];
1022
+ }
1023
+ else {
1024
+ return `{${match}}`;
1025
+ }
1026
+ });
1027
+ }
1028
+ /**
1029
+ * Instantiate a Textdomain object. Textdomain objects are singletons
1030
+ * for each textdomain identifier.
1031
+ *
1032
+ * @param textdomain - the textdomain of your application or library.
1033
+ *
1034
+ * @returns a [[`Textdomain`]]
1035
+ */
1036
+ static getInstance(textdomain) {
1037
+ if (typeof textdomain === 'undefined' ||
1038
+ textdomain === null ||
1039
+ textdomain === '') {
1040
+ throw new Error('Cannot instantiate TextDomain without a textdomain');
1041
+ }
1042
+ if (Object.prototype.hasOwnProperty.call(Textdomain.domains, textdomain)) {
1043
+ return Textdomain.domains[textdomain];
1044
+ }
1045
+ else {
1046
+ const domain = new Textdomain(textdomain);
1047
+ Textdomain.domains[textdomain] = domain;
1048
+ domain.catalog = {
1049
+ major: 0,
1050
+ minor: 0,
1051
+ pluralFunction: germanicPlural,
1052
+ entries: {},
1053
+ };
1054
+ return domain;
1055
+ }
1056
+ }
1057
+ /**
1058
+ * Delete all existing singletons. This method should usually be called
1059
+ * only, when you want to free memory.
1060
+ */
1061
+ static clearInstances() {
1062
+ Textdomain.boundDomains = {};
1063
+ }
1064
+ /**
1065
+ * This method is used for testing. Do not use it yourself!
1066
+ */
1067
+ static forgetInstances() {
1068
+ Textdomain.clearInstances();
1069
+ Textdomain.domains = {};
1070
+ }
1071
+ /**
1072
+ * Query the locale in use.
1073
+ */
1074
+ static get locale() {
1075
+ return Textdomain._locale;
1076
+ }
1077
+ /**
1078
+ * Change the locale.
1079
+ *
1080
+ * For the web you can use all valid language identifier tags that
1081
+ * [BCP47](https://tools.ietf.org/html/bcp47) allows
1082
+ * (and actually a lot more). The tag is always used unmodified.
1083
+ *
1084
+ * For server environments, the locale identifier has to match the following
1085
+ * scheme:
1086
+ *
1087
+ * `ll_CC.charset\@modifier`
1088
+ *
1089
+ * * `ll` is the two- or three-letter language code.
1090
+ * * `CC` is the optional two-letter country code.
1091
+ * * `charset` is an optional character set (letters, digits, and the hyphen).
1092
+ * * `modifier` is an optional variant (letters and digits).
1093
+ *
1094
+ * The language code is always converted to lowercase, the country code is
1095
+ * converted to uppercase, variant and charset are used as is.
1096
+ *
1097
+ * @param locale - the locale identifier
1098
+ * @returns the locale in use
1099
+ */
1100
+ static set locale(locale) {
1101
+ const ucLocale = locale.toUpperCase();
1102
+ if (ucLocale === 'POSIX' || ucLocale === 'C') {
1103
+ this._locale = 'POSIX';
1104
+ return;
1105
+ }
1106
+ const split = splitLocale(locale);
1107
+ if (!split) {
1108
+ throw new Error('invalid locale identifier');
1109
+ }
1110
+ // Node.
1111
+ split.tags[0] = split.tags[0].toLowerCase();
1112
+ if (split.tags.length > 1) {
1113
+ split.tags[1] = split.tags[1].toUpperCase();
1114
+ }
1115
+ const separator = split.underscoreSeparator ? '_' : '-';
1116
+ this._locale = split.tags.join(separator);
1117
+ if (typeof split.charset !== 'undefined') {
1118
+ this._locale += '.' + split.charset;
1119
+ }
1120
+ if (typeof split.modifier !== 'undefined') {
1121
+ this._locale += '@' + split.modifier;
1122
+ }
1123
+ }
1124
+ constructor(domain) {
1125
+ this._catalogFormat = 'mo.json';
1126
+ this.catalog = undefined;
1127
+ this.domain = domain;
1128
+ const msg = "The property 'locale' is not an instance property but static. Use 'Textdomain.locale' instead!";
1129
+ Object.defineProperty(this, 'locale', {
1130
+ get: () => {
1131
+ throw new Error(msg);
1132
+ },
1133
+ set: () => {
1134
+ throw new Error(msg);
1135
+ },
1136
+ enumerable: true,
1137
+ configurable: true,
1138
+ });
1139
+ }
1140
+ /**
1141
+ * A textdomain is an identifier for your application or library. It is
1142
+ * the basename of your translation files which are either
1143
+ * TEXTDOMAIN.mo.json or TEXTDOMAIN.mo, depending on the format you have
1144
+ * chosen.
1145
+ *
1146
+ * FIXME! This should be a getter!
1147
+ *
1148
+ * @returns the textdomain
1149
+ */
1150
+ textdomain() {
1151
+ return this.domain;
1152
+ }
1153
+ /**
1154
+ * Bind a textdomain to a certain path or queries the path that a
1155
+ * textdomain is bound to. The catalog file will be searched
1156
+ * in `${path}/LC_MESSAGES/${domainname}.EXT` where `EXT` is the
1157
+ * selected catalog format (one of `mo.json`, `mo`, or `json`).
1158
+ *
1159
+ * Alternatively, you can pass a [[`LocaleContainer`]] that holds the
1160
+ * catalogs in memory.
1161
+ *
1162
+ * The returned string or `LocaleContainer` is valid until the next
1163
+ * `bindtextdomain` call with an argument.
1164
+ *
1165
+ * @param path - the base path or [[`LocaleContainer`]] for this textdomain
1166
+ *
1167
+ * @returns the current base directory or [[`LocaleContainer`]] for this domain, after possibly changing it.
1168
+ */
1169
+ bindtextdomain(path) {
1170
+ if (typeof path !== 'undefined') {
1171
+ Textdomain.boundDomains[this.domain] = path;
1172
+ }
1173
+ return Textdomain.boundDomains[this.domain];
1174
+ }
1175
+ /**
1176
+ * Resolve a textdomain, i.e. load the LocaleContainer for this domain and all
1177
+ * of its dependencies for the currently selected locale or the locale
1178
+ * specified.
1179
+ *
1180
+ * The promise will always resolve. If no catalog was found, an empty
1181
+ * catalog will be returned that is still usable.
1182
+ *
1183
+ * @param locale - an optional locale identifier, defaults to Textdomain.locale
1184
+ *
1185
+ * @returns a promise for a Catalog that will always resolve.
1186
+ */
1187
+ resolve(locale) {
1188
+ return __awaiter(this, void 0, void 0, function* () {
1189
+ const promises = [this.resolve1(locale)];
1190
+ for (const td in Textdomain.domains) {
1191
+ if (Object.prototype.hasOwnProperty.call(Textdomain.domains, td) &&
1192
+ Textdomain.domains[td] !== this) {
1193
+ promises.push(Textdomain.domains[td].resolve1(locale));
1194
+ }
1195
+ }
1196
+ return Promise.all(promises).then(values => {
1197
+ return new Promise(resolve => resolve(values[0]));
1198
+ });
1199
+ });
1200
+ }
1201
+ resolve1(locale) {
1202
+ return __awaiter(this, void 0, void 0, function* () {
1203
+ let path = this.bindtextdomain();
1204
+ if (typeof path === 'undefined' || path === null) {
1205
+ const parts = ['.', 'locale'];
1206
+ path = parts.join(pathSeparator);
1207
+ }
1208
+ const resolvedLocale = locale ? locale : Textdomain.locale;
1209
+ return resolveImpl(this.domain, path, this.catalogFormat, resolvedLocale).then(catalog => {
1210
+ if (!locale) {
1211
+ this.catalog = catalog;
1212
+ }
1213
+ return new Promise(resolve => resolve(catalog));
1214
+ });
1215
+ });
1216
+ }
1217
+ /**
1218
+ * Get the catalog format in use.
1219
+ *
1220
+ * @returns one of 'mo.json' or 'mo' (default is 'mo.json')
1221
+ */
1222
+ get catalogFormat() {
1223
+ return this._catalogFormat;
1224
+ }
1225
+ /**
1226
+ * Set the catalog format to use.
1227
+ *
1228
+ * @param format - one of 'mo.json' or 'mo'
1229
+ */
1230
+ set catalogFormat(format) {
1231
+ format = format.toLowerCase();
1232
+ if (format === 'mo.json') {
1233
+ this._catalogFormat = 'mo.json';
1234
+ }
1235
+ else if (format === 'mo') {
1236
+ this._catalogFormat = 'mo';
1237
+ }
1238
+ else {
1239
+ throw new Error(`unsupported format ${format}`);
1240
+ }
1241
+ }
1242
+ /**
1243
+ * Queries the user's preferred locales. On the server it queries the
1244
+ * environment variables `LANGUAGE`, `LC_ALL`, `LANG`, and `LC_MESSAGES`
1245
+ * (in that order). In the browser, it parses it checks the user preferences
1246
+ * in the variables `navigator.languages`, `navigator.language`,
1247
+ * `navigator.userLanguage`, `navigator.browserLanguage`, and
1248
+ * `navigator.systemLanguage`.
1249
+ *
1250
+ * @returns the set of locales in order of preference
1251
+ *
1252
+ * Added in \@runtime 0.1.0.
1253
+ */
1254
+ static userLocales() {
1255
+ return userLocales();
1256
+ }
1257
+ /**
1258
+ * Select one of the supported locales from a list of locales accepted by
1259
+ * the user.
1260
+ *
1261
+ * @param supported - the list of locales supported by the application
1262
+ * @param requested - the list of locales accepted by the user
1263
+ *
1264
+ * If called with just one argument, then the list of requested locales
1265
+ * is determined by calling [[Textdomain.userLocales]].
1266
+ *
1267
+ * @returns the negotiated locale or 'C' if not possible.
1268
+ */
1269
+ static selectLocale(supported, requested) {
1270
+ return selectLocale(supported, requested !== null && requested !== void 0 ? requested : Textdomain.userLocales());
1271
+ }
1272
+ /**
1273
+ * A no-op method for string marking.
1274
+ *
1275
+ * Sometimes you want to mark strings for translation but do not actually
1276
+ * want to translate them, at least not at the time of their definition.
1277
+ * This is often the case, when you have to preserve the original string.
1278
+ *
1279
+ * Take this example:
1280
+ *
1281
+ * ```
1282
+ * orangeColors = [gtx.N_('coral'), gtx.N_('tomato'), gtx.N_('orangered'),
1283
+ * gtx.N_('gold'), gtx.N_('orange'), gtx.N_('darkorange')]
1284
+ * ```
1285
+ *
1286
+ * These are standard CSS colors, and you cannot translate them inside
1287
+ * CSS styles. But for presentation you may want to translate them later:
1288
+ *
1289
+ * ```
1290
+ * console.log(gtx._x("The css color '{color}' is {translated}.",
1291
+ * {
1292
+ * color: orangeColors[2],
1293
+ * translated: gtx._(orangeColors[2]),
1294
+ * }
1295
+ * )
1296
+ * );
1297
+ * ```
1298
+ *
1299
+ * In other words: The method just marks strings for translation, so that
1300
+ * the extractor `esgettext-xgettext` finds them but it does not actually
1301
+ * translate anything.
1302
+ *
1303
+ * Similar methods are available for other cases (with placeholder
1304
+ * expansion, context, or both). They are *not* available for plural
1305
+ * methods because that would not make sense.
1306
+ *
1307
+ * Note that all of these methods are also available as instance methods.
1308
+ *
1309
+ * @param msgid - the message id
1310
+ * @returns the original string
1311
+ */
1312
+ static N_(msgid) {
1313
+ return msgid;
1314
+ }
1315
+ /**
1316
+ * Does the same as the static method `N_()`.
1317
+ *
1318
+ * @param msgid - the message id
1319
+ * @returns the original string
1320
+ */
1321
+ N_(msgid) {
1322
+ return msgid;
1323
+ }
1324
+ /**
1325
+ * Same as `N_()` but with placeholder expansion.
1326
+ *
1327
+ * @param msgid - the message id
1328
+ * @param placeholders - a dictionary of placeholders
1329
+ * @returns the original string with placeholders expanded
1330
+ */
1331
+ N_x(msgid, placeholders) {
1332
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1333
+ }
1334
+ /**
1335
+ * Does the same as the static method `N_x()`.
1336
+ *
1337
+ * @param msgid - the message id
1338
+ * @param placeholders - a dictionary of placeholders
1339
+ * @returns the original string with placeholders expanded
1340
+ */
1341
+ static N_x(msgid, placeholders) {
1342
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1343
+ }
1344
+ /**
1345
+ * Same as `N_()` but with context.
1346
+ *
1347
+ * @param _msgctxt - the message context (not used)
1348
+ * @param msgid - the message id
1349
+ * @returns the original string
1350
+ */
1351
+ N_p(_msgctxt, msgid) {
1352
+ return msgid;
1353
+ }
1354
+ /**
1355
+ * Does the same as the static method `N_p()`.
1356
+ *
1357
+ * @param _msgctxt - the message context (not used)
1358
+ * @param msgid - the message id
1359
+ * @returns the original string with placeholders expanded
1360
+ */
1361
+ static N_p(_msgctxt, msgid) {
1362
+ return msgid;
1363
+ }
1364
+ /**
1365
+ * Same as `N_()` but with context and placeholder expansion.
1366
+ *
1367
+ * @param _msgctxt - the message context (not used)
1368
+ * @param msgid - the message id
1369
+ * @param placeholders - a dictionary of placeholders
1370
+ * @returns the original string with placeholders expanded
1371
+ */
1372
+ N_px(_msgctxt, msgid, placeholders) {
1373
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1374
+ }
1375
+ /**
1376
+ * Does the same as the static method `N_px()`.
1377
+ *
1378
+ * @param _msgctxt - the message context (not used)
1379
+ * @param msgid - the message id
1380
+ * @param placeholders - a dictionary of placeholders
1381
+ * @returns the original string with placeholders expanded
1382
+ */
1383
+ static N_px(_msgctxt, msgid, placeholders) {
1384
+ return Textdomain.expand(msgid, placeholders !== null && placeholders !== void 0 ? placeholders : {});
1385
+ }
1386
+ }
1387
+ Textdomain.domains = {};
1388
+ Textdomain.boundDomains = {};
1389
+ Textdomain._locale = 'C';
1390
+
1391
+ // FIXME! Windows!
1392
+ if (typeof process.env.LANGUAGE !== 'undefined') {
1393
+ userLocales(process.env.LANGUAGE.split(':'));
1394
+ }
1395
+ else if (typeof process.env.LC_ALL !== 'undefined') {
1396
+ userLocales([process.env.LC_ALL]);
1397
+ }
1398
+ else if (typeof process.env.LANG !== 'undefined') {
1399
+ userLocales([process.env.LANG]);
1400
+ }
1401
+ else if (typeof process.env.LC_MESSAGES !== 'undefined') {
1402
+ userLocales([process.env.LC_MESSAGES]);
1403
+ }
1404
+
1405
+ export { CatalogCache, Textdomain, parseMoCatalog, parseMoJsonCatalog };
1406
+ //# sourceMappingURL=esgettext.esm.js.map