@lattice-php/lattice 0.1.0 → 0.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 (367) hide show
  1. package/dist/_virtual/_rolldown/runtime.js +8 -0
  2. package/dist/action/components/action-form.d.ts +24 -0
  3. package/dist/action/components/action-form.js +270 -0
  4. package/dist/action/components/action-form.js.map +1 -0
  5. package/dist/action/components/action-group.d.ts +1 -8
  6. package/dist/action/components/action-group.js +24 -66
  7. package/dist/action/components/action-group.js.map +1 -1
  8. package/dist/action/components/action.d.ts +1 -24
  9. package/dist/action/components/action.js +61 -46
  10. package/dist/action/components/action.js.map +1 -1
  11. package/dist/action/effects.d.ts +6 -25
  12. package/dist/action/effects.js +2 -2
  13. package/dist/action/effects.js.map +1 -1
  14. package/dist/action/index.d.ts +1 -1
  15. package/dist/core/components/badge.d.ts +1 -8
  16. package/dist/core/components/badge.js +2 -3
  17. package/dist/core/components/badge.js.map +1 -1
  18. package/dist/core/components/button.d.ts +4 -12
  19. package/dist/core/components/button.js +6 -9
  20. package/dist/core/components/button.js.map +1 -1
  21. package/dist/core/components/card.d.ts +1 -9
  22. package/dist/core/components/card.js +1 -3
  23. package/dist/core/components/card.js.map +1 -1
  24. package/dist/core/components/confirm-dialog.d.ts +2 -3
  25. package/dist/core/components/confirm-dialog.js +19 -13
  26. package/dist/core/components/confirm-dialog.js.map +1 -1
  27. package/dist/core/components/fragment.d.ts +1 -10
  28. package/dist/core/components/fragment.js +5 -6
  29. package/dist/core/components/fragment.js.map +1 -1
  30. package/dist/core/components/grid.d.ts +1 -8
  31. package/dist/core/components/grid.js +1 -2
  32. package/dist/core/components/grid.js.map +1 -1
  33. package/dist/core/components/heading.d.ts +1 -9
  34. package/dist/core/components/heading.js +2 -3
  35. package/dist/core/components/heading.js.map +1 -1
  36. package/dist/core/components/icon.d.ts +3 -0
  37. package/dist/core/components/icon.js +30 -0
  38. package/dist/core/components/icon.js.map +1 -0
  39. package/dist/core/components/index.d.ts +1 -1
  40. package/dist/core/components/index.js +4 -0
  41. package/dist/core/components/index.js.map +1 -1
  42. package/dist/core/components/link.d.ts +1 -12
  43. package/dist/core/components/link.js +4 -9
  44. package/dist/core/components/link.js.map +1 -1
  45. package/dist/core/components/modal.d.ts +1 -11
  46. package/dist/core/components/modal.js +27 -31
  47. package/dist/core/components/modal.js.map +1 -1
  48. package/dist/core/components/section.d.ts +3 -0
  49. package/dist/core/components/section.js +79 -0
  50. package/dist/core/components/section.js.map +1 -0
  51. package/dist/core/components/segmented-control.d.ts +1 -14
  52. package/dist/core/components/segmented-control.js +4 -7
  53. package/dist/core/components/segmented-control.js.map +1 -1
  54. package/dist/core/components/segmented-pills.d.ts +4 -2
  55. package/dist/core/components/segmented-pills.js +10 -1
  56. package/dist/core/components/segmented-pills.js.map +1 -1
  57. package/dist/core/components/spinner.js +8 -4
  58. package/dist/core/components/spinner.js.map +1 -1
  59. package/dist/core/components/stack.d.ts +1 -11
  60. package/dist/core/components/stack.js +5 -5
  61. package/dist/core/components/stack.js.map +1 -1
  62. package/dist/core/components/tabs.d.ts +1 -19
  63. package/dist/core/components/tabs.js +45 -21
  64. package/dist/core/components/tabs.js.map +1 -1
  65. package/dist/core/components/text.d.ts +1 -9
  66. package/dist/core/components/text.js +2 -3
  67. package/dist/core/components/text.js.map +1 -1
  68. package/dist/core/registry.d.ts +9 -3
  69. package/dist/core/registry.js +21 -5
  70. package/dist/core/registry.js.map +1 -1
  71. package/dist/core/renderer.js +7 -13
  72. package/dist/core/renderer.js.map +1 -1
  73. package/dist/core/types.d.ts +54 -26
  74. package/dist/form/components/base/checkbox.js +5 -2
  75. package/dist/form/components/base/checkbox.js.map +1 -1
  76. package/dist/form/components/base/field.d.ts +2 -1
  77. package/dist/form/components/base/field.js +5 -1
  78. package/dist/form/components/base/field.js.map +1 -1
  79. package/dist/form/components/base/password-input.js +9 -2
  80. package/dist/form/components/base/password-input.js.map +1 -1
  81. package/dist/form/components/base/submit-button.d.ts +4 -4
  82. package/dist/form/components/base/submit-button.js +2 -2
  83. package/dist/form/components/base/submit-button.js.map +1 -1
  84. package/dist/form/components/conditions.d.ts +6 -9
  85. package/dist/form/components/conditions.js +10 -2
  86. package/dist/form/components/conditions.js.map +1 -1
  87. package/dist/form/components/context.d.ts +0 -4
  88. package/dist/form/components/context.js +1 -5
  89. package/dist/form/components/context.js.map +1 -1
  90. package/dist/form/components/field-props.d.ts +24 -0
  91. package/dist/form/components/field-props.js +15 -0
  92. package/dist/form/components/field-props.js.map +1 -0
  93. package/dist/form/components/fields/checkbox.d.ts +1 -15
  94. package/dist/form/components/fields/checkbox.js +16 -21
  95. package/dist/form/components/fields/checkbox.js.map +1 -1
  96. package/dist/form/components/fields/choice.d.ts +1 -13
  97. package/dist/form/components/fields/choice.js +13 -20
  98. package/dist/form/components/fields/choice.js.map +1 -1
  99. package/dist/form/components/fields/date-input.d.ts +1 -19
  100. package/dist/form/components/fields/date-input.js +11 -16
  101. package/dist/form/components/fields/date-input.js.map +1 -1
  102. package/dist/form/components/fields/hidden-input.d.ts +1 -9
  103. package/dist/form/components/fields/hidden-input.js +2 -3
  104. package/dist/form/components/fields/hidden-input.js.map +1 -1
  105. package/dist/form/components/fields/number-input.d.ts +1 -22
  106. package/dist/form/components/fields/number-input.js +38 -41
  107. package/dist/form/components/fields/number-input.js.map +1 -1
  108. package/dist/form/components/fields/password-input.d.ts +1 -28
  109. package/dist/form/components/fields/password-input.js +15 -24
  110. package/dist/form/components/fields/password-input.js.map +1 -1
  111. package/dist/form/components/fields/rich-editor.d.ts +1 -16
  112. package/dist/form/components/fields/rich-editor.js +57 -47
  113. package/dist/form/components/fields/rich-editor.js.map +1 -1
  114. package/dist/form/components/fields/select.d.ts +1 -22
  115. package/dist/form/components/fields/select.js +85 -74
  116. package/dist/form/components/fields/select.js.map +1 -1
  117. package/dist/form/components/fields/simple-field.d.ts +9 -0
  118. package/dist/form/components/fields/simple-field.js +22 -0
  119. package/dist/form/components/fields/simple-field.js.map +1 -0
  120. package/dist/form/components/fields/text-input.d.ts +1 -20
  121. package/dist/form/components/fields/text-input.js +12 -17
  122. package/dist/form/components/fields/text-input.js.map +1 -1
  123. package/dist/form/components/fields/textarea.d.ts +1 -19
  124. package/dist/form/components/fields/textarea.js +11 -16
  125. package/dist/form/components/fields/textarea.js.map +1 -1
  126. package/dist/form/components/form.d.ts +1 -20
  127. package/dist/form/components/form.js +29 -36
  128. package/dist/form/components/form.js.map +1 -1
  129. package/dist/form/components/index.d.ts +0 -1
  130. package/dist/form/components/index.js +1 -2
  131. package/dist/form/components/resolved-nodes.d.ts +1 -1
  132. package/dist/form/components/resolved-nodes.js +2 -2
  133. package/dist/form/components/resolved-nodes.js.map +1 -1
  134. package/dist/form/components/types.d.ts +1 -0
  135. package/dist/form/components/use-controlled-field.d.ts +3 -9
  136. package/dist/form/components/use-controlled-field.js +5 -9
  137. package/dist/form/components/use-controlled-field.js.map +1 -1
  138. package/dist/form/components/use-dependent-field.d.ts +1 -1
  139. package/dist/form/components/use-dependent-field.js +8 -8
  140. package/dist/form/components/use-dependent-field.js.map +1 -1
  141. package/dist/form/components/use-form-resolver.d.ts +1 -1
  142. package/dist/form/components/use-form-resolver.js +8 -13
  143. package/dist/form/components/use-form-resolver.js.map +1 -1
  144. package/dist/form/components/use-seed-default.d.ts +5 -0
  145. package/dist/form/components/use-seed-default.js +23 -0
  146. package/dist/form/components/use-seed-default.js.map +1 -0
  147. package/dist/form/index.d.ts +1 -1
  148. package/dist/form/index.js +0 -1
  149. package/dist/form/index.js.map +1 -1
  150. package/dist/form/skeleton.d.ts +1 -1
  151. package/dist/form/skeleton.js +1 -1
  152. package/dist/form/skeleton.js.map +1 -1
  153. package/dist/i18n/backend.d.ts +24 -0
  154. package/dist/i18n/backend.js +39 -0
  155. package/dist/i18n/backend.js.map +1 -0
  156. package/dist/i18n/index.d.ts +3 -0
  157. package/dist/i18n/index.js +3 -0
  158. package/dist/i18n/instance.js +48 -0
  159. package/dist/i18n/instance.js.map +1 -0
  160. package/dist/icons/icon-renderer.js +30 -5
  161. package/dist/icons/icon-renderer.js.map +1 -1
  162. package/dist/icons/index.d.ts +2 -0
  163. package/dist/icons/index.js +2 -1
  164. package/dist/icons/sprite.d.ts +30 -0
  165. package/dist/icons/sprite.js +40 -0
  166. package/dist/icons/sprite.js.map +1 -0
  167. package/dist/index.d.ts +9 -5
  168. package/dist/index.js +7 -3
  169. package/dist/inertia.d.ts +1 -6
  170. package/dist/inertia.js +4 -8
  171. package/dist/inertia.js.map +1 -1
  172. package/dist/lattice.css +129 -5
  173. package/dist/layout/components.d.ts +1 -0
  174. package/dist/layout/components.js +19 -0
  175. package/dist/layout/components.js.map +1 -0
  176. package/dist/layout/context.d.ts +12 -0
  177. package/dist/layout/context.js +19 -0
  178. package/dist/layout/context.js.map +1 -0
  179. package/dist/layout/index.d.ts +3 -0
  180. package/dist/layout/index.js +4 -0
  181. package/dist/layout/menu-item.d.ts +3 -0
  182. package/dist/layout/menu-item.js +130 -0
  183. package/dist/layout/menu-item.js.map +1 -0
  184. package/dist/layout/menu.d.ts +3 -0
  185. package/dist/layout/menu.js +13 -0
  186. package/dist/layout/menu.js.map +1 -0
  187. package/dist/layout/outlet.d.ts +6 -0
  188. package/dist/layout/outlet.js +14 -0
  189. package/dist/layout/outlet.js.map +1 -0
  190. package/dist/layout/schema-layout.d.ts +10 -0
  191. package/dist/layout/schema-layout.js +30 -0
  192. package/dist/layout/schema-layout.js.map +1 -0
  193. package/dist/layout/sidebar.d.ts +3 -0
  194. package/dist/layout/sidebar.js +48 -0
  195. package/dist/layout/sidebar.js.map +1 -0
  196. package/dist/lib/utils.d.ts +0 -2
  197. package/dist/lib/utils.js +1 -4
  198. package/dist/lib/utils.js.map +1 -1
  199. package/dist/node_modules/i18next/dist/esm/i18next.js +1982 -0
  200. package/dist/node_modules/i18next/dist/esm/i18next.js.map +1 -0
  201. package/dist/node_modules/i18next-http-backend/esm/index.js +352 -0
  202. package/dist/node_modules/i18next-http-backend/esm/index.js.map +1 -0
  203. package/dist/node_modules/react-i18next/dist/es/context.js +23 -0
  204. package/dist/node_modules/react-i18next/dist/es/context.js.map +1 -0
  205. package/dist/node_modules/react-i18next/dist/es/defaults.js +29 -0
  206. package/dist/node_modules/react-i18next/dist/es/defaults.js.map +1 -0
  207. package/dist/node_modules/react-i18next/dist/es/i18nInstance.js +10 -0
  208. package/dist/node_modules/react-i18next/dist/es/i18nInstance.js.map +1 -0
  209. package/dist/node_modules/react-i18next/dist/es/initReactI18next.js +14 -0
  210. package/dist/node_modules/react-i18next/dist/es/initReactI18next.js.map +1 -0
  211. package/dist/node_modules/react-i18next/dist/es/unescape.js +30 -0
  212. package/dist/node_modules/react-i18next/dist/es/unescape.js.map +1 -0
  213. package/dist/node_modules/react-i18next/dist/es/useTranslation.js +157 -0
  214. package/dist/node_modules/react-i18next/dist/es/useTranslation.js.map +1 -0
  215. package/dist/node_modules/react-i18next/dist/es/utils.js +58 -0
  216. package/dist/node_modules/react-i18next/dist/es/utils.js.map +1 -0
  217. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js +70 -0
  218. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.development.js.map +1 -0
  219. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +61 -0
  220. package/dist/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js.map +1 -0
  221. package/dist/node_modules/use-sync-external-store/shim/index.js +13 -0
  222. package/dist/node_modules/use-sync-external-store/shim/index.js.map +1 -0
  223. package/dist/page.d.ts +1 -1
  224. package/dist/page.js +2 -2
  225. package/dist/page.js.map +1 -1
  226. package/dist/provider.d.ts +8 -3
  227. package/dist/provider.js +17 -9
  228. package/dist/provider.js.map +1 -1
  229. package/dist/registry.d.ts +1 -1
  230. package/dist/registry.js +2 -1
  231. package/dist/registry.js.map +1 -1
  232. package/dist/table/bulk.d.ts +6 -10
  233. package/dist/table/bulk.js +13 -35
  234. package/dist/table/bulk.js.map +1 -1
  235. package/dist/table/column-registry.d.ts +9 -0
  236. package/dist/table/components/bulk-bar.js +34 -3
  237. package/dist/table/components/bulk-bar.js.map +1 -1
  238. package/dist/table/components/cells/badge-cell.d.ts +5 -0
  239. package/dist/table/components/cells/badge-cell.js +16 -0
  240. package/dist/table/components/cells/badge-cell.js.map +1 -0
  241. package/dist/table/components/cells/icon-cell.d.ts +5 -0
  242. package/dist/table/components/cells/icon-cell.js +22 -0
  243. package/dist/table/components/cells/icon-cell.js.map +1 -0
  244. package/dist/table/components/cells/image-cell.d.ts +5 -0
  245. package/dist/table/components/cells/image-cell.js +24 -0
  246. package/dist/table/components/cells/image-cell.js.map +1 -0
  247. package/dist/table/components/cells/text-cell.d.ts +6 -0
  248. package/dist/table/components/cells/text-cell.js +50 -0
  249. package/dist/table/components/cells/text-cell.js.map +1 -0
  250. package/dist/table/components/column-filter-control.js +59 -96
  251. package/dist/table/components/column-filter-control.js.map +1 -1
  252. package/dist/table/components/column-header.js +22 -11
  253. package/dist/table/components/column-header.js.map +1 -1
  254. package/dist/table/components/filter-stack-bar.d.ts +2 -2
  255. package/dist/table/components/filter-stack-bar.js +10 -8
  256. package/dist/table/components/filter-stack-bar.js.map +1 -1
  257. package/dist/table/components/filter-value-input.d.ts +5 -3
  258. package/dist/table/components/filter-value-input.js +25 -16
  259. package/dist/table/components/filter-value-input.js.map +1 -1
  260. package/dist/table/components/pagination.d.ts +1 -1
  261. package/dist/table/components/pagination.js +20 -8
  262. package/dist/table/components/pagination.js.map +1 -1
  263. package/dist/table/components/sort-bar.d.ts +2 -2
  264. package/dist/table/components/sort-bar.js +12 -10
  265. package/dist/table/components/sort-bar.js.map +1 -1
  266. package/dist/table/components/table-action-node.d.ts +1 -1
  267. package/dist/table/components/table-action-node.js +1 -1
  268. package/dist/table/components/table-action-node.js.map +1 -1
  269. package/dist/table/components/table-cell.d.ts +1 -1
  270. package/dist/table/components/table-cell.js +24 -43
  271. package/dist/table/components/table-cell.js.map +1 -1
  272. package/dist/table/components/table.d.ts +6 -2
  273. package/dist/table/components/table.js +40 -17
  274. package/dist/table/components/table.js.map +1 -1
  275. package/dist/table/format.js +5 -3
  276. package/dist/table/format.js.map +1 -1
  277. package/dist/table/index.d.ts +1 -1
  278. package/dist/table/index.js.map +1 -1
  279. package/dist/table/payload.d.ts +1 -1
  280. package/dist/table/query.d.ts +0 -1
  281. package/dist/table/query.js +8 -9
  282. package/dist/table/query.js.map +1 -1
  283. package/dist/table/types.d.ts +38 -42
  284. package/dist/table/use-table.d.ts +3 -4
  285. package/dist/table/use-table.js +12 -23
  286. package/dist/table/use-table.js.map +1 -1
  287. package/dist/test-support.d.ts +14 -0
  288. package/dist/test-support.js +14 -0
  289. package/dist/test-support.js.map +1 -0
  290. package/dist/toast/index.d.ts +1 -0
  291. package/dist/toast/index.js +2 -0
  292. package/dist/toast/toaster.d.ts +3 -0
  293. package/dist/toast/toaster.js +126 -0
  294. package/dist/toast/toaster.js.map +1 -0
  295. package/dist/types/generated.d.ts +677 -0
  296. package/dist/types/generated.js +0 -0
  297. package/dist/types/index.d.ts +1 -1
  298. package/package.json +18 -3
  299. package/resources/icons/align-center.svg +17 -0
  300. package/resources/icons/align-justify.svg +17 -0
  301. package/resources/icons/align-left.svg +17 -0
  302. package/resources/icons/align-right.svg +17 -0
  303. package/resources/icons/arrow-down.svg +16 -0
  304. package/resources/icons/arrow-up.svg +16 -0
  305. package/resources/icons/bold.svg +15 -0
  306. package/resources/icons/check.svg +15 -0
  307. package/resources/icons/chevron-down.svg +15 -0
  308. package/resources/icons/chevron-right.svg +15 -0
  309. package/resources/icons/chevrons-up-down.svg +16 -0
  310. package/resources/icons/circle-alert.svg +17 -0
  311. package/resources/icons/circle-check.svg +16 -0
  312. package/resources/icons/circle-help.svg +17 -0
  313. package/resources/icons/circle-x.svg +17 -0
  314. package/resources/icons/code.svg +16 -0
  315. package/resources/icons/columns-3.svg +17 -0
  316. package/resources/icons/copy.svg +16 -0
  317. package/resources/icons/external-link.svg +17 -0
  318. package/resources/icons/eye-off.svg +18 -0
  319. package/resources/icons/eye.svg +16 -0
  320. package/resources/icons/filter.svg +15 -0
  321. package/resources/icons/heading-1.svg +18 -0
  322. package/resources/icons/heading-2.svg +18 -0
  323. package/resources/icons/heading-3.svg +19 -0
  324. package/resources/icons/highlighter.svg +16 -0
  325. package/resources/icons/info.svg +17 -0
  326. package/resources/icons/italic.svg +17 -0
  327. package/resources/icons/layout-dashboard.svg +18 -0
  328. package/resources/icons/link.svg +16 -0
  329. package/resources/icons/list-ordered.svg +20 -0
  330. package/resources/icons/list.svg +20 -0
  331. package/resources/icons/loader-2.svg +15 -0
  332. package/resources/icons/minus.svg +15 -0
  333. package/resources/icons/more-horizontal.svg +17 -0
  334. package/resources/icons/panel-left.svg +16 -0
  335. package/resources/icons/pencil-line.svg +17 -0
  336. package/resources/icons/pencil.svg +16 -0
  337. package/resources/icons/plus.svg +16 -0
  338. package/resources/icons/quote.svg +16 -0
  339. package/resources/icons/rows-3.svg +17 -0
  340. package/resources/icons/search.svg +16 -0
  341. package/resources/icons/send.svg +16 -0
  342. package/resources/icons/settings.svg +16 -0
  343. package/resources/icons/smile.svg +18 -0
  344. package/resources/icons/strikethrough.svg +17 -0
  345. package/resources/icons/table.svg +18 -0
  346. package/resources/icons/trash-2.svg +19 -0
  347. package/resources/icons/underline.svg +16 -0
  348. package/resources/icons/x.svg +16 -0
  349. package/dist/core/props.d.ts +0 -14
  350. package/dist/core/props.js +0 -30
  351. package/dist/core/props.js.map +0 -1
  352. package/dist/form/components/fields/submit-button.d.ts +0 -10
  353. package/dist/form/components/fields/submit-button.js +0 -14
  354. package/dist/form/components/fields/submit-button.js.map +0 -1
  355. package/dist/generated/types.d.ts +0 -17
  356. package/dist/icons/default-icons.d.ts +0 -3
  357. package/dist/icons/default-icons.js +0 -44
  358. package/dist/icons/default-icons.js.map +0 -1
  359. package/dist/icons/dynamic-lucide-renderer.d.ts +0 -2
  360. package/dist/icons/dynamic-lucide-renderer.js +0 -18
  361. package/dist/icons/dynamic-lucide-renderer.js.map +0 -1
  362. package/dist/menu/index.d.ts +0 -1
  363. package/dist/menu/index.js +0 -2
  364. package/dist/menu/use-menu.d.ts +0 -2
  365. package/dist/menu/use-menu.js +0 -9
  366. package/dist/menu/use-menu.js.map +0 -1
  367. /package/dist/{generated/types.js → table/column-registry.js} +0 -0
@@ -0,0 +1,1982 @@
1
+ //#region node_modules/i18next/dist/esm/i18next.js
2
+ var isString = (obj) => typeof obj === "string";
3
+ var defer = () => {
4
+ let res;
5
+ let rej;
6
+ const promise = new Promise((resolve, reject) => {
7
+ res = resolve;
8
+ rej = reject;
9
+ });
10
+ promise.resolve = res;
11
+ promise.reject = rej;
12
+ return promise;
13
+ };
14
+ var makeString = (object) => {
15
+ if (object == null) return "";
16
+ return String(object);
17
+ };
18
+ var copy = (a, s, t) => {
19
+ a.forEach((m) => {
20
+ if (s[m]) t[m] = s[m];
21
+ });
22
+ };
23
+ var lastOfPathSeparatorRegExp = /###/g;
24
+ var cleanKey = (key) => key && key.includes("###") ? key.replace(lastOfPathSeparatorRegExp, ".") : key;
25
+ var canNotTraverseDeeper = (object) => !object || isString(object);
26
+ var getLastOfPath = (object, path, Empty) => {
27
+ const stack = !isString(path) ? path : path.split(".");
28
+ let stackIndex = 0;
29
+ while (stackIndex < stack.length - 1) {
30
+ if (canNotTraverseDeeper(object)) return {};
31
+ const key = cleanKey(stack[stackIndex]);
32
+ if (!object[key] && Empty) object[key] = new Empty();
33
+ if (Object.prototype.hasOwnProperty.call(object, key)) object = object[key];
34
+ else object = {};
35
+ ++stackIndex;
36
+ }
37
+ if (canNotTraverseDeeper(object)) return {};
38
+ return {
39
+ obj: object,
40
+ k: cleanKey(stack[stackIndex])
41
+ };
42
+ };
43
+ var setPath = (object, path, newValue) => {
44
+ const { obj, k } = getLastOfPath(object, path, Object);
45
+ if (obj !== void 0 || path.length === 1) {
46
+ obj[k] = newValue;
47
+ return;
48
+ }
49
+ let e = path[path.length - 1];
50
+ let p = path.slice(0, path.length - 1);
51
+ let last = getLastOfPath(object, p, Object);
52
+ while (last.obj === void 0 && p.length) {
53
+ e = `${p[p.length - 1]}.${e}`;
54
+ p = p.slice(0, p.length - 1);
55
+ last = getLastOfPath(object, p, Object);
56
+ if (last?.obj && typeof last.obj[`${last.k}.${e}`] !== "undefined") last.obj = void 0;
57
+ }
58
+ last.obj[`${last.k}.${e}`] = newValue;
59
+ };
60
+ var pushPath = (object, path, newValue, concat) => {
61
+ const { obj, k } = getLastOfPath(object, path, Object);
62
+ obj[k] = obj[k] || [];
63
+ obj[k].push(newValue);
64
+ };
65
+ var getPath = (object, path) => {
66
+ const { obj, k } = getLastOfPath(object, path);
67
+ if (!obj) return void 0;
68
+ if (!Object.prototype.hasOwnProperty.call(obj, k)) return void 0;
69
+ return obj[k];
70
+ };
71
+ var getPathWithDefaults = (data, defaultData, key) => {
72
+ const value = getPath(data, key);
73
+ if (value !== void 0) return value;
74
+ return getPath(defaultData, key);
75
+ };
76
+ var deepExtend = (target, source, overwrite) => {
77
+ for (const prop in source) if (prop !== "__proto__" && prop !== "constructor") if (prop in target) if (isString(target[prop]) || target[prop] instanceof String || isString(source[prop]) || source[prop] instanceof String) {
78
+ if (overwrite) target[prop] = source[prop];
79
+ } else deepExtend(target[prop], source[prop], overwrite);
80
+ else target[prop] = source[prop];
81
+ return target;
82
+ };
83
+ var regexEscape = (str) => str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
84
+ var _entityMap = {
85
+ "&": "&amp;",
86
+ "<": "&lt;",
87
+ ">": "&gt;",
88
+ "\"": "&quot;",
89
+ "'": "&#39;",
90
+ "/": "&#x2F;"
91
+ };
92
+ var escape = (data) => {
93
+ if (isString(data)) return data.replace(/[&<>"'\/]/g, (s) => _entityMap[s]);
94
+ return data;
95
+ };
96
+ var RegExpCache = class {
97
+ constructor(capacity) {
98
+ this.capacity = capacity;
99
+ this.regExpMap = /* @__PURE__ */ new Map();
100
+ this.regExpQueue = [];
101
+ }
102
+ getRegExp(pattern) {
103
+ const regExpFromCache = this.regExpMap.get(pattern);
104
+ if (regExpFromCache !== void 0) return regExpFromCache;
105
+ const regExpNew = new RegExp(pattern);
106
+ if (this.regExpQueue.length === this.capacity) this.regExpMap.delete(this.regExpQueue.shift());
107
+ this.regExpMap.set(pattern, regExpNew);
108
+ this.regExpQueue.push(pattern);
109
+ return regExpNew;
110
+ }
111
+ };
112
+ var chars = [
113
+ " ",
114
+ ",",
115
+ "?",
116
+ "!",
117
+ ";"
118
+ ];
119
+ var looksLikeObjectPathRegExpCache = new RegExpCache(20);
120
+ var looksLikeObjectPath = (key, nsSeparator, keySeparator) => {
121
+ nsSeparator = nsSeparator || "";
122
+ keySeparator = keySeparator || "";
123
+ const possibleChars = chars.filter((c) => !nsSeparator.includes(c) && !keySeparator.includes(c));
124
+ if (possibleChars.length === 0) return true;
125
+ const r = looksLikeObjectPathRegExpCache.getRegExp(`(${possibleChars.map((c) => c === "?" ? "\\?" : c).join("|")})`);
126
+ let matched = !r.test(key);
127
+ if (!matched) {
128
+ const ki = key.indexOf(keySeparator);
129
+ if (ki > 0 && !r.test(key.substring(0, ki))) matched = true;
130
+ }
131
+ return matched;
132
+ };
133
+ var deepFind = (obj, path, keySeparator = ".") => {
134
+ if (!obj) return void 0;
135
+ if (obj[path]) {
136
+ if (!Object.prototype.hasOwnProperty.call(obj, path)) return void 0;
137
+ return obj[path];
138
+ }
139
+ const tokens = path.split(keySeparator);
140
+ let current = obj;
141
+ for (let i = 0; i < tokens.length;) {
142
+ if (!current || typeof current !== "object") return;
143
+ let next;
144
+ let nextPath = "";
145
+ for (let j = i; j < tokens.length; ++j) {
146
+ if (j !== i) nextPath += keySeparator;
147
+ nextPath += tokens[j];
148
+ next = current[nextPath];
149
+ if (next !== void 0) {
150
+ if ([
151
+ "string",
152
+ "number",
153
+ "boolean"
154
+ ].includes(typeof next) && j < tokens.length - 1) continue;
155
+ i += j - i + 1;
156
+ break;
157
+ }
158
+ }
159
+ current = next;
160
+ }
161
+ return current;
162
+ };
163
+ var getCleanedCode = (code) => code?.replace(/_/g, "-");
164
+ var consoleLogger = {
165
+ type: "logger",
166
+ log(args) {
167
+ this.output("log", args);
168
+ },
169
+ warn(args) {
170
+ this.output("warn", args);
171
+ },
172
+ error(args) {
173
+ this.output("error", args);
174
+ },
175
+ output(type, args) {
176
+ console?.[type]?.apply?.(console, args);
177
+ }
178
+ };
179
+ var baseLogger = new class Logger {
180
+ constructor(concreteLogger, options = {}) {
181
+ this.init(concreteLogger, options);
182
+ }
183
+ init(concreteLogger, options = {}) {
184
+ this.prefix = options.prefix || "i18next:";
185
+ this.logger = concreteLogger || consoleLogger;
186
+ this.options = options;
187
+ this.debug = options.debug;
188
+ }
189
+ log(...args) {
190
+ return this.forward(args, "log", "", true);
191
+ }
192
+ warn(...args) {
193
+ return this.forward(args, "warn", "", true);
194
+ }
195
+ error(...args) {
196
+ return this.forward(args, "error", "");
197
+ }
198
+ deprecate(...args) {
199
+ return this.forward(args, "warn", "WARNING DEPRECATED: ", true);
200
+ }
201
+ forward(args, lvl, prefix, debugOnly) {
202
+ if (debugOnly && !this.debug) return null;
203
+ args = args.map((a) => isString(a) ? a.replace(/[\r\n\x00-\x1F\x7F]/g, " ") : a);
204
+ if (isString(args[0])) args[0] = `${prefix}${this.prefix} ${args[0]}`;
205
+ return this.logger[lvl](args);
206
+ }
207
+ create(moduleName) {
208
+ return new Logger(this.logger, {
209
+ prefix: `${this.prefix}:${moduleName}:`,
210
+ ...this.options
211
+ });
212
+ }
213
+ clone(options) {
214
+ options = options || this.options;
215
+ options.prefix = options.prefix || this.prefix;
216
+ return new Logger(this.logger, options);
217
+ }
218
+ }();
219
+ var EventEmitter = class {
220
+ constructor() {
221
+ this.observers = {};
222
+ }
223
+ on(events, listener) {
224
+ events.split(" ").forEach((event) => {
225
+ if (!this.observers[event]) this.observers[event] = /* @__PURE__ */ new Map();
226
+ const numListeners = this.observers[event].get(listener) || 0;
227
+ this.observers[event].set(listener, numListeners + 1);
228
+ });
229
+ return this;
230
+ }
231
+ off(event, listener) {
232
+ if (!this.observers[event]) return;
233
+ if (!listener) {
234
+ delete this.observers[event];
235
+ return;
236
+ }
237
+ this.observers[event].delete(listener);
238
+ }
239
+ once(event, listener) {
240
+ const wrapper = (...args) => {
241
+ listener(...args);
242
+ this.off(event, wrapper);
243
+ };
244
+ this.on(event, wrapper);
245
+ return this;
246
+ }
247
+ emit(event, ...args) {
248
+ if (this.observers[event]) Array.from(this.observers[event].entries()).forEach(([observer, numTimesAdded]) => {
249
+ for (let i = 0; i < numTimesAdded; i++) observer(...args);
250
+ });
251
+ if (this.observers["*"]) Array.from(this.observers["*"].entries()).forEach(([observer, numTimesAdded]) => {
252
+ for (let i = 0; i < numTimesAdded; i++) observer(event, ...args);
253
+ });
254
+ }
255
+ };
256
+ var ResourceStore = class extends EventEmitter {
257
+ constructor(data, options = {
258
+ ns: ["translation"],
259
+ defaultNS: "translation"
260
+ }) {
261
+ super();
262
+ this.data = data || {};
263
+ this.options = options;
264
+ if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
265
+ if (this.options.ignoreJSONStructure === void 0) this.options.ignoreJSONStructure = true;
266
+ }
267
+ addNamespaces(ns) {
268
+ if (!this.options.ns.includes(ns)) this.options.ns.push(ns);
269
+ }
270
+ removeNamespaces(ns) {
271
+ const index = this.options.ns.indexOf(ns);
272
+ if (index > -1) this.options.ns.splice(index, 1);
273
+ }
274
+ getResource(lng, ns, key, options = {}) {
275
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
276
+ const ignoreJSONStructure = options.ignoreJSONStructure !== void 0 ? options.ignoreJSONStructure : this.options.ignoreJSONStructure;
277
+ let path;
278
+ if (lng.includes(".")) path = lng.split(".");
279
+ else {
280
+ path = [lng, ns];
281
+ if (key) if (Array.isArray(key)) path.push(...key);
282
+ else if (isString(key) && keySeparator) path.push(...key.split(keySeparator));
283
+ else path.push(key);
284
+ }
285
+ const result = getPath(this.data, path);
286
+ if (!result && !ns && !key && lng.includes(".")) {
287
+ lng = path[0];
288
+ ns = path[1];
289
+ key = path.slice(2).join(".");
290
+ }
291
+ if (result || !ignoreJSONStructure || !isString(key)) return result;
292
+ return deepFind(this.data?.[lng]?.[ns], key, keySeparator);
293
+ }
294
+ addResource(lng, ns, key, value, options = { silent: false }) {
295
+ const keySeparator = options.keySeparator !== void 0 ? options.keySeparator : this.options.keySeparator;
296
+ let path = [lng, ns];
297
+ if (key) path = path.concat(keySeparator ? key.split(keySeparator) : key);
298
+ if (lng.includes(".")) {
299
+ path = lng.split(".");
300
+ value = ns;
301
+ ns = path[1];
302
+ }
303
+ this.addNamespaces(ns);
304
+ setPath(this.data, path, value);
305
+ if (!options.silent) this.emit("added", lng, ns, key, value);
306
+ }
307
+ addResources(lng, ns, resources, options = { silent: false }) {
308
+ for (const m in resources) if (isString(resources[m]) || Array.isArray(resources[m])) this.addResource(lng, ns, m, resources[m], { silent: true });
309
+ if (!options.silent) this.emit("added", lng, ns, resources);
310
+ }
311
+ addResourceBundle(lng, ns, resources, deep, overwrite, options = {
312
+ silent: false,
313
+ skipCopy: false
314
+ }) {
315
+ let path = [lng, ns];
316
+ if (lng.includes(".")) {
317
+ path = lng.split(".");
318
+ deep = resources;
319
+ resources = ns;
320
+ ns = path[1];
321
+ }
322
+ this.addNamespaces(ns);
323
+ let pack = getPath(this.data, path) || {};
324
+ if (!options.skipCopy) resources = JSON.parse(JSON.stringify(resources));
325
+ if (deep) deepExtend(pack, resources, overwrite);
326
+ else pack = {
327
+ ...pack,
328
+ ...resources
329
+ };
330
+ setPath(this.data, path, pack);
331
+ if (!options.silent) this.emit("added", lng, ns, resources);
332
+ }
333
+ removeResourceBundle(lng, ns) {
334
+ if (this.hasResourceBundle(lng, ns)) delete this.data[lng][ns];
335
+ this.removeNamespaces(ns);
336
+ this.emit("removed", lng, ns);
337
+ }
338
+ hasResourceBundle(lng, ns) {
339
+ return this.getResource(lng, ns) !== void 0;
340
+ }
341
+ getResourceBundle(lng, ns) {
342
+ if (!ns) ns = this.options.defaultNS;
343
+ return this.getResource(lng, ns);
344
+ }
345
+ getDataByLanguage(lng) {
346
+ return this.data[lng];
347
+ }
348
+ hasLanguageSomeTranslations(lng) {
349
+ const data = this.getDataByLanguage(lng);
350
+ return !!(data && Object.keys(data) || []).find((v) => data[v] && Object.keys(data[v]).length > 0);
351
+ }
352
+ toJSON() {
353
+ return this.data;
354
+ }
355
+ };
356
+ var postProcessor = {
357
+ processors: {},
358
+ addPostProcessor(module) {
359
+ this.processors[module.name] = module;
360
+ },
361
+ handle(processors, value, key, options, translator) {
362
+ processors.forEach((processor) => {
363
+ value = this.processors[processor]?.process(value, key, options, translator) ?? value;
364
+ });
365
+ return value;
366
+ }
367
+ };
368
+ var PATH_KEY = Symbol("i18next/PATH_KEY");
369
+ function createProxy() {
370
+ const state = [];
371
+ const handler = Object.create(null);
372
+ let proxy;
373
+ handler.get = (target, key) => {
374
+ proxy?.revoke?.();
375
+ if (key === PATH_KEY) return state;
376
+ state.push(key);
377
+ proxy = Proxy.revocable(target, handler);
378
+ return proxy.proxy;
379
+ };
380
+ return Proxy.revocable(Object.create(null), handler).proxy;
381
+ }
382
+ function keysFromSelector(selector, opts) {
383
+ const { [PATH_KEY]: path } = selector(createProxy());
384
+ const keySeparator = opts?.keySeparator ?? ".";
385
+ const nsSeparator = opts?.nsSeparator ?? ":";
386
+ const strict = opts?.enableSelector === "strict";
387
+ if (path.length > 1 && nsSeparator) {
388
+ const ns = opts?.ns;
389
+ const nsList = strict ? Array.isArray(ns) ? ns : ns ? [ns] : null : Array.isArray(ns) ? ns : null;
390
+ if (nsList) {
391
+ if ((strict ? nsList : nsList.length > 1 ? nsList.slice(1) : []).includes(path[0])) return `${path[0]}${nsSeparator}${path.slice(1).join(keySeparator)}`;
392
+ }
393
+ }
394
+ return path.join(keySeparator);
395
+ }
396
+ var shouldHandleAsObject = (res) => !isString(res) && typeof res !== "boolean" && typeof res !== "number";
397
+ var Translator = class Translator extends EventEmitter {
398
+ constructor(services, options = {}) {
399
+ super();
400
+ copy([
401
+ "resourceStore",
402
+ "languageUtils",
403
+ "pluralResolver",
404
+ "interpolator",
405
+ "backendConnector",
406
+ "i18nFormat",
407
+ "utils"
408
+ ], services, this);
409
+ this.options = options;
410
+ if (this.options.keySeparator === void 0) this.options.keySeparator = ".";
411
+ this.logger = baseLogger.create("translator");
412
+ this.checkedLoadedFor = {};
413
+ }
414
+ changeLanguage(lng) {
415
+ if (lng) this.language = lng;
416
+ }
417
+ exists(key, o = { interpolation: {} }) {
418
+ const opt = { ...o };
419
+ if (key == null) return false;
420
+ const resolved = this.resolve(key, opt);
421
+ if (resolved?.res === void 0) return false;
422
+ const isObject = shouldHandleAsObject(resolved.res);
423
+ if (opt.returnObjects === false && isObject) return false;
424
+ return true;
425
+ }
426
+ extractFromKey(key, opt) {
427
+ let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
428
+ if (nsSeparator === void 0) nsSeparator = ":";
429
+ const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
430
+ let namespaces = opt.ns || this.options.defaultNS || [];
431
+ const wouldCheckForNsInKey = nsSeparator && key.includes(nsSeparator);
432
+ const seemsNaturalLanguage = !this.options.userDefinedKeySeparator && !opt.keySeparator && !this.options.userDefinedNsSeparator && !opt.nsSeparator && !looksLikeObjectPath(key, nsSeparator, keySeparator);
433
+ if (wouldCheckForNsInKey && !seemsNaturalLanguage) {
434
+ const m = key.match(this.interpolator.nestingRegexp);
435
+ if (m && m.length > 0) return {
436
+ key,
437
+ namespaces: isString(namespaces) ? [namespaces] : namespaces
438
+ };
439
+ const parts = key.split(nsSeparator);
440
+ if (nsSeparator !== keySeparator || nsSeparator === keySeparator && this.options.ns.includes(parts[0])) namespaces = parts.shift();
441
+ key = parts.join(keySeparator);
442
+ }
443
+ return {
444
+ key,
445
+ namespaces: isString(namespaces) ? [namespaces] : namespaces
446
+ };
447
+ }
448
+ translate(keys, o, lastKey) {
449
+ let opt = typeof o === "object" ? { ...o } : o;
450
+ if (typeof opt !== "object" && this.options.overloadTranslationOptionHandler) opt = this.options.overloadTranslationOptionHandler(arguments);
451
+ if (typeof opt === "object") opt = { ...opt };
452
+ if (!opt) opt = {};
453
+ if (keys == null) return "";
454
+ if (typeof keys === "function") keys = keysFromSelector(keys, {
455
+ ...this.options,
456
+ ...opt
457
+ });
458
+ if (!Array.isArray(keys)) keys = [String(keys)];
459
+ keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
460
+ ...this.options,
461
+ ...opt
462
+ }) : String(k));
463
+ const returnDetails = opt.returnDetails !== void 0 ? opt.returnDetails : this.options.returnDetails;
464
+ const keySeparator = opt.keySeparator !== void 0 ? opt.keySeparator : this.options.keySeparator;
465
+ const { key, namespaces } = this.extractFromKey(keys[keys.length - 1], opt);
466
+ const namespace = namespaces[namespaces.length - 1];
467
+ let nsSeparator = opt.nsSeparator !== void 0 ? opt.nsSeparator : this.options.nsSeparator;
468
+ if (nsSeparator === void 0) nsSeparator = ":";
469
+ const lng = opt.lng || this.language;
470
+ const appendNamespaceToCIMode = opt.appendNamespaceToCIMode || this.options.appendNamespaceToCIMode;
471
+ if (lng?.toLowerCase() === "cimode") {
472
+ if (appendNamespaceToCIMode) {
473
+ if (returnDetails) return {
474
+ res: `${namespace}${nsSeparator}${key}`,
475
+ usedKey: key,
476
+ exactUsedKey: key,
477
+ usedLng: lng,
478
+ usedNS: namespace,
479
+ usedParams: this.getUsedParamsDetails(opt)
480
+ };
481
+ return `${namespace}${nsSeparator}${key}`;
482
+ }
483
+ if (returnDetails) return {
484
+ res: key,
485
+ usedKey: key,
486
+ exactUsedKey: key,
487
+ usedLng: lng,
488
+ usedNS: namespace,
489
+ usedParams: this.getUsedParamsDetails(opt)
490
+ };
491
+ return key;
492
+ }
493
+ const resolved = this.resolve(keys, opt);
494
+ let res = resolved?.res;
495
+ const resUsedKey = resolved?.usedKey || key;
496
+ const resExactUsedKey = resolved?.exactUsedKey || key;
497
+ const noObject = [
498
+ "[object Number]",
499
+ "[object Function]",
500
+ "[object RegExp]"
501
+ ];
502
+ const joinArrays = opt.joinArrays !== void 0 ? opt.joinArrays : this.options.joinArrays;
503
+ const handleAsObjectInI18nFormat = !this.i18nFormat || this.i18nFormat.handleAsObject;
504
+ const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
505
+ const hasDefaultValue = Translator.hasDefaultValue(opt);
506
+ const defaultValueSuffix = needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, opt) : "";
507
+ const defaultValueSuffixOrdinalFallback = opt.ordinal && needsPluralHandling ? this.pluralResolver.getSuffix(lng, opt.count, { ordinal: false }) : "";
508
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
509
+ const defaultValue = needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] || opt[`defaultValue${defaultValueSuffix}`] || opt[`defaultValue${defaultValueSuffixOrdinalFallback}`] || opt.defaultValue;
510
+ let resForObjHndl = res;
511
+ if (handleAsObjectInI18nFormat && !res && hasDefaultValue) resForObjHndl = defaultValue;
512
+ const handleAsObject = shouldHandleAsObject(resForObjHndl);
513
+ const resType = Object.prototype.toString.apply(resForObjHndl);
514
+ if (handleAsObjectInI18nFormat && resForObjHndl && handleAsObject && !noObject.includes(resType) && !(isString(joinArrays) && Array.isArray(resForObjHndl))) {
515
+ if (!opt.returnObjects && !this.options.returnObjects) {
516
+ if (!this.options.returnedObjectHandler) this.logger.warn("accessing an object - but returnObjects options is not enabled!");
517
+ const r = this.options.returnedObjectHandler ? this.options.returnedObjectHandler(resUsedKey, resForObjHndl, {
518
+ ...opt,
519
+ ns: namespaces
520
+ }) : `key '${key} (${this.language})' returned an object instead of string.`;
521
+ if (returnDetails) {
522
+ resolved.res = r;
523
+ resolved.usedParams = this.getUsedParamsDetails(opt);
524
+ return resolved;
525
+ }
526
+ return r;
527
+ }
528
+ if (keySeparator) {
529
+ const resTypeIsArray = Array.isArray(resForObjHndl);
530
+ const copy = resTypeIsArray ? [] : {};
531
+ const newKeyToUse = resTypeIsArray ? resExactUsedKey : resUsedKey;
532
+ for (const m in resForObjHndl) if (Object.prototype.hasOwnProperty.call(resForObjHndl, m)) {
533
+ const deepKey = `${newKeyToUse}${keySeparator}${m}`;
534
+ if (hasDefaultValue && !res) copy[m] = this.translate(deepKey, {
535
+ ...opt,
536
+ defaultValue: shouldHandleAsObject(defaultValue) ? defaultValue[m] : void 0,
537
+ joinArrays: false,
538
+ ns: namespaces
539
+ });
540
+ else copy[m] = this.translate(deepKey, {
541
+ ...opt,
542
+ joinArrays: false,
543
+ ns: namespaces
544
+ });
545
+ if (copy[m] === deepKey) copy[m] = resForObjHndl[m];
546
+ }
547
+ res = copy;
548
+ }
549
+ } else if (handleAsObjectInI18nFormat && isString(joinArrays) && Array.isArray(res)) {
550
+ res = res.join(joinArrays);
551
+ if (res) res = this.extendTranslation(res, keys, opt, lastKey);
552
+ } else {
553
+ let usedDefault = false;
554
+ let usedKey = false;
555
+ if (!this.isValidLookup(res) && hasDefaultValue) {
556
+ usedDefault = true;
557
+ res = defaultValue;
558
+ }
559
+ if (!this.isValidLookup(res)) {
560
+ usedKey = true;
561
+ res = key;
562
+ }
563
+ const resForMissing = (opt.missingKeyNoValueFallbackToKey || this.options.missingKeyNoValueFallbackToKey) && usedKey ? void 0 : res;
564
+ const updateMissing = hasDefaultValue && defaultValue !== res && this.options.updateMissing;
565
+ if (usedKey || usedDefault || updateMissing) {
566
+ this.logger.log(updateMissing ? "updateKey" : "missingKey", lng, namespace, needsPluralHandling && !updateMissing ? `${key}${this.pluralResolver.getSuffix(lng, opt.count, opt)}` : key, updateMissing ? defaultValue : res);
567
+ if (keySeparator) {
568
+ const fk = this.resolve(key, {
569
+ ...opt,
570
+ keySeparator: false
571
+ });
572
+ if (fk && fk.res) this.logger.warn("Seems the loaded translations were in flat JSON format instead of nested. Either set keySeparator: false on init or make sure your translations are published in nested format.");
573
+ }
574
+ let lngs = [];
575
+ const fallbackLngs = this.languageUtils.getFallbackCodes(this.options.fallbackLng, opt.lng || this.language);
576
+ if (this.options.saveMissingTo === "fallback" && fallbackLngs && fallbackLngs[0]) for (let i = 0; i < fallbackLngs.length; i++) lngs.push(fallbackLngs[i]);
577
+ else if (this.options.saveMissingTo === "all") lngs = this.languageUtils.toResolveHierarchy(opt.lng || this.language);
578
+ else lngs.push(opt.lng || this.language);
579
+ const send = (l, k, specificDefaultValue) => {
580
+ const defaultForMissing = hasDefaultValue && specificDefaultValue !== res ? specificDefaultValue : resForMissing;
581
+ if (this.options.missingKeyHandler) this.options.missingKeyHandler(l, namespace, k, defaultForMissing, updateMissing, opt);
582
+ else if (this.backendConnector?.saveMissing) this.backendConnector.saveMissing(l, namespace, k, defaultForMissing, updateMissing, opt);
583
+ this.emit("missingKey", l, namespace, k, res);
584
+ };
585
+ if (this.options.saveMissing) if (this.options.saveMissingPlurals && needsPluralHandling) lngs.forEach((language) => {
586
+ const suffixes = this.pluralResolver.getSuffixes(language, opt);
587
+ if (needsZeroSuffixLookup && opt[`defaultValue${this.options.pluralSeparator}zero`] && !suffixes.includes(`${this.options.pluralSeparator}zero`)) suffixes.push(`${this.options.pluralSeparator}zero`);
588
+ suffixes.forEach((suffix) => {
589
+ send([language], key + suffix, opt[`defaultValue${suffix}`] || defaultValue);
590
+ });
591
+ });
592
+ else send(lngs, key, defaultValue);
593
+ }
594
+ res = this.extendTranslation(res, keys, opt, resolved, lastKey);
595
+ if (usedKey && res === key && this.options.appendNamespaceToMissingKey) res = `${namespace}${nsSeparator}${key}`;
596
+ if ((usedKey || usedDefault) && this.options.parseMissingKeyHandler) res = this.options.parseMissingKeyHandler(this.options.appendNamespaceToMissingKey ? `${namespace}${nsSeparator}${key}` : key, usedDefault ? res : void 0, opt);
597
+ }
598
+ if (returnDetails) {
599
+ resolved.res = res;
600
+ resolved.usedParams = this.getUsedParamsDetails(opt);
601
+ return resolved;
602
+ }
603
+ return res;
604
+ }
605
+ extendTranslation(res, key, opt, resolved, lastKey) {
606
+ if (this.i18nFormat?.parse) res = this.i18nFormat.parse(res, {
607
+ ...this.options.interpolation.defaultVariables,
608
+ ...opt
609
+ }, opt.lng || this.language || resolved.usedLng, resolved.usedNS, resolved.usedKey, { resolved });
610
+ else if (!opt.skipInterpolation) {
611
+ if (opt.interpolation) this.interpolator.init({
612
+ ...opt,
613
+ interpolation: {
614
+ ...this.options.interpolation,
615
+ ...opt.interpolation
616
+ }
617
+ });
618
+ const skipOnVariables = isString(res) && (opt?.interpolation?.skipOnVariables !== void 0 ? opt.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables);
619
+ let nestBef;
620
+ if (skipOnVariables) {
621
+ const nb = res.match(this.interpolator.nestingRegexp);
622
+ nestBef = nb && nb.length;
623
+ }
624
+ let data = opt.replace && !isString(opt.replace) ? opt.replace : opt;
625
+ if (this.options.interpolation.defaultVariables) data = {
626
+ ...this.options.interpolation.defaultVariables,
627
+ ...data
628
+ };
629
+ res = this.interpolator.interpolate(res, data, opt.lng || this.language || resolved.usedLng, opt);
630
+ if (skipOnVariables) {
631
+ const na = res.match(this.interpolator.nestingRegexp);
632
+ const nestAft = na && na.length;
633
+ if (nestBef < nestAft) opt.nest = false;
634
+ }
635
+ if (!opt.lng && resolved && resolved.res) opt.lng = this.language || resolved.usedLng;
636
+ if (opt.nest !== false) res = this.interpolator.nest(res, (...args) => {
637
+ if (lastKey?.[0] === args[0] && !opt.context) {
638
+ this.logger.warn(`It seems you are nesting recursively key: ${args[0]} in key: ${key[0]}`);
639
+ return null;
640
+ }
641
+ return this.translate(...args, key);
642
+ }, opt);
643
+ if (opt.interpolation) this.interpolator.reset();
644
+ }
645
+ const postProcess = opt.postProcess || this.options.postProcess;
646
+ const postProcessorNames = isString(postProcess) ? [postProcess] : postProcess;
647
+ if (res != null && postProcessorNames?.length && opt.applyPostProcessor !== false) res = postProcessor.handle(postProcessorNames, res, key, this.options && this.options.postProcessPassResolved ? {
648
+ i18nResolved: {
649
+ ...resolved,
650
+ usedParams: this.getUsedParamsDetails(opt)
651
+ },
652
+ ...opt
653
+ } : opt, this);
654
+ return res;
655
+ }
656
+ resolve(keys, opt = {}) {
657
+ let found;
658
+ let usedKey;
659
+ let exactUsedKey;
660
+ let usedLng;
661
+ let usedNS;
662
+ if (isString(keys)) keys = [keys];
663
+ if (Array.isArray(keys)) keys = keys.map((k) => typeof k === "function" ? keysFromSelector(k, {
664
+ ...this.options,
665
+ ...opt
666
+ }) : k);
667
+ keys.forEach((k) => {
668
+ if (this.isValidLookup(found)) return;
669
+ const extracted = this.extractFromKey(k, opt);
670
+ const key = extracted.key;
671
+ usedKey = key;
672
+ let namespaces = extracted.namespaces;
673
+ if (this.options.fallbackNS) namespaces = namespaces.concat(this.options.fallbackNS);
674
+ const needsPluralHandling = opt.count !== void 0 && !isString(opt.count);
675
+ const needsZeroSuffixLookup = needsPluralHandling && !opt.ordinal && opt.count === 0;
676
+ const needsContextHandling = opt.context !== void 0 && (isString(opt.context) || typeof opt.context === "number") && opt.context !== "";
677
+ const codes = opt.lngs ? opt.lngs : this.languageUtils.toResolveHierarchy(opt.lng || this.language, opt.fallbackLng);
678
+ namespaces.forEach((ns) => {
679
+ if (this.isValidLookup(found)) return;
680
+ usedNS = ns;
681
+ if (!this.checkedLoadedFor[`${codes[0]}-${ns}`] && this.utils?.hasLoadedNamespace && !this.utils?.hasLoadedNamespace(usedNS)) {
682
+ this.checkedLoadedFor[`${codes[0]}-${ns}`] = true;
683
+ this.logger.warn(`key "${usedKey}" for languages "${codes.join(", ")}" won't get resolved as namespace "${usedNS}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
684
+ }
685
+ codes.forEach((code) => {
686
+ if (this.isValidLookup(found)) return;
687
+ usedLng = code;
688
+ const finalKeys = [key];
689
+ if (this.i18nFormat?.addLookupKeys) this.i18nFormat.addLookupKeys(finalKeys, key, code, ns, opt);
690
+ else {
691
+ let pluralSuffix;
692
+ if (needsPluralHandling) pluralSuffix = this.pluralResolver.getSuffix(code, opt.count, opt);
693
+ const zeroSuffix = `${this.options.pluralSeparator}zero`;
694
+ const ordinalPrefix = `${this.options.pluralSeparator}ordinal${this.options.pluralSeparator}`;
695
+ if (needsPluralHandling) {
696
+ if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) finalKeys.push(key + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
697
+ finalKeys.push(key + pluralSuffix);
698
+ if (needsZeroSuffixLookup) finalKeys.push(key + zeroSuffix);
699
+ }
700
+ if (needsContextHandling) {
701
+ const contextKey = `${key}${this.options.contextSeparator || "_"}${opt.context}`;
702
+ finalKeys.push(contextKey);
703
+ if (needsPluralHandling) {
704
+ if (opt.ordinal && pluralSuffix.startsWith(ordinalPrefix)) finalKeys.push(contextKey + pluralSuffix.replace(ordinalPrefix, this.options.pluralSeparator));
705
+ finalKeys.push(contextKey + pluralSuffix);
706
+ if (needsZeroSuffixLookup) finalKeys.push(contextKey + zeroSuffix);
707
+ }
708
+ }
709
+ }
710
+ let possibleKey;
711
+ while (possibleKey = finalKeys.pop()) if (!this.isValidLookup(found)) {
712
+ exactUsedKey = possibleKey;
713
+ found = this.getResource(code, ns, possibleKey, opt);
714
+ }
715
+ });
716
+ });
717
+ });
718
+ return {
719
+ res: found,
720
+ usedKey,
721
+ exactUsedKey,
722
+ usedLng,
723
+ usedNS
724
+ };
725
+ }
726
+ isValidLookup(res) {
727
+ return res !== void 0 && !(!this.options.returnNull && res === null) && !(!this.options.returnEmptyString && res === "");
728
+ }
729
+ getResource(code, ns, key, options = {}) {
730
+ if (this.i18nFormat?.getResource) return this.i18nFormat.getResource(code, ns, key, options);
731
+ return this.resourceStore.getResource(code, ns, key, options);
732
+ }
733
+ getUsedParamsDetails(options = {}) {
734
+ const optionsKeys = [
735
+ "defaultValue",
736
+ "ordinal",
737
+ "context",
738
+ "replace",
739
+ "lng",
740
+ "lngs",
741
+ "fallbackLng",
742
+ "ns",
743
+ "keySeparator",
744
+ "nsSeparator",
745
+ "returnObjects",
746
+ "returnDetails",
747
+ "joinArrays",
748
+ "postProcess",
749
+ "interpolation"
750
+ ];
751
+ const useOptionsReplaceForData = options.replace && !isString(options.replace);
752
+ let data = useOptionsReplaceForData ? options.replace : options;
753
+ if (useOptionsReplaceForData && typeof options.count !== "undefined") data.count = options.count;
754
+ if (this.options.interpolation.defaultVariables) data = {
755
+ ...this.options.interpolation.defaultVariables,
756
+ ...data
757
+ };
758
+ if (!useOptionsReplaceForData) {
759
+ data = { ...data };
760
+ for (const key of optionsKeys) delete data[key];
761
+ }
762
+ return data;
763
+ }
764
+ static hasDefaultValue(options) {
765
+ const prefix = "defaultValue";
766
+ for (const option in options) if (Object.prototype.hasOwnProperty.call(options, option) && option.startsWith(prefix) && void 0 !== options[option]) return true;
767
+ return false;
768
+ }
769
+ };
770
+ var LanguageUtil = class {
771
+ constructor(options) {
772
+ this.options = options;
773
+ this.supportedLngs = this.options.supportedLngs || false;
774
+ this.logger = baseLogger.create("languageUtils");
775
+ }
776
+ getScriptPartFromCode(code) {
777
+ code = getCleanedCode(code);
778
+ if (!code || !code.includes("-")) return null;
779
+ const p = code.split("-");
780
+ if (p.length === 2) return null;
781
+ p.pop();
782
+ if (p[p.length - 1].toLowerCase() === "x") return null;
783
+ return this.formatLanguageCode(p.join("-"));
784
+ }
785
+ getLanguagePartFromCode(code) {
786
+ code = getCleanedCode(code);
787
+ if (!code || !code.includes("-")) return code;
788
+ const p = code.split("-");
789
+ return this.formatLanguageCode(p[0]);
790
+ }
791
+ formatLanguageCode(code) {
792
+ if (isString(code) && code.includes("-")) {
793
+ let formattedCode;
794
+ try {
795
+ formattedCode = Intl.getCanonicalLocales(code)[0];
796
+ } catch (e) {}
797
+ if (formattedCode && this.options.lowerCaseLng) formattedCode = formattedCode.toLowerCase();
798
+ if (formattedCode) return formattedCode;
799
+ if (this.options.lowerCaseLng) return code.toLowerCase();
800
+ return code;
801
+ }
802
+ return this.options.cleanCode || this.options.lowerCaseLng ? code.toLowerCase() : code;
803
+ }
804
+ isSupportedCode(code) {
805
+ if (this.options.load === "languageOnly" || this.options.nonExplicitSupportedLngs) code = this.getLanguagePartFromCode(code);
806
+ return !this.supportedLngs || !this.supportedLngs.length || this.supportedLngs.includes(code);
807
+ }
808
+ getBestMatchFromCodes(codes) {
809
+ if (!codes) return null;
810
+ let found;
811
+ codes.forEach((code) => {
812
+ if (found) return;
813
+ const cleanedLng = this.formatLanguageCode(code);
814
+ if (!this.options.supportedLngs || this.isSupportedCode(cleanedLng)) found = cleanedLng;
815
+ });
816
+ if (!found && this.options.supportedLngs) codes.forEach((code) => {
817
+ if (found) return;
818
+ const lngScOnly = this.getScriptPartFromCode(code);
819
+ if (this.isSupportedCode(lngScOnly)) return found = lngScOnly;
820
+ const lngOnly = this.getLanguagePartFromCode(code);
821
+ if (this.isSupportedCode(lngOnly)) return found = lngOnly;
822
+ found = this.options.supportedLngs.find((supportedLng) => {
823
+ if (supportedLng === lngOnly) return true;
824
+ if (!supportedLng.includes("-") && !lngOnly.includes("-")) return false;
825
+ if (supportedLng.includes("-") && !lngOnly.includes("-") && supportedLng.slice(0, supportedLng.indexOf("-")) === lngOnly) return true;
826
+ if (supportedLng.startsWith(lngOnly) && lngOnly.length > 1) return true;
827
+ return false;
828
+ });
829
+ });
830
+ if (!found) found = this.getFallbackCodes(this.options.fallbackLng)[0];
831
+ return found;
832
+ }
833
+ getFallbackCodes(fallbacks, code) {
834
+ if (!fallbacks) return [];
835
+ if (typeof fallbacks === "function") fallbacks = fallbacks(code);
836
+ if (isString(fallbacks)) fallbacks = [fallbacks];
837
+ if (Array.isArray(fallbacks)) return fallbacks;
838
+ if (!code) return fallbacks.default || [];
839
+ let found = fallbacks[code];
840
+ if (!found) found = fallbacks[this.getScriptPartFromCode(code)];
841
+ if (!found) found = fallbacks[this.formatLanguageCode(code)];
842
+ if (!found) found = fallbacks[this.getLanguagePartFromCode(code)];
843
+ if (!found) found = fallbacks.default;
844
+ return found || [];
845
+ }
846
+ toResolveHierarchy(code, fallbackCode) {
847
+ const fallbackCodes = this.getFallbackCodes((fallbackCode === false ? [] : fallbackCode) || this.options.fallbackLng || [], code);
848
+ const codes = [];
849
+ const addCode = (c) => {
850
+ if (!c) return;
851
+ if (this.isSupportedCode(c)) codes.push(c);
852
+ else this.logger.warn(`rejecting language code not found in supportedLngs: ${c}`);
853
+ };
854
+ if (isString(code) && (code.includes("-") || code.includes("_"))) {
855
+ if (this.options.load !== "languageOnly") addCode(this.formatLanguageCode(code));
856
+ if (this.options.load !== "languageOnly" && this.options.load !== "currentOnly") addCode(this.getScriptPartFromCode(code));
857
+ if (this.options.load !== "currentOnly") addCode(this.getLanguagePartFromCode(code));
858
+ } else if (isString(code)) addCode(this.formatLanguageCode(code));
859
+ fallbackCodes.forEach((fc) => {
860
+ if (!codes.includes(fc)) addCode(this.formatLanguageCode(fc));
861
+ });
862
+ return codes;
863
+ }
864
+ };
865
+ var suffixesOrder = {
866
+ zero: 0,
867
+ one: 1,
868
+ two: 2,
869
+ few: 3,
870
+ many: 4,
871
+ other: 5
872
+ };
873
+ var dummyRule = {
874
+ select: (count) => count === 1 ? "one" : "other",
875
+ resolvedOptions: () => ({ pluralCategories: ["one", "other"] })
876
+ };
877
+ var PluralResolver = class {
878
+ constructor(languageUtils, options = {}) {
879
+ this.languageUtils = languageUtils;
880
+ this.options = options;
881
+ this.logger = baseLogger.create("pluralResolver");
882
+ this.pluralRulesCache = {};
883
+ }
884
+ clearCache() {
885
+ this.pluralRulesCache = {};
886
+ }
887
+ getRule(code, options = {}) {
888
+ const cleanedCode = getCleanedCode(code === "dev" ? "en" : code);
889
+ const type = options.ordinal ? "ordinal" : "cardinal";
890
+ const cacheKey = JSON.stringify({
891
+ cleanedCode,
892
+ type
893
+ });
894
+ if (cacheKey in this.pluralRulesCache) return this.pluralRulesCache[cacheKey];
895
+ let rule;
896
+ try {
897
+ rule = new Intl.PluralRules(cleanedCode, { type });
898
+ } catch (err) {
899
+ if (typeof Intl === "undefined") {
900
+ this.logger.error("No Intl support, please use an Intl polyfill!");
901
+ return dummyRule;
902
+ }
903
+ if (!code.match(/-|_/)) return dummyRule;
904
+ const lngPart = this.languageUtils.getLanguagePartFromCode(code);
905
+ rule = this.getRule(lngPart, options);
906
+ }
907
+ this.pluralRulesCache[cacheKey] = rule;
908
+ return rule;
909
+ }
910
+ needsPlural(code, options = {}) {
911
+ let rule = this.getRule(code, options);
912
+ if (!rule) rule = this.getRule("dev", options);
913
+ return rule?.resolvedOptions().pluralCategories.length > 1;
914
+ }
915
+ getPluralFormsOfKey(code, key, options = {}) {
916
+ return this.getSuffixes(code, options).map((suffix) => `${key}${suffix}`);
917
+ }
918
+ getSuffixes(code, options = {}) {
919
+ let rule = this.getRule(code, options);
920
+ if (!rule) rule = this.getRule("dev", options);
921
+ if (!rule) return [];
922
+ return rule.resolvedOptions().pluralCategories.sort((pluralCategory1, pluralCategory2) => suffixesOrder[pluralCategory1] - suffixesOrder[pluralCategory2]).map((pluralCategory) => `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${pluralCategory}`);
923
+ }
924
+ getSuffix(code, count, options = {}) {
925
+ const rule = this.getRule(code, options);
926
+ if (rule) return `${this.options.prepend}${options.ordinal ? `ordinal${this.options.prepend}` : ""}${rule.select(count)}`;
927
+ this.logger.warn(`no plural rule found for: ${code}`);
928
+ return this.getSuffix("dev", count, options);
929
+ }
930
+ };
931
+ var deepFindWithDefaults = (data, defaultData, key, keySeparator = ".", ignoreJSONStructure = true) => {
932
+ let path = getPathWithDefaults(data, defaultData, key);
933
+ if (!path && ignoreJSONStructure && isString(key)) {
934
+ path = deepFind(data, key, keySeparator);
935
+ if (path === void 0) path = deepFind(defaultData, key, keySeparator);
936
+ }
937
+ return path;
938
+ };
939
+ var regexSafe = (val) => val.replace(/\$/g, "$$$$");
940
+ var Interpolator = class {
941
+ constructor(options = {}) {
942
+ this.logger = baseLogger.create("interpolator");
943
+ this.options = options;
944
+ this.format = options?.interpolation?.format || ((value) => value);
945
+ this.init(options);
946
+ }
947
+ init(options = {}) {
948
+ if (!options.interpolation) options.interpolation = { escapeValue: true };
949
+ const { escape: escape$1, escapeValue, useRawValueToEscape, prefix, prefixEscaped, suffix, suffixEscaped, formatSeparator, unescapeSuffix, unescapePrefix, nestingPrefix, nestingPrefixEscaped, nestingSuffix, nestingSuffixEscaped, nestingOptionsSeparator, maxReplaces, alwaysFormat } = options.interpolation;
950
+ this.escape = escape$1 !== void 0 ? escape$1 : escape;
951
+ this.escapeValue = escapeValue !== void 0 ? escapeValue : true;
952
+ this.useRawValueToEscape = useRawValueToEscape !== void 0 ? useRawValueToEscape : false;
953
+ this.prefix = prefix ? regexEscape(prefix) : prefixEscaped || "{{";
954
+ this.suffix = suffix ? regexEscape(suffix) : suffixEscaped || "}}";
955
+ this.formatSeparator = formatSeparator || ",";
956
+ this.unescapePrefix = unescapeSuffix ? "" : unescapePrefix ? regexEscape(unescapePrefix) : "-";
957
+ this.unescapeSuffix = this.unescapePrefix ? "" : unescapeSuffix ? regexEscape(unescapeSuffix) : "";
958
+ this.nestingPrefix = nestingPrefix ? regexEscape(nestingPrefix) : nestingPrefixEscaped || regexEscape("$t(");
959
+ this.nestingSuffix = nestingSuffix ? regexEscape(nestingSuffix) : nestingSuffixEscaped || regexEscape(")");
960
+ this.nestingOptionsSeparator = nestingOptionsSeparator || ",";
961
+ this.maxReplaces = maxReplaces || 1e3;
962
+ this.alwaysFormat = alwaysFormat !== void 0 ? alwaysFormat : false;
963
+ this.resetRegExp();
964
+ }
965
+ reset() {
966
+ if (this.options) this.init(this.options);
967
+ }
968
+ resetRegExp() {
969
+ const getOrResetRegExp = (existingRegExp, pattern) => {
970
+ if (existingRegExp?.source === pattern) {
971
+ existingRegExp.lastIndex = 0;
972
+ return existingRegExp;
973
+ }
974
+ return new RegExp(pattern, "g");
975
+ };
976
+ this.regexp = getOrResetRegExp(this.regexp, `${this.prefix}(.+?)${this.suffix}`);
977
+ this.regexpUnescape = getOrResetRegExp(this.regexpUnescape, `${this.prefix}${this.unescapePrefix}(.+?)${this.unescapeSuffix}${this.suffix}`);
978
+ this.nestingRegexp = getOrResetRegExp(this.nestingRegexp, `${this.nestingPrefix}((?:[^()"']+|"[^"]*"|'[^']*'|\\((?:[^()]|"[^"]*"|'[^']*')*\\))*?)${this.nestingSuffix}`);
979
+ }
980
+ interpolate(str, data, lng, options) {
981
+ let match;
982
+ let value;
983
+ let replaces;
984
+ const defaultData = this.options && this.options.interpolation && this.options.interpolation.defaultVariables || {};
985
+ const handleFormat = (key) => {
986
+ if (!key.includes(this.formatSeparator)) {
987
+ const path = deepFindWithDefaults(data, defaultData, key, this.options.keySeparator, this.options.ignoreJSONStructure);
988
+ return this.alwaysFormat ? this.format(path, void 0, lng, {
989
+ ...options,
990
+ ...data,
991
+ interpolationkey: key
992
+ }) : path;
993
+ }
994
+ const p = key.split(this.formatSeparator);
995
+ const k = p.shift().trim();
996
+ const f = p.join(this.formatSeparator).trim();
997
+ return this.format(deepFindWithDefaults(data, defaultData, k, this.options.keySeparator, this.options.ignoreJSONStructure), f, lng, {
998
+ ...options,
999
+ ...data,
1000
+ interpolationkey: k
1001
+ });
1002
+ };
1003
+ this.resetRegExp();
1004
+ if (!this.escapeValue && typeof str === "string" && /\$t\([^)]*\{[^}]*\{\{/.test(str)) this.logger.warn("nesting options string contains interpolated variables with escapeValue: false — if any of those values are attacker-controlled they can inject additional nesting options (e.g. redirect lng/ns). Sanitise untrusted input before passing it to t(), or keep escapeValue: true.");
1005
+ const missingInterpolationHandler = options?.missingInterpolationHandler || this.options.missingInterpolationHandler;
1006
+ const skipOnVariables = options?.interpolation?.skipOnVariables !== void 0 ? options.interpolation.skipOnVariables : this.options.interpolation.skipOnVariables;
1007
+ [{
1008
+ regex: this.regexpUnescape,
1009
+ safeValue: (val) => regexSafe(val)
1010
+ }, {
1011
+ regex: this.regexp,
1012
+ safeValue: (val) => this.escapeValue ? regexSafe(this.escape(val)) : regexSafe(val)
1013
+ }].forEach((todo) => {
1014
+ replaces = 0;
1015
+ while (match = todo.regex.exec(str)) {
1016
+ const matchedVar = match[1].trim();
1017
+ value = handleFormat(matchedVar);
1018
+ if (value === void 0) if (typeof missingInterpolationHandler === "function") {
1019
+ const temp = missingInterpolationHandler(str, match, options);
1020
+ value = isString(temp) ? temp : "";
1021
+ } else if (options && Object.prototype.hasOwnProperty.call(options, matchedVar)) value = "";
1022
+ else if (skipOnVariables) {
1023
+ value = match[0];
1024
+ continue;
1025
+ } else {
1026
+ this.logger.warn(`missed to pass in variable ${matchedVar} for interpolating ${str}`);
1027
+ value = "";
1028
+ }
1029
+ else if (!isString(value) && !this.useRawValueToEscape) value = makeString(value);
1030
+ const safeValue = todo.safeValue(value);
1031
+ str = str.replace(match[0], safeValue);
1032
+ if (skipOnVariables) {
1033
+ todo.regex.lastIndex += value.length;
1034
+ todo.regex.lastIndex -= match[0].length;
1035
+ } else todo.regex.lastIndex = 0;
1036
+ replaces++;
1037
+ if (replaces >= this.maxReplaces) break;
1038
+ }
1039
+ });
1040
+ return str;
1041
+ }
1042
+ nest(str, fc, options = {}) {
1043
+ let match;
1044
+ let value;
1045
+ let clonedOptions;
1046
+ const handleHasOptions = (key, inheritedOptions) => {
1047
+ const sep = this.nestingOptionsSeparator;
1048
+ if (!key.includes(sep)) return key;
1049
+ const c = key.split(new RegExp(`${regexEscape(sep)}[ ]*{`));
1050
+ let optionsString = `{${c[1]}`;
1051
+ key = c[0];
1052
+ optionsString = this.interpolate(optionsString, clonedOptions);
1053
+ const matchedSingleQuotes = optionsString.match(/'/g);
1054
+ const matchedDoubleQuotes = optionsString.match(/"/g);
1055
+ if ((matchedSingleQuotes?.length ?? 0) % 2 === 0 && !matchedDoubleQuotes || (matchedDoubleQuotes?.length ?? 0) % 2 !== 0) optionsString = optionsString.replace(/'/g, "\"");
1056
+ try {
1057
+ clonedOptions = JSON.parse(optionsString);
1058
+ if (inheritedOptions) clonedOptions = {
1059
+ ...inheritedOptions,
1060
+ ...clonedOptions
1061
+ };
1062
+ } catch (e) {
1063
+ this.logger.warn(`failed parsing options string in nesting for key ${key}`, e);
1064
+ return `${key}${sep}${optionsString}`;
1065
+ }
1066
+ if (clonedOptions.defaultValue && clonedOptions.defaultValue.includes(this.prefix)) delete clonedOptions.defaultValue;
1067
+ return key;
1068
+ };
1069
+ while (match = this.nestingRegexp.exec(str)) {
1070
+ let formatters = [];
1071
+ clonedOptions = { ...options };
1072
+ clonedOptions = clonedOptions.replace && !isString(clonedOptions.replace) ? clonedOptions.replace : clonedOptions;
1073
+ clonedOptions.applyPostProcessor = false;
1074
+ delete clonedOptions.defaultValue;
1075
+ const keyEndIndex = /{.*}/.test(match[1]) ? match[1].lastIndexOf("}") + 1 : match[1].indexOf(this.formatSeparator);
1076
+ if (keyEndIndex !== -1) {
1077
+ formatters = match[1].slice(keyEndIndex).split(this.formatSeparator).map((elem) => elem.trim()).filter(Boolean);
1078
+ match[1] = match[1].slice(0, keyEndIndex);
1079
+ }
1080
+ value = fc(handleHasOptions.call(this, match[1].trim(), clonedOptions), clonedOptions);
1081
+ if (value && match[0] === str && !isString(value)) return value;
1082
+ if (!isString(value)) value = makeString(value);
1083
+ if (!value) {
1084
+ this.logger.warn(`missed to resolve ${match[1]} for nesting ${str}`);
1085
+ value = "";
1086
+ }
1087
+ if (formatters.length) value = formatters.reduce((v, f) => this.format(v, f, options.lng, {
1088
+ ...options,
1089
+ interpolationkey: match[1].trim()
1090
+ }), value.trim());
1091
+ str = str.replace(match[0], value);
1092
+ this.regexp.lastIndex = 0;
1093
+ }
1094
+ return str;
1095
+ }
1096
+ };
1097
+ var parseFormatStr = (formatStr) => {
1098
+ let formatName = formatStr.toLowerCase().trim();
1099
+ const formatOptions = {};
1100
+ if (formatStr.includes("(")) {
1101
+ const p = formatStr.split("(");
1102
+ formatName = p[0].toLowerCase().trim();
1103
+ const optStr = p[1].slice(0, -1);
1104
+ if (formatName === "currency" && !optStr.includes(":")) {
1105
+ if (!formatOptions.currency) formatOptions.currency = optStr.trim();
1106
+ } else if (formatName === "relativetime" && !optStr.includes(":")) {
1107
+ if (!formatOptions.range) formatOptions.range = optStr.trim();
1108
+ } else optStr.split(";").forEach((opt) => {
1109
+ if (opt) {
1110
+ const [key, ...rest] = opt.split(":");
1111
+ const val = rest.join(":").trim().replace(/^'+|'+$/g, "");
1112
+ const trimmedKey = key.trim();
1113
+ if (!formatOptions[trimmedKey]) formatOptions[trimmedKey] = val;
1114
+ if (val === "false") formatOptions[trimmedKey] = false;
1115
+ if (val === "true") formatOptions[trimmedKey] = true;
1116
+ if (!isNaN(val)) formatOptions[trimmedKey] = parseInt(val, 10);
1117
+ }
1118
+ });
1119
+ }
1120
+ return {
1121
+ formatName,
1122
+ formatOptions
1123
+ };
1124
+ };
1125
+ var createCachedFormatter = (fn) => {
1126
+ const cache = {};
1127
+ return (v, l, o) => {
1128
+ let optForCache = o;
1129
+ if (o && o.interpolationkey && o.formatParams && o.formatParams[o.interpolationkey] && o[o.interpolationkey]) optForCache = {
1130
+ ...optForCache,
1131
+ [o.interpolationkey]: void 0
1132
+ };
1133
+ const key = l + JSON.stringify(optForCache);
1134
+ let frm = cache[key];
1135
+ if (!frm) {
1136
+ frm = fn(getCleanedCode(l), o);
1137
+ cache[key] = frm;
1138
+ }
1139
+ return frm(v);
1140
+ };
1141
+ };
1142
+ var createNonCachedFormatter = (fn) => (v, l, o) => fn(getCleanedCode(l), o)(v);
1143
+ var Formatter = class {
1144
+ constructor(options = {}) {
1145
+ this.logger = baseLogger.create("formatter");
1146
+ this.options = options;
1147
+ this.init(options);
1148
+ }
1149
+ init(services, options = { interpolation: {} }) {
1150
+ this.formatSeparator = options.interpolation.formatSeparator || ",";
1151
+ const cf = options.cacheInBuiltFormats ? createCachedFormatter : createNonCachedFormatter;
1152
+ this.formats = {
1153
+ number: cf((lng, opt) => {
1154
+ const formatter = new Intl.NumberFormat(lng, { ...opt });
1155
+ return (val) => formatter.format(val);
1156
+ }),
1157
+ currency: cf((lng, opt) => {
1158
+ const formatter = new Intl.NumberFormat(lng, {
1159
+ ...opt,
1160
+ style: "currency"
1161
+ });
1162
+ return (val) => formatter.format(val);
1163
+ }),
1164
+ datetime: cf((lng, opt) => {
1165
+ const formatter = new Intl.DateTimeFormat(lng, { ...opt });
1166
+ return (val) => formatter.format(val);
1167
+ }),
1168
+ relativetime: cf((lng, opt) => {
1169
+ const formatter = new Intl.RelativeTimeFormat(lng, { ...opt });
1170
+ return (val) => formatter.format(val, opt.range || "day");
1171
+ }),
1172
+ list: cf((lng, opt) => {
1173
+ const formatter = new Intl.ListFormat(lng, { ...opt });
1174
+ return (val) => formatter.format(val);
1175
+ })
1176
+ };
1177
+ }
1178
+ add(name, fc) {
1179
+ this.formats[name.toLowerCase().trim()] = fc;
1180
+ }
1181
+ addCached(name, fc) {
1182
+ this.formats[name.toLowerCase().trim()] = createCachedFormatter(fc);
1183
+ }
1184
+ format(value, format, lng, options = {}) {
1185
+ if (!format) return value;
1186
+ if (value == null) return value;
1187
+ const formats = format.split(this.formatSeparator);
1188
+ if (formats.length > 1 && formats[0].indexOf("(") > 1 && !formats[0].includes(")") && formats.find((f) => f.includes(")"))) {
1189
+ const lastIndex = formats.findIndex((f) => f.includes(")"));
1190
+ formats[0] = [formats[0], ...formats.splice(1, lastIndex)].join(this.formatSeparator);
1191
+ }
1192
+ return formats.reduce((mem, f) => {
1193
+ const { formatName, formatOptions } = parseFormatStr(f);
1194
+ if (this.formats[formatName]) {
1195
+ let formatted = mem;
1196
+ try {
1197
+ const valOptions = options?.formatParams?.[options.interpolationkey] || {};
1198
+ const l = valOptions.locale || valOptions.lng || options.locale || options.lng || lng;
1199
+ formatted = this.formats[formatName](mem, l, {
1200
+ ...formatOptions,
1201
+ ...options,
1202
+ ...valOptions
1203
+ });
1204
+ } catch (error) {
1205
+ this.logger.warn(error);
1206
+ }
1207
+ return formatted;
1208
+ } else this.logger.warn(`there was no format function for ${formatName}`);
1209
+ return mem;
1210
+ }, value);
1211
+ }
1212
+ };
1213
+ var removePending = (q, name) => {
1214
+ if (q.pending[name] !== void 0) {
1215
+ delete q.pending[name];
1216
+ q.pendingCount--;
1217
+ }
1218
+ };
1219
+ var Connector = class extends EventEmitter {
1220
+ constructor(backend, store, services, options = {}) {
1221
+ super();
1222
+ this.backend = backend;
1223
+ this.store = store;
1224
+ this.services = services;
1225
+ this.languageUtils = services.languageUtils;
1226
+ this.options = options;
1227
+ this.logger = baseLogger.create("backendConnector");
1228
+ this.waitingReads = [];
1229
+ this.maxParallelReads = options.maxParallelReads || 10;
1230
+ this.readingCalls = 0;
1231
+ this.maxRetries = options.maxRetries >= 0 ? options.maxRetries : 5;
1232
+ this.retryTimeout = options.retryTimeout >= 1 ? options.retryTimeout : 350;
1233
+ this.state = {};
1234
+ this.queue = [];
1235
+ this.backend?.init?.(services, options.backend, options);
1236
+ }
1237
+ queueLoad(languages, namespaces, options, callback) {
1238
+ const toLoad = {};
1239
+ const pending = {};
1240
+ const toLoadLanguages = {};
1241
+ const toLoadNamespaces = {};
1242
+ languages.forEach((lng) => {
1243
+ let hasAllNamespaces = true;
1244
+ namespaces.forEach((ns) => {
1245
+ const name = `${lng}|${ns}`;
1246
+ if (!options.reload && this.store.hasResourceBundle(lng, ns)) this.state[name] = 2;
1247
+ else if (this.state[name] < 0);
1248
+ else if (this.state[name] === 1) {
1249
+ if (pending[name] === void 0) pending[name] = true;
1250
+ } else {
1251
+ this.state[name] = 1;
1252
+ hasAllNamespaces = false;
1253
+ if (pending[name] === void 0) pending[name] = true;
1254
+ if (toLoad[name] === void 0) toLoad[name] = true;
1255
+ if (toLoadNamespaces[ns] === void 0) toLoadNamespaces[ns] = true;
1256
+ }
1257
+ });
1258
+ if (!hasAllNamespaces) toLoadLanguages[lng] = true;
1259
+ });
1260
+ if (Object.keys(toLoad).length || Object.keys(pending).length) this.queue.push({
1261
+ pending,
1262
+ pendingCount: Object.keys(pending).length,
1263
+ loaded: {},
1264
+ errors: [],
1265
+ callback
1266
+ });
1267
+ return {
1268
+ toLoad: Object.keys(toLoad),
1269
+ pending: Object.keys(pending),
1270
+ toLoadLanguages: Object.keys(toLoadLanguages),
1271
+ toLoadNamespaces: Object.keys(toLoadNamespaces)
1272
+ };
1273
+ }
1274
+ loaded(name, err, data) {
1275
+ const s = name.split("|");
1276
+ const lng = s[0];
1277
+ const ns = s[1];
1278
+ if (err) this.emit("failedLoading", lng, ns, err);
1279
+ if (!err && data) this.store.addResourceBundle(lng, ns, data, void 0, void 0, { skipCopy: true });
1280
+ this.state[name] = err ? -1 : 2;
1281
+ if (err && data) this.state[name] = 0;
1282
+ const loaded = {};
1283
+ this.queue.forEach((q) => {
1284
+ pushPath(q.loaded, [lng], ns);
1285
+ removePending(q, name);
1286
+ if (err) q.errors.push(err);
1287
+ if (q.pendingCount === 0 && !q.done) {
1288
+ Object.keys(q.loaded).forEach((l) => {
1289
+ if (!loaded[l]) loaded[l] = {};
1290
+ const loadedKeys = q.loaded[l];
1291
+ if (loadedKeys.length) loadedKeys.forEach((n) => {
1292
+ if (loaded[l][n] === void 0) loaded[l][n] = true;
1293
+ });
1294
+ });
1295
+ q.done = true;
1296
+ if (q.errors.length) q.callback(q.errors);
1297
+ else q.callback();
1298
+ }
1299
+ });
1300
+ this.emit("loaded", loaded);
1301
+ this.queue = this.queue.filter((q) => !q.done);
1302
+ }
1303
+ read(lng, ns, fcName, tried = 0, wait = this.retryTimeout, callback) {
1304
+ if (!lng.length) return callback(null, {});
1305
+ if (this.readingCalls >= this.maxParallelReads) {
1306
+ this.waitingReads.push({
1307
+ lng,
1308
+ ns,
1309
+ fcName,
1310
+ tried,
1311
+ wait,
1312
+ callback
1313
+ });
1314
+ return;
1315
+ }
1316
+ this.readingCalls++;
1317
+ const resolver = (err, data) => {
1318
+ this.readingCalls--;
1319
+ if (this.waitingReads.length > 0) {
1320
+ const next = this.waitingReads.shift();
1321
+ this.read(next.lng, next.ns, next.fcName, next.tried, next.wait, next.callback);
1322
+ }
1323
+ if (err && data && tried < this.maxRetries) {
1324
+ setTimeout(() => {
1325
+ this.read(lng, ns, fcName, tried + 1, wait * 2, callback);
1326
+ }, wait);
1327
+ return;
1328
+ }
1329
+ callback(err, data);
1330
+ };
1331
+ const fc = this.backend[fcName].bind(this.backend);
1332
+ if (fc.length === 2) {
1333
+ try {
1334
+ const r = fc(lng, ns);
1335
+ if (r && typeof r.then === "function") r.then((data) => resolver(null, data)).catch(resolver);
1336
+ else resolver(null, r);
1337
+ } catch (err) {
1338
+ resolver(err);
1339
+ }
1340
+ return;
1341
+ }
1342
+ return fc(lng, ns, resolver);
1343
+ }
1344
+ prepareLoading(languages, namespaces, options = {}, callback) {
1345
+ if (!this.backend) {
1346
+ this.logger.warn("No backend was added via i18next.use. Will not load resources.");
1347
+ return callback && callback();
1348
+ }
1349
+ if (isString(languages)) languages = this.languageUtils.toResolveHierarchy(languages);
1350
+ if (isString(namespaces)) namespaces = [namespaces];
1351
+ const toLoad = this.queueLoad(languages, namespaces, options, callback);
1352
+ if (!toLoad.toLoad.length) {
1353
+ if (!toLoad.pending.length) callback();
1354
+ return null;
1355
+ }
1356
+ toLoad.toLoad.forEach((name) => {
1357
+ this.loadOne(name);
1358
+ });
1359
+ }
1360
+ load(languages, namespaces, callback) {
1361
+ this.prepareLoading(languages, namespaces, {}, callback);
1362
+ }
1363
+ reload(languages, namespaces, callback) {
1364
+ this.prepareLoading(languages, namespaces, { reload: true }, callback);
1365
+ }
1366
+ loadOne(name, prefix = "") {
1367
+ const s = name.split("|");
1368
+ const lng = s[0];
1369
+ const ns = s[1];
1370
+ this.read(lng, ns, "read", void 0, void 0, (err, data) => {
1371
+ if (err) this.logger.warn(`${prefix}loading namespace ${ns} for language ${lng} failed`, err);
1372
+ if (!err && data) this.logger.log(`${prefix}loaded namespace ${ns} for language ${lng}`, data);
1373
+ this.loaded(name, err, data);
1374
+ });
1375
+ }
1376
+ saveMissing(languages, namespace, key, fallbackValue, isUpdate, options = {}, clb = () => {}) {
1377
+ if (this.services?.utils?.hasLoadedNamespace && !this.services?.utils?.hasLoadedNamespace(namespace)) {
1378
+ this.logger.warn(`did not save key "${key}" as the namespace "${namespace}" was not yet loaded`, "This means something IS WRONG in your setup. You access the t function before i18next.init / i18next.loadNamespace / i18next.changeLanguage was done. Wait for the callback or Promise to resolve before accessing it!!!");
1379
+ return;
1380
+ }
1381
+ if (key === void 0 || key === null || key === "") return;
1382
+ if (this.backend?.create) {
1383
+ const opts = {
1384
+ ...options,
1385
+ isUpdate
1386
+ };
1387
+ const fc = this.backend.create.bind(this.backend);
1388
+ if (fc.length < 6) try {
1389
+ let r;
1390
+ if (fc.length === 5) r = fc(languages, namespace, key, fallbackValue, opts);
1391
+ else r = fc(languages, namespace, key, fallbackValue);
1392
+ if (r && typeof r.then === "function") r.then((data) => clb(null, data)).catch(clb);
1393
+ else clb(null, r);
1394
+ } catch (err) {
1395
+ clb(err);
1396
+ }
1397
+ else fc(languages, namespace, key, fallbackValue, clb, opts);
1398
+ }
1399
+ if (!languages || !languages[0]) return;
1400
+ this.store.addResource(languages[0], namespace, key, fallbackValue);
1401
+ }
1402
+ };
1403
+ var get = () => ({
1404
+ debug: false,
1405
+ initAsync: true,
1406
+ ns: ["translation"],
1407
+ defaultNS: ["translation"],
1408
+ fallbackLng: ["dev"],
1409
+ fallbackNS: false,
1410
+ supportedLngs: false,
1411
+ nonExplicitSupportedLngs: false,
1412
+ load: "all",
1413
+ preload: false,
1414
+ keySeparator: ".",
1415
+ nsSeparator: ":",
1416
+ pluralSeparator: "_",
1417
+ contextSeparator: "_",
1418
+ enableSelector: false,
1419
+ partialBundledLanguages: false,
1420
+ saveMissing: false,
1421
+ updateMissing: false,
1422
+ saveMissingTo: "fallback",
1423
+ saveMissingPlurals: true,
1424
+ missingKeyHandler: false,
1425
+ missingInterpolationHandler: false,
1426
+ postProcess: false,
1427
+ postProcessPassResolved: false,
1428
+ returnNull: false,
1429
+ returnEmptyString: true,
1430
+ returnObjects: false,
1431
+ joinArrays: false,
1432
+ returnedObjectHandler: false,
1433
+ parseMissingKeyHandler: false,
1434
+ appendNamespaceToMissingKey: false,
1435
+ appendNamespaceToCIMode: false,
1436
+ overloadTranslationOptionHandler: (args) => {
1437
+ let ret = {};
1438
+ if (typeof args[1] === "object") ret = args[1];
1439
+ if (isString(args[1])) ret.defaultValue = args[1];
1440
+ if (isString(args[2])) ret.tDescription = args[2];
1441
+ if (typeof args[2] === "object" || typeof args[3] === "object") {
1442
+ const options = args[3] || args[2];
1443
+ Object.keys(options).forEach((key) => {
1444
+ ret[key] = options[key];
1445
+ });
1446
+ }
1447
+ return ret;
1448
+ },
1449
+ interpolation: {
1450
+ escapeValue: true,
1451
+ prefix: "{{",
1452
+ suffix: "}}",
1453
+ formatSeparator: ",",
1454
+ unescapePrefix: "-",
1455
+ nestingPrefix: "$t(",
1456
+ nestingSuffix: ")",
1457
+ nestingOptionsSeparator: ",",
1458
+ maxReplaces: 1e3,
1459
+ skipOnVariables: true
1460
+ },
1461
+ cacheInBuiltFormats: true
1462
+ });
1463
+ var transformOptions = (options) => {
1464
+ if (isString(options.ns)) options.ns = [options.ns];
1465
+ if (isString(options.fallbackLng)) options.fallbackLng = [options.fallbackLng];
1466
+ if (isString(options.fallbackNS)) options.fallbackNS = [options.fallbackNS];
1467
+ if (options.supportedLngs && !options.supportedLngs.includes("cimode")) options.supportedLngs = options.supportedLngs.concat(["cimode"]);
1468
+ return options;
1469
+ };
1470
+ var noop = () => {};
1471
+ var bindMemberFunctions = (inst) => {
1472
+ Object.getOwnPropertyNames(Object.getPrototypeOf(inst)).forEach((mem) => {
1473
+ if (typeof inst[mem] === "function") inst[mem] = inst[mem].bind(inst);
1474
+ });
1475
+ };
1476
+ var instance = class I18n extends EventEmitter {
1477
+ constructor(options = {}, callback) {
1478
+ super();
1479
+ this.options = transformOptions(options);
1480
+ this.services = {};
1481
+ this.logger = baseLogger;
1482
+ this.modules = { external: [] };
1483
+ bindMemberFunctions(this);
1484
+ if (callback && !this.isInitialized && !options.isClone) {
1485
+ if (!this.options.initAsync) {
1486
+ this.init(options, callback);
1487
+ return this;
1488
+ }
1489
+ setTimeout(() => {
1490
+ this.init(options, callback);
1491
+ }, 0);
1492
+ }
1493
+ }
1494
+ init(options = {}, callback) {
1495
+ this.isInitializing = true;
1496
+ if (typeof options === "function") {
1497
+ callback = options;
1498
+ options = {};
1499
+ }
1500
+ if (options.defaultNS == null && options.ns) {
1501
+ if (isString(options.ns)) options.defaultNS = options.ns;
1502
+ else if (!options.ns.includes("translation")) options.defaultNS = options.ns[0];
1503
+ }
1504
+ const defOpts = get();
1505
+ this.options = {
1506
+ ...defOpts,
1507
+ ...this.options,
1508
+ ...transformOptions(options)
1509
+ };
1510
+ this.options.interpolation = {
1511
+ ...defOpts.interpolation,
1512
+ ...this.options.interpolation
1513
+ };
1514
+ if (options.keySeparator !== void 0) this.options.userDefinedKeySeparator = options.keySeparator;
1515
+ if (options.nsSeparator !== void 0) this.options.userDefinedNsSeparator = options.nsSeparator;
1516
+ if (typeof this.options.overloadTranslationOptionHandler !== "function") this.options.overloadTranslationOptionHandler = defOpts.overloadTranslationOptionHandler;
1517
+ const createClassOnDemand = (ClassOrObject) => {
1518
+ if (!ClassOrObject) return null;
1519
+ if (typeof ClassOrObject === "function") return new ClassOrObject();
1520
+ return ClassOrObject;
1521
+ };
1522
+ if (!this.options.isClone) {
1523
+ if (this.modules.logger) baseLogger.init(createClassOnDemand(this.modules.logger), this.options);
1524
+ else baseLogger.init(null, this.options);
1525
+ let formatter;
1526
+ if (this.modules.formatter) formatter = this.modules.formatter;
1527
+ else formatter = Formatter;
1528
+ const lu = new LanguageUtil(this.options);
1529
+ this.store = new ResourceStore(this.options.resources, this.options);
1530
+ const s = this.services;
1531
+ s.logger = baseLogger;
1532
+ s.resourceStore = this.store;
1533
+ s.languageUtils = lu;
1534
+ s.pluralResolver = new PluralResolver(lu, { prepend: this.options.pluralSeparator });
1535
+ if (formatter) {
1536
+ s.formatter = createClassOnDemand(formatter);
1537
+ if (s.formatter.init) s.formatter.init(s, this.options);
1538
+ this.options.interpolation.format = s.formatter.format.bind(s.formatter);
1539
+ }
1540
+ s.interpolator = new Interpolator(this.options);
1541
+ s.utils = { hasLoadedNamespace: this.hasLoadedNamespace.bind(this) };
1542
+ s.backendConnector = new Connector(createClassOnDemand(this.modules.backend), s.resourceStore, s, this.options);
1543
+ s.backendConnector.on("*", (event, ...args) => {
1544
+ this.emit(event, ...args);
1545
+ });
1546
+ if (this.modules.languageDetector) {
1547
+ s.languageDetector = createClassOnDemand(this.modules.languageDetector);
1548
+ if (s.languageDetector.init) s.languageDetector.init(s, this.options.detection, this.options);
1549
+ }
1550
+ if (this.modules.i18nFormat) {
1551
+ s.i18nFormat = createClassOnDemand(this.modules.i18nFormat);
1552
+ if (s.i18nFormat.init) s.i18nFormat.init(this);
1553
+ }
1554
+ this.translator = new Translator(this.services, this.options);
1555
+ this.translator.on("*", (event, ...args) => {
1556
+ this.emit(event, ...args);
1557
+ });
1558
+ this.modules.external.forEach((m) => {
1559
+ if (m.init) m.init(this);
1560
+ });
1561
+ }
1562
+ this.format = this.options.interpolation.format;
1563
+ if (!callback) callback = noop;
1564
+ if (this.options.fallbackLng && !this.services.languageDetector && !this.options.lng) {
1565
+ const codes = this.services.languageUtils.getFallbackCodes(this.options.fallbackLng);
1566
+ if (codes.length > 0 && codes[0] !== "dev") this.options.lng = codes[0];
1567
+ }
1568
+ if (!this.services.languageDetector && !this.options.lng) this.logger.warn("init: no languageDetector is used and no lng is defined");
1569
+ [
1570
+ "getResource",
1571
+ "hasResourceBundle",
1572
+ "getResourceBundle",
1573
+ "getDataByLanguage"
1574
+ ].forEach((fcName) => {
1575
+ this[fcName] = (...args) => this.store[fcName](...args);
1576
+ });
1577
+ [
1578
+ "addResource",
1579
+ "addResources",
1580
+ "addResourceBundle",
1581
+ "removeResourceBundle"
1582
+ ].forEach((fcName) => {
1583
+ this[fcName] = (...args) => {
1584
+ this.store[fcName](...args);
1585
+ return this;
1586
+ };
1587
+ });
1588
+ const deferred = defer();
1589
+ const load = () => {
1590
+ const finish = (err, t) => {
1591
+ this.isInitializing = false;
1592
+ if (this.isInitialized && !this.initializedStoreOnce) this.logger.warn("init: i18next is already initialized. You should call init just once!");
1593
+ this.isInitialized = true;
1594
+ if (!this.options.isClone) this.logger.log("initialized", this.options);
1595
+ this.emit("initialized", this.options);
1596
+ deferred.resolve(t);
1597
+ callback(err, t);
1598
+ };
1599
+ if ((this.languages || this.isLanguageChangingTo) && !this.isInitialized) return finish(null, this.t.bind(this));
1600
+ this.changeLanguage(this.options.lng, finish);
1601
+ };
1602
+ if (this.options.resources || !this.options.initAsync) load();
1603
+ else setTimeout(load, 0);
1604
+ return deferred;
1605
+ }
1606
+ loadResources(language, callback = noop) {
1607
+ let usedCallback = callback;
1608
+ const usedLng = isString(language) ? language : this.language;
1609
+ if (typeof language === "function") usedCallback = language;
1610
+ if (!this.options.resources || this.options.partialBundledLanguages) {
1611
+ if (usedLng?.toLowerCase() === "cimode" && (!this.options.preload || this.options.preload.length === 0)) return usedCallback();
1612
+ const toLoad = [];
1613
+ const append = (lng) => {
1614
+ if (!lng) return;
1615
+ if (lng === "cimode") return;
1616
+ this.services.languageUtils.toResolveHierarchy(lng).forEach((l) => {
1617
+ if (l === "cimode") return;
1618
+ if (!toLoad.includes(l)) toLoad.push(l);
1619
+ });
1620
+ };
1621
+ if (!usedLng) this.services.languageUtils.getFallbackCodes(this.options.fallbackLng).forEach((l) => append(l));
1622
+ else append(usedLng);
1623
+ this.options.preload?.forEach?.((l) => append(l));
1624
+ this.services.backendConnector.load(toLoad, this.options.ns, (e) => {
1625
+ if (!e && !this.resolvedLanguage && this.language) this.setResolvedLanguage(this.language);
1626
+ usedCallback(e);
1627
+ });
1628
+ } else usedCallback(null);
1629
+ }
1630
+ reloadResources(lngs, ns, callback) {
1631
+ const deferred = defer();
1632
+ if (typeof lngs === "function") {
1633
+ callback = lngs;
1634
+ lngs = void 0;
1635
+ }
1636
+ if (typeof ns === "function") {
1637
+ callback = ns;
1638
+ ns = void 0;
1639
+ }
1640
+ if (!lngs) lngs = this.languages;
1641
+ if (!ns) ns = this.options.ns;
1642
+ if (!callback) callback = noop;
1643
+ this.services.backendConnector.reload(lngs, ns, (err) => {
1644
+ deferred.resolve();
1645
+ callback(err);
1646
+ });
1647
+ return deferred;
1648
+ }
1649
+ use(module) {
1650
+ if (!module) throw new Error("You are passing an undefined module! Please check the object you are passing to i18next.use()");
1651
+ if (!module.type) throw new Error("You are passing a wrong module! Please check the object you are passing to i18next.use()");
1652
+ if (module.type === "backend") this.modules.backend = module;
1653
+ if (module.type === "logger" || module.log && module.warn && module.error) this.modules.logger = module;
1654
+ if (module.type === "languageDetector") this.modules.languageDetector = module;
1655
+ if (module.type === "i18nFormat") this.modules.i18nFormat = module;
1656
+ if (module.type === "postProcessor") postProcessor.addPostProcessor(module);
1657
+ if (module.type === "formatter") this.modules.formatter = module;
1658
+ if (module.type === "3rdParty") this.modules.external.push(module);
1659
+ return this;
1660
+ }
1661
+ setResolvedLanguage(l) {
1662
+ if (!l || !this.languages) return;
1663
+ if (["cimode", "dev"].includes(l)) return;
1664
+ for (let li = 0; li < this.languages.length; li++) {
1665
+ const lngInLngs = this.languages[li];
1666
+ if (["cimode", "dev"].includes(lngInLngs)) continue;
1667
+ if (this.store.hasLanguageSomeTranslations(lngInLngs)) {
1668
+ this.resolvedLanguage = lngInLngs;
1669
+ break;
1670
+ }
1671
+ }
1672
+ if (!this.resolvedLanguage && !this.languages.includes(l) && this.store.hasLanguageSomeTranslations(l)) {
1673
+ this.resolvedLanguage = l;
1674
+ this.languages.unshift(l);
1675
+ }
1676
+ }
1677
+ changeLanguage(lng, callback) {
1678
+ this.isLanguageChangingTo = lng;
1679
+ const deferred = defer();
1680
+ this.emit("languageChanging", lng);
1681
+ const setLngProps = (l) => {
1682
+ this.language = l;
1683
+ this.languages = this.services.languageUtils.toResolveHierarchy(l);
1684
+ this.resolvedLanguage = void 0;
1685
+ this.setResolvedLanguage(l);
1686
+ };
1687
+ const done = (err, l) => {
1688
+ if (l) {
1689
+ if (this.isLanguageChangingTo === lng) {
1690
+ setLngProps(l);
1691
+ this.translator.changeLanguage(l);
1692
+ this.isLanguageChangingTo = void 0;
1693
+ this.emit("languageChanged", l);
1694
+ this.logger.log("languageChanged", l);
1695
+ }
1696
+ } else this.isLanguageChangingTo = void 0;
1697
+ deferred.resolve((...args) => this.t(...args));
1698
+ if (callback) callback(err, (...args) => this.t(...args));
1699
+ };
1700
+ const setLng = (lngs) => {
1701
+ if (!lng && !lngs && this.services.languageDetector) lngs = [];
1702
+ const fl = isString(lngs) ? lngs : lngs && lngs[0];
1703
+ const l = this.store.hasLanguageSomeTranslations(fl) ? fl : this.services.languageUtils.getBestMatchFromCodes(isString(lngs) ? [lngs] : lngs);
1704
+ if (l) {
1705
+ if (!this.language) setLngProps(l);
1706
+ if (!this.translator.language) this.translator.changeLanguage(l);
1707
+ this.services.languageDetector?.cacheUserLanguage?.(l);
1708
+ }
1709
+ this.loadResources(l, (err) => {
1710
+ done(err, l);
1711
+ });
1712
+ };
1713
+ if (!lng && this.services.languageDetector && !this.services.languageDetector.async) setLng(this.services.languageDetector.detect());
1714
+ else if (!lng && this.services.languageDetector && this.services.languageDetector.async) if (this.services.languageDetector.detect.length === 0) this.services.languageDetector.detect().then(setLng);
1715
+ else this.services.languageDetector.detect(setLng);
1716
+ else setLng(lng);
1717
+ return deferred;
1718
+ }
1719
+ getFixedT(lng, ns, keyPrefix, fixedOpts) {
1720
+ const scopeNs = fixedOpts?.scopeNs;
1721
+ const fixedT = (key, opts, ...rest) => {
1722
+ let o;
1723
+ if (typeof opts !== "object") o = this.options.overloadTranslationOptionHandler([key, opts].concat(rest));
1724
+ else o = { ...opts };
1725
+ o.lng = o.lng || fixedT.lng;
1726
+ o.lngs = o.lngs || fixedT.lngs;
1727
+ const explicitCallNs = o.ns !== void 0 && o.ns !== null;
1728
+ o.ns = o.ns || fixedT.ns;
1729
+ if (o.keyPrefix !== "") o.keyPrefix = o.keyPrefix || keyPrefix || fixedT.keyPrefix;
1730
+ const selectorOpts = {
1731
+ ...this.options,
1732
+ ...o
1733
+ };
1734
+ if (Array.isArray(scopeNs) && !explicitCallNs) selectorOpts.ns = scopeNs;
1735
+ if (typeof o.keyPrefix === "function") o.keyPrefix = keysFromSelector(o.keyPrefix, selectorOpts);
1736
+ const keySeparator = this.options.keySeparator || ".";
1737
+ let resultKey;
1738
+ if (o.keyPrefix && Array.isArray(key)) resultKey = key.map((k) => {
1739
+ if (typeof k === "function") k = keysFromSelector(k, selectorOpts);
1740
+ return `${o.keyPrefix}${keySeparator}${k}`;
1741
+ });
1742
+ else {
1743
+ if (typeof key === "function") key = keysFromSelector(key, selectorOpts);
1744
+ resultKey = o.keyPrefix ? `${o.keyPrefix}${keySeparator}${key}` : key;
1745
+ }
1746
+ return this.t(resultKey, o);
1747
+ };
1748
+ if (isString(lng)) fixedT.lng = lng;
1749
+ else fixedT.lngs = lng;
1750
+ fixedT.ns = ns;
1751
+ fixedT.keyPrefix = keyPrefix;
1752
+ return fixedT;
1753
+ }
1754
+ t(...args) {
1755
+ return this.translator?.translate(...args);
1756
+ }
1757
+ exists(...args) {
1758
+ return this.translator?.exists(...args);
1759
+ }
1760
+ setDefaultNamespace(ns) {
1761
+ this.options.defaultNS = ns;
1762
+ }
1763
+ hasLoadedNamespace(ns, options = {}) {
1764
+ if (!this.isInitialized) {
1765
+ this.logger.warn("hasLoadedNamespace: i18next was not initialized", this.languages);
1766
+ return false;
1767
+ }
1768
+ if (!this.languages || !this.languages.length) {
1769
+ this.logger.warn("hasLoadedNamespace: i18n.languages were undefined or empty", this.languages);
1770
+ return false;
1771
+ }
1772
+ const lng = options.lng || this.resolvedLanguage || this.languages[0];
1773
+ const fallbackLng = this.options ? this.options.fallbackLng : false;
1774
+ const lastLng = this.languages[this.languages.length - 1];
1775
+ if (lng.toLowerCase() === "cimode") return true;
1776
+ const loadNotPending = (l, n) => {
1777
+ const loadState = this.services.backendConnector.state[`${l}|${n}`];
1778
+ return loadState === -1 || loadState === 0 || loadState === 2;
1779
+ };
1780
+ if (options.precheck) {
1781
+ const preResult = options.precheck(this, loadNotPending);
1782
+ if (preResult !== void 0) return preResult;
1783
+ }
1784
+ if (this.hasResourceBundle(lng, ns)) return true;
1785
+ if (!this.services.backendConnector.backend || this.options.resources && !this.options.partialBundledLanguages) return true;
1786
+ if (loadNotPending(lng, ns) && (!fallbackLng || loadNotPending(lastLng, ns))) return true;
1787
+ return false;
1788
+ }
1789
+ loadNamespaces(ns, callback) {
1790
+ const deferred = defer();
1791
+ if (!this.options.ns) {
1792
+ if (callback) callback();
1793
+ return Promise.resolve();
1794
+ }
1795
+ if (isString(ns)) ns = [ns];
1796
+ ns.forEach((n) => {
1797
+ if (!this.options.ns.includes(n)) this.options.ns.push(n);
1798
+ });
1799
+ this.loadResources((err) => {
1800
+ deferred.resolve();
1801
+ if (callback) callback(err);
1802
+ });
1803
+ return deferred;
1804
+ }
1805
+ loadLanguages(lngs, callback) {
1806
+ const deferred = defer();
1807
+ if (isString(lngs)) lngs = [lngs];
1808
+ const preloaded = this.options.preload || [];
1809
+ const newLngs = lngs.filter((lng) => !preloaded.includes(lng) && this.services.languageUtils.isSupportedCode(lng));
1810
+ if (!newLngs.length) {
1811
+ if (callback) callback();
1812
+ return Promise.resolve();
1813
+ }
1814
+ this.options.preload = preloaded.concat(newLngs);
1815
+ this.loadResources((err) => {
1816
+ deferred.resolve();
1817
+ if (callback) callback(err);
1818
+ });
1819
+ return deferred;
1820
+ }
1821
+ dir(lng) {
1822
+ if (!lng) lng = this.resolvedLanguage || (this.languages?.length > 0 ? this.languages[0] : this.language);
1823
+ if (!lng) return "rtl";
1824
+ try {
1825
+ const l = new Intl.Locale(lng);
1826
+ if (l && l.getTextInfo) {
1827
+ const ti = l.getTextInfo();
1828
+ if (ti && ti.direction) return ti.direction;
1829
+ }
1830
+ } catch (e) {}
1831
+ const rtlLngs = [
1832
+ "ar",
1833
+ "shu",
1834
+ "sqr",
1835
+ "ssh",
1836
+ "xaa",
1837
+ "yhd",
1838
+ "yud",
1839
+ "aao",
1840
+ "abh",
1841
+ "abv",
1842
+ "acm",
1843
+ "acq",
1844
+ "acw",
1845
+ "acx",
1846
+ "acy",
1847
+ "adf",
1848
+ "ads",
1849
+ "aeb",
1850
+ "aec",
1851
+ "afb",
1852
+ "ajp",
1853
+ "apc",
1854
+ "apd",
1855
+ "arb",
1856
+ "arq",
1857
+ "ars",
1858
+ "ary",
1859
+ "arz",
1860
+ "auz",
1861
+ "avl",
1862
+ "ayh",
1863
+ "ayl",
1864
+ "ayn",
1865
+ "ayp",
1866
+ "bbz",
1867
+ "pga",
1868
+ "he",
1869
+ "iw",
1870
+ "ps",
1871
+ "pbt",
1872
+ "pbu",
1873
+ "pst",
1874
+ "prp",
1875
+ "prd",
1876
+ "ug",
1877
+ "ur",
1878
+ "ydd",
1879
+ "yds",
1880
+ "yih",
1881
+ "ji",
1882
+ "yi",
1883
+ "hbo",
1884
+ "men",
1885
+ "xmn",
1886
+ "fa",
1887
+ "jpr",
1888
+ "peo",
1889
+ "pes",
1890
+ "prs",
1891
+ "dv",
1892
+ "sam",
1893
+ "ckb"
1894
+ ];
1895
+ const languageUtils = this.services?.languageUtils || new LanguageUtil(get());
1896
+ if (lng.toLowerCase().indexOf("-latn") > 1) return "ltr";
1897
+ return rtlLngs.includes(languageUtils.getLanguagePartFromCode(lng)) || lng.toLowerCase().indexOf("-arab") > 1 ? "rtl" : "ltr";
1898
+ }
1899
+ static createInstance(options = {}, callback) {
1900
+ const instance = new I18n(options, callback);
1901
+ instance.createInstance = I18n.createInstance;
1902
+ return instance;
1903
+ }
1904
+ cloneInstance(options = {}, callback = noop) {
1905
+ const forkResourceStore = options.forkResourceStore;
1906
+ if (forkResourceStore) delete options.forkResourceStore;
1907
+ const mergedOptions = {
1908
+ ...this.options,
1909
+ ...options,
1910
+ isClone: true
1911
+ };
1912
+ const clone = new I18n(mergedOptions);
1913
+ if (options.debug !== void 0 || options.prefix !== void 0) clone.logger = clone.logger.clone(options);
1914
+ [
1915
+ "store",
1916
+ "services",
1917
+ "language"
1918
+ ].forEach((m) => {
1919
+ clone[m] = this[m];
1920
+ });
1921
+ clone.services = { ...this.services };
1922
+ clone.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
1923
+ if (forkResourceStore) {
1924
+ clone.store = new ResourceStore(Object.keys(this.store.data).reduce((prev, l) => {
1925
+ prev[l] = { ...this.store.data[l] };
1926
+ prev[l] = Object.keys(prev[l]).reduce((acc, n) => {
1927
+ acc[n] = { ...prev[l][n] };
1928
+ return acc;
1929
+ }, prev[l]);
1930
+ return prev;
1931
+ }, {}), mergedOptions);
1932
+ clone.services.resourceStore = clone.store;
1933
+ }
1934
+ if (options.interpolation) {
1935
+ const mergedInterpolation = {
1936
+ ...get().interpolation,
1937
+ ...this.options.interpolation,
1938
+ ...options.interpolation
1939
+ };
1940
+ const mergedForInterpolator = {
1941
+ ...mergedOptions,
1942
+ interpolation: mergedInterpolation
1943
+ };
1944
+ clone.services.interpolator = new Interpolator(mergedForInterpolator);
1945
+ }
1946
+ clone.translator = new Translator(clone.services, mergedOptions);
1947
+ clone.translator.on("*", (event, ...args) => {
1948
+ clone.emit(event, ...args);
1949
+ });
1950
+ clone.init(mergedOptions, callback);
1951
+ clone.translator.options = mergedOptions;
1952
+ clone.translator.backendConnector.services.utils = { hasLoadedNamespace: clone.hasLoadedNamespace.bind(clone) };
1953
+ return clone;
1954
+ }
1955
+ toJSON() {
1956
+ return {
1957
+ options: this.options,
1958
+ store: this.store,
1959
+ language: this.language,
1960
+ languages: this.languages,
1961
+ resolvedLanguage: this.resolvedLanguage
1962
+ };
1963
+ }
1964
+ }.createInstance();
1965
+ instance.createInstance;
1966
+ instance.dir;
1967
+ instance.init;
1968
+ instance.loadResources;
1969
+ instance.reloadResources;
1970
+ instance.use;
1971
+ instance.changeLanguage;
1972
+ instance.getFixedT;
1973
+ instance.t;
1974
+ instance.exists;
1975
+ instance.setDefaultNamespace;
1976
+ instance.hasLoadedNamespace;
1977
+ instance.loadNamespaces;
1978
+ instance.loadLanguages;
1979
+ //#endregion
1980
+ export { instance };
1981
+
1982
+ //# sourceMappingURL=i18next.js.map