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