@intlayer/core 8.2.4 → 8.3.0-canary.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 (326) hide show
  1. package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +1 -1
  2. package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
  3. package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +1 -1
  4. package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
  5. package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +1 -1
  6. package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
  7. package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
  8. package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
  9. package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +1 -1
  10. package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
  11. package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
  12. package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
  13. package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +1 -1
  14. package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
  15. package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +1 -1
  16. package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
  17. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +1 -1
  18. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
  19. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -1
  20. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
  21. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +1 -1
  22. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
  23. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -1
  24. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
  25. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -1
  26. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
  27. package/dist/cjs/dictionaryManipulator/getNodeType.cjs +1 -1
  28. package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
  29. package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
  30. package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
  31. package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
  32. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -1
  33. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
  34. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -1
  35. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
  36. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +1 -1
  37. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
  38. package/dist/cjs/formatters/compact.cjs.map +1 -1
  39. package/dist/cjs/formatters/currency.cjs.map +1 -1
  40. package/dist/cjs/formatters/date.cjs.map +1 -1
  41. package/dist/cjs/formatters/list.cjs.map +1 -1
  42. package/dist/cjs/formatters/number.cjs.map +1 -1
  43. package/dist/cjs/formatters/percentage.cjs.map +1 -1
  44. package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
  45. package/dist/cjs/formatters/units.cjs.map +1 -1
  46. package/dist/cjs/getStorageAttributes.cjs.map +1 -1
  47. package/dist/cjs/interpreter/getContent/deepTransform.cjs +1 -1
  48. package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
  49. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  50. package/dist/cjs/interpreter/getContent/plugins.cjs +1 -1
  51. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  52. package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
  53. package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
  54. package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
  55. package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
  56. package/dist/cjs/localization/getBrowserLocale.cjs +1 -1
  57. package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
  58. package/dist/cjs/localization/getHTMLTextDir.cjs +1 -1
  59. package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
  60. package/dist/cjs/localization/getLocale.cjs.map +1 -1
  61. package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
  62. package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
  63. package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
  64. package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
  65. package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
  66. package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
  67. package/dist/cjs/localization/getPrefix.cjs.map +1 -1
  68. package/dist/cjs/localization/localeDetector.cjs.map +1 -1
  69. package/dist/cjs/localization/localeMapper.cjs +1 -1
  70. package/dist/cjs/localization/localeMapper.cjs.map +1 -1
  71. package/dist/cjs/localization/localeResolver.cjs.map +1 -1
  72. package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
  73. package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
  74. package/dist/cjs/messageFormat/ICU.cjs +1 -1
  75. package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
  76. package/dist/cjs/messageFormat/i18next.cjs +1 -1
  77. package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
  78. package/dist/cjs/messageFormat/vue-i18n.cjs +1 -1
  79. package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
  80. package/dist/cjs/transpiler/condition/condition.cjs +1 -1
  81. package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
  82. package/dist/cjs/transpiler/enumeration/enumeration.cjs +1 -1
  83. package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
  84. package/dist/cjs/transpiler/file/file.cjs +1 -1
  85. package/dist/cjs/transpiler/file/file.cjs.map +1 -1
  86. package/dist/cjs/transpiler/file/fileBrowser.cjs +1 -1
  87. package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
  88. package/dist/cjs/transpiler/gender/gender.cjs +1 -1
  89. package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
  90. package/dist/cjs/transpiler/html/html.cjs +1 -1
  91. package/dist/cjs/transpiler/html/html.cjs.map +1 -1
  92. package/dist/cjs/transpiler/insertion/insertion.cjs +1 -1
  93. package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
  94. package/dist/cjs/transpiler/markdown/markdown.cjs +1 -1
  95. package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
  96. package/dist/cjs/transpiler/nesting/nesting.cjs +1 -1
  97. package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
  98. package/dist/cjs/transpiler/translation/translation.cjs +1 -1
  99. package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
  100. package/dist/cjs/utils/intl.cjs +1 -1
  101. package/dist/cjs/utils/intl.cjs.map +1 -1
  102. package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
  103. package/dist/cjs/utils/localeStorage.cjs.map +1 -1
  104. package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +1 -1
  105. package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
  106. package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +1 -1
  107. package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
  108. package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +1 -1
  109. package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
  110. package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
  111. package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
  112. package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +1 -1
  113. package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
  114. package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
  115. package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
  116. package/dist/esm/deepTransformPlugins/getSplittedContent.mjs +1 -1
  117. package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
  118. package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs +1 -1
  119. package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
  120. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +1 -1
  121. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
  122. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -1
  123. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
  124. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +1 -1
  125. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
  126. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -1
  127. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
  128. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -1
  129. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
  130. package/dist/esm/dictionaryManipulator/getNodeType.mjs +1 -1
  131. package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
  132. package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
  133. package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
  134. package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
  135. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -1
  136. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
  137. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -1
  138. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
  139. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +1 -1
  140. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
  141. package/dist/esm/formatters/compact.mjs.map +1 -1
  142. package/dist/esm/formatters/currency.mjs.map +1 -1
  143. package/dist/esm/formatters/date.mjs.map +1 -1
  144. package/dist/esm/formatters/list.mjs.map +1 -1
  145. package/dist/esm/formatters/number.mjs.map +1 -1
  146. package/dist/esm/formatters/percentage.mjs.map +1 -1
  147. package/dist/esm/formatters/relativeTime.mjs.map +1 -1
  148. package/dist/esm/formatters/units.mjs.map +1 -1
  149. package/dist/esm/getStorageAttributes.mjs.map +1 -1
  150. package/dist/esm/interpreter/getContent/deepTransform.mjs +1 -1
  151. package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
  152. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  153. package/dist/esm/interpreter/getContent/plugins.mjs +1 -1
  154. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  155. package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
  156. package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
  157. package/dist/esm/interpreter/getNesting.mjs.map +1 -1
  158. package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
  159. package/dist/esm/localization/getBrowserLocale.mjs +1 -1
  160. package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
  161. package/dist/esm/localization/getHTMLTextDir.mjs +1 -1
  162. package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
  163. package/dist/esm/localization/getLocale.mjs.map +1 -1
  164. package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
  165. package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
  166. package/dist/esm/localization/getLocaleName.mjs.map +1 -1
  167. package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
  168. package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
  169. package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
  170. package/dist/esm/localization/getPrefix.mjs.map +1 -1
  171. package/dist/esm/localization/localeDetector.mjs.map +1 -1
  172. package/dist/esm/localization/localeMapper.mjs +1 -1
  173. package/dist/esm/localization/localeMapper.mjs.map +1 -1
  174. package/dist/esm/localization/localeResolver.mjs.map +1 -1
  175. package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
  176. package/dist/esm/localization/validatePrefix.mjs.map +1 -1
  177. package/dist/esm/messageFormat/ICU.mjs +1 -1
  178. package/dist/esm/messageFormat/ICU.mjs.map +1 -1
  179. package/dist/esm/messageFormat/i18next.mjs +1 -1
  180. package/dist/esm/messageFormat/i18next.mjs.map +1 -1
  181. package/dist/esm/messageFormat/vue-i18n.mjs +1 -1
  182. package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
  183. package/dist/esm/transpiler/condition/condition.mjs +1 -1
  184. package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
  185. package/dist/esm/transpiler/enumeration/enumeration.mjs +1 -1
  186. package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
  187. package/dist/esm/transpiler/file/file.mjs +1 -1
  188. package/dist/esm/transpiler/file/file.mjs.map +1 -1
  189. package/dist/esm/transpiler/file/fileBrowser.mjs +1 -1
  190. package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
  191. package/dist/esm/transpiler/gender/gender.mjs +1 -1
  192. package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
  193. package/dist/esm/transpiler/html/html.mjs +1 -1
  194. package/dist/esm/transpiler/html/html.mjs.map +1 -1
  195. package/dist/esm/transpiler/insertion/insertion.mjs +1 -1
  196. package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
  197. package/dist/esm/transpiler/markdown/markdown.mjs +1 -1
  198. package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
  199. package/dist/esm/transpiler/nesting/nesting.mjs +1 -1
  200. package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
  201. package/dist/esm/transpiler/translation/translation.mjs +1 -1
  202. package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
  203. package/dist/esm/utils/intl.mjs +1 -1
  204. package/dist/esm/utils/intl.mjs.map +1 -1
  205. package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
  206. package/dist/esm/utils/localeStorage.mjs.map +1 -1
  207. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts +12 -11
  208. package/dist/types/deepTransformPlugins/getFilterMissingTranslationsContent.d.ts.map +1 -1
  209. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts +12 -11
  210. package/dist/types/deepTransformPlugins/getFilterTranslationsOnlyContent.d.ts.map +1 -1
  211. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts +12 -11
  212. package/dist/types/deepTransformPlugins/getFilteredLocalesContent.d.ts.map +1 -1
  213. package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts +2 -1
  214. package/dist/types/deepTransformPlugins/getLocalizedContent.d.ts.map +1 -1
  215. package/dist/types/deepTransformPlugins/getMaskContent.d.ts +1 -1
  216. package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts +3 -1
  217. package/dist/types/deepTransformPlugins/getMissingLocalesContent.d.ts.map +1 -1
  218. package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts +1 -1
  219. package/dist/types/deepTransformPlugins/getMultilingualDictionary.d.ts.map +1 -1
  220. package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts +1 -1
  221. package/dist/types/deepTransformPlugins/getReplacedValuesContent.d.ts.map +1 -1
  222. package/dist/types/deepTransformPlugins/getSplittedContent.d.ts +2 -1
  223. package/dist/types/deepTransformPlugins/getSplittedContent.d.ts.map +1 -1
  224. package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts +2 -1
  225. package/dist/types/deepTransformPlugins/insertContentInDictionary.d.ts.map +1 -1
  226. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts +2 -1
  227. package/dist/types/dictionaryManipulator/editDictionaryByKeyPath.d.ts.map +1 -1
  228. package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts +3 -1
  229. package/dist/types/dictionaryManipulator/getContentNodeByKeyPath.d.ts.map +1 -1
  230. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts +3 -1
  231. package/dist/types/dictionaryManipulator/getDefaultNode.d.ts.map +1 -1
  232. package/dist/types/dictionaryManipulator/getEmptyNode.d.ts +1 -1
  233. package/dist/types/dictionaryManipulator/getEmptyNode.d.ts.map +1 -1
  234. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts +1 -1
  235. package/dist/types/dictionaryManipulator/getNodeChildren.d.ts.map +1 -1
  236. package/dist/types/dictionaryManipulator/getNodeType.d.ts +2 -1
  237. package/dist/types/dictionaryManipulator/getNodeType.d.ts.map +1 -1
  238. package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts +1 -1
  239. package/dist/types/dictionaryManipulator/mergeDictionaries.d.ts.map +1 -1
  240. package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts +2 -1
  241. package/dist/types/dictionaryManipulator/normalizeDictionary.d.ts.map +1 -1
  242. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts +3 -3
  243. package/dist/types/dictionaryManipulator/orderDictionaries.d.ts.map +1 -1
  244. package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts +2 -1
  245. package/dist/types/dictionaryManipulator/removeContentNodeByKeyPath.d.ts.map +1 -1
  246. package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts +2 -1
  247. package/dist/types/dictionaryManipulator/renameContentNodeByKeyPath.d.ts.map +1 -1
  248. package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts +1 -1
  249. package/dist/types/dictionaryManipulator/updateNodeChildren.d.ts.map +1 -1
  250. package/dist/types/formatters/compact.d.ts +1 -1
  251. package/dist/types/formatters/currency.d.ts +1 -1
  252. package/dist/types/formatters/date.d.ts +1 -1
  253. package/dist/types/formatters/list.d.ts +1 -1
  254. package/dist/types/formatters/number.d.ts +1 -1
  255. package/dist/types/formatters/percentage.d.ts +1 -1
  256. package/dist/types/formatters/relativeTime.d.ts +1 -1
  257. package/dist/types/formatters/units.d.ts +1 -1
  258. package/dist/types/getStorageAttributes.d.ts +1 -1
  259. package/dist/types/getStorageAttributes.d.ts.map +1 -1
  260. package/dist/types/interpreter/getContent/deepTransform.d.ts.map +1 -1
  261. package/dist/types/interpreter/getContent/getContent.d.ts +2 -1
  262. package/dist/types/interpreter/getContent/getContent.d.ts.map +1 -1
  263. package/dist/types/interpreter/getContent/plugins.d.ts +4 -1
  264. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  265. package/dist/types/interpreter/getDictionary.d.ts +2 -1
  266. package/dist/types/interpreter/getDictionary.d.ts.map +1 -1
  267. package/dist/types/interpreter/getIntlayer.d.ts +1 -1
  268. package/dist/types/interpreter/getIntlayer.d.ts.map +1 -1
  269. package/dist/types/interpreter/getNesting.d.ts +2 -1
  270. package/dist/types/interpreter/getNesting.d.ts.map +1 -1
  271. package/dist/types/interpreter/getTranslation.d.ts +1 -1
  272. package/dist/types/localization/getBrowserLocale.d.ts +1 -1
  273. package/dist/types/localization/getBrowserLocale.d.ts.map +1 -1
  274. package/dist/types/localization/getHTMLTextDir.d.ts +1 -1
  275. package/dist/types/localization/getHTMLTextDir.d.ts.map +1 -1
  276. package/dist/types/localization/getLocale.d.ts +1 -1
  277. package/dist/types/localization/getLocaleFromPath.d.ts +3 -1
  278. package/dist/types/localization/getLocaleFromPath.d.ts.map +1 -1
  279. package/dist/types/localization/getLocaleLang.d.ts +1 -1
  280. package/dist/types/localization/getLocaleName.d.ts +1 -1
  281. package/dist/types/localization/getLocalizedUrl.d.ts +2 -1
  282. package/dist/types/localization/getLocalizedUrl.d.ts.map +1 -1
  283. package/dist/types/localization/getMultilingualUrls.d.ts +2 -1
  284. package/dist/types/localization/getMultilingualUrls.d.ts.map +1 -1
  285. package/dist/types/localization/getPathWithoutLocale.d.ts +1 -1
  286. package/dist/types/localization/getPrefix.d.ts +3 -1
  287. package/dist/types/localization/getPrefix.d.ts.map +1 -1
  288. package/dist/types/localization/localeDetector.d.ts +1 -1
  289. package/dist/types/localization/localeMapper.d.ts +2 -1
  290. package/dist/types/localization/localeMapper.d.ts.map +1 -1
  291. package/dist/types/localization/localeResolver.d.ts +2 -1
  292. package/dist/types/localization/localeResolver.d.ts.map +1 -1
  293. package/dist/types/localization/rewriteUtils.d.ts +3 -1
  294. package/dist/types/localization/rewriteUtils.d.ts.map +1 -1
  295. package/dist/types/localization/validatePrefix.d.ts +1 -1
  296. package/dist/types/messageFormat/ICU.d.ts +1 -1
  297. package/dist/types/messageFormat/ICU.d.ts.map +1 -1
  298. package/dist/types/messageFormat/i18next.d.ts +1 -1
  299. package/dist/types/messageFormat/vue-i18n.d.ts +1 -1
  300. package/dist/types/messageFormat/vue-i18n.d.ts.map +1 -1
  301. package/dist/types/transpiler/condition/condition.d.ts +1 -1
  302. package/dist/types/transpiler/condition/condition.d.ts.map +1 -1
  303. package/dist/types/transpiler/enumeration/enumeration.d.ts +1 -1
  304. package/dist/types/transpiler/enumeration/enumeration.d.ts.map +1 -1
  305. package/dist/types/transpiler/file/file.d.ts +1 -1
  306. package/dist/types/transpiler/file/file.d.ts.map +1 -1
  307. package/dist/types/transpiler/file/fileBrowser.d.ts +1 -1
  308. package/dist/types/transpiler/file/fileBrowser.d.ts.map +1 -1
  309. package/dist/types/transpiler/gender/gender.d.ts +1 -1
  310. package/dist/types/transpiler/gender/gender.d.ts.map +1 -1
  311. package/dist/types/transpiler/html/html.d.ts +1 -1
  312. package/dist/types/transpiler/html/html.d.ts.map +1 -1
  313. package/dist/types/transpiler/insertion/insertion.d.ts +1 -1
  314. package/dist/types/transpiler/insertion/insertion.d.ts.map +1 -1
  315. package/dist/types/transpiler/markdown/markdown.d.ts +1 -1
  316. package/dist/types/transpiler/markdown/markdown.d.ts.map +1 -1
  317. package/dist/types/transpiler/nesting/nesting.d.ts +2 -1
  318. package/dist/types/transpiler/nesting/nesting.d.ts.map +1 -1
  319. package/dist/types/transpiler/translation/translation.d.ts +3 -2
  320. package/dist/types/transpiler/translation/translation.d.ts.map +1 -1
  321. package/dist/types/utils/intl.d.ts +1 -1
  322. package/dist/types/utils/intl.d.ts.map +1 -1
  323. package/dist/types/utils/isSameKeyPath.d.ts +1 -1
  324. package/dist/types/utils/localeStorage.d.ts +2 -1
  325. package/dist/types/utils/localeStorage.d.ts.map +1 -1
  326. package/package.json +17 -17
@@ -1 +1 @@
1
- {"version":3,"file":"intl.cjs","names":["Locales"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport { Locales, type LocalesValues } from '@intlayer/types';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? {\n new (locales?: LocalesValues, options?: Options): Instance;\n new (options?: Options & { locale?: LocalesValues }): Instance;\n }\n : T extends new (\n locales: any\n ) => infer Instance\n ? {\n new (locales?: LocalesValues): Instance;\n new (options?: { locale?: LocalesValues }): Instance;\n }\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// ... (Keep your Type Helper definitions here: IntlConstructors, ReplaceLocaleWithLocalesValues, WrappedIntl) ...\n\n/**\n * Optimized Cache Key Generator\n * 1. Fast path: If no options, just use the locale string.\n * 2. Normal path: JSON.stringify for deterministic object comparison.\n */\nconst getCacheKey = (\n locales: LocalesValues | undefined,\n options: unknown\n): string => {\n const localeKey = locales ? String(locales) : Locales.ENGLISH;\n\n if (!options) return localeKey;\n\n // JSON.stringify is the most robust way to handle nested options objects\n // without a heavy custom hashing function.\n return `${localeKey}|${JSON.stringify(options)}`;\n};\n\n/**\n * Generic wrapper for any `new Intl.*()` constructor.\n */\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n // The cache lives here, inside the closure of the wrapped constructor.\n const cache = new Map<string, InstanceType<T>>();\n const MAX_CACHE_SIZE = 50;\n\n function Wrapped(locales?: LocalesValues | any, options?: any) {\n let resolvedLocales = locales;\n let resolvedOptions = options;\n\n // Handle case where first argument is an options object instead of locales\n if (\n typeof locales === 'object' &&\n !Array.isArray(locales) &&\n locales !== null\n ) {\n resolvedOptions = locales;\n resolvedLocales = locales.locale;\n }\n\n // Handle DisplayNames Polyfill warning\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n // ... (Existing polyfill logic would go here if needed, but let's keep it simple for now as it was empty in the read output)\n // Actually the read output had \"// ... (Your existing polyfill warning logic) ...\"\n // I should check what was there before or just preserve it.\n }\n\n // Generate Key\n const key = getCacheKey(resolvedLocales, resolvedOptions);\n\n // Check Cache\n let instance = cache.get(key);\n if (instance) return instance;\n\n // Create New Instance\n instance = new Ctor(resolvedLocales as never, resolvedOptions as never);\n\n // Smart Eviction (LRU-ish)\n // Map iterates in insertion order. Deleting the first key removes the \"oldest\".\n if (cache.size >= MAX_CACHE_SIZE) {\n const oldestKey = cache.keys().next().value;\n if (oldestKey) cache.delete(oldestKey);\n }\n\n cache.set(key, instance as InstanceType<T>);\n return instance as InstanceType<T>;\n }\n\n // Preserve prototype for `instanceof` checks\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n/**\n * Factory that turns the global `Intl` into a cached clone.\n */\nexport const createCachedIntl = (): WrappedIntl => {\n // We must cache the *wrapped constructors* themselves.\n // Otherwise, the Proxy creates a new `Wrapped` function (and a new empty Map)\n // on every single property access.\n const constructorCache = new Map<string | symbol, any>();\n\n return new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n // Fast return if we already wrapped this constructor\n if (constructorCache.has(prop)) {\n return constructorCache.get(prop);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap only Constructors (Heuristic: Function + starts with Uppercase)\n // This prevents wrapping static methods like `Intl.getCanonicalLocales`\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n const wrapped = createCachedConstructor(value);\n constructorCache.set(prop, wrapped);\n return wrapped;\n }\n\n // Pass through everything else (static methods, constants)\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\nexport const CachedIntl = createCachedIntl();\n\n/**\n * Creates a proxied Intl object with a preset locale.\n *\n * @example\n * const intl = bindIntl(Locales.FRENCH);\n * new intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(10);\n * // Uses 'fr' automatically\n */\nexport const bindIntl = (locale: LocalesValues): WrappedIntl => {\n return new Proxy(CachedIntl, {\n get: (target, prop) => {\n const value = Reflect.get(target, prop);\n\n // We only want to intercept Constructors (e.g., NumberFormat, DateTimeFormat)\n // to inject the locale into their arguments.\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n return new Proxy(value, {\n construct: (Ctor, args) => {\n let [locales, options] = args;\n\n // If the user provided a locale (args[0]), respect it.\n // If args[0] is undefined, inject the bound locale.\n // If args[0] is an object (not array), it's the options object.\n if (\n typeof locales === 'object' &&\n !Array.isArray(locales) &&\n locales !== null\n ) {\n options = locales;\n locales = options.locale ?? locale;\n } else if (locales === undefined) {\n locales = locale;\n }\n\n // We pass it to `CachedIntl` which handles caching logic.\n return new Ctor(locales, options);\n },\n // Ensure static methods (like supportedLocalesOf) still work\n get: (Ctor, key) => Reflect.get(Ctor, key),\n });\n }\n\n // Return constants or static methods as-is\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { num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IAAI,MAAM,EAAY,CAC3B,KAAM,EAAQ,IAAS,CACrB,IAAM,EAAQ,QAAQ,IAAI,EAAQ,EAAK,CAoCvC,OA/BE,OAAO,GAAU,YACjB,OAAO,GAAS,UAChB,SAAS,KAAK,EAAK,CAEZ,IAAI,MAAM,EAAO,CACtB,WAAY,EAAM,IAAS,CACzB,GAAI,CAAC,EAAS,GAAW,EAiBzB,OAXE,OAAO,GAAY,UACnB,CAAC,MAAM,QAAQ,EAAQ,EACvB,IAAY,MAEZ,EAAU,EACV,EAAU,EAAQ,QAAU,GACnB,IAAY,IAAA,KACrB,EAAU,GAIL,IAAI,EAAK,EAAS,EAAQ,EAGnC,KAAM,EAAM,IAAQ,QAAQ,IAAI,EAAM,EAAI,CAC3C,CAAC,CAIG,GAEV,CAAC"}
1
+ {"version":3,"file":"intl.cjs","names":["Locales"],"sources":["../../../src/utils/intl.ts"],"sourcesContent":["// Cached Intl helper – drop‑in replacement for the global `Intl` object.\n// ‑‑‑\n// • Uses a `Proxy` to lazily wrap every *constructor* hanging off `Intl` (NumberFormat, DateTimeFormat, …).\n// • Each wrapped constructor keeps an in‑memory cache keyed by `[locales, options]` so that identical requests\n// reuse the same heavy instance instead of reparsing CLDR data every time.\n// • A polyfill warning for `Intl.DisplayNames` is emitted only once and only in dev.\n// • The public API is fully type‑safe and mirrors the native `Intl` surface exactly –\n// you can treat `CachedIntl` just like the built‑in `Intl`.\n//\n// Usage examples:\n// ---------------\n// import { CachedIntl } from \"./cached-intl\";\n//\n// const nf = CachedIntl.NumberFormat(\"en-US\", { style: \"currency\", currency: \"USD\" });\n// console.log(nf.format(1234));\n//\n// const dn = CachedIntl.DisplayNames([\"fr\"], { type: \"language\" });\n// console.log(dn.of(\"en\")); // → \"anglais\"\n//\n// You can also spin up an isolated instance with its own caches (handy in test suites):\n// const TestIntl = createCachedIntl();\n//\n// ---------------------------------------------------------------------\n\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport * as Locales from '@intlayer/types/locales';\n\n// Helper type that picks just the constructor members off `typeof Intl`.\n// The \"capital‑letter\" heuristic is 100 % accurate today and keeps the\n// mapping short‑lived, so we don't have to manually list every constructor.\ntype IntlConstructors = {\n [K in keyof typeof Intl as (typeof Intl)[K] extends new (\n ...args: any\n ) => any\n ? K\n : never]: (typeof Intl)[K];\n};\n\n// Type wrapper to replace locale arguments with LocalesValues\ntype ReplaceLocaleWithLocalesValues<T> = T extends new (\n locales: any,\n options?: infer Options\n) => infer Instance\n ? {\n new (locales?: LocalesValues, options?: Options): Instance;\n new (options?: Options & { locale?: LocalesValues }): Instance;\n }\n : T extends new (\n locales: any\n ) => infer Instance\n ? {\n new (locales?: LocalesValues): Instance;\n new (options?: { locale?: LocalesValues }): Instance;\n }\n : T;\n\n// Wrapped Intl type with LocalesValues\ntype WrappedIntl = {\n [K in keyof typeof Intl]: K extends keyof IntlConstructors\n ? ReplaceLocaleWithLocalesValues<(typeof Intl)[K]>\n : (typeof Intl)[K];\n};\n\n// ... (Keep your Type Helper definitions here: IntlConstructors, ReplaceLocaleWithLocalesValues, WrappedIntl) ...\n\n/**\n * Optimized Cache Key Generator\n * 1. Fast path: If no options, just use the locale string.\n * 2. Normal path: JSON.stringify for deterministic object comparison.\n */\nconst getCacheKey = (\n locales: LocalesValues | undefined,\n options: unknown\n): string => {\n const localeKey = locales ? String(locales) : Locales.ENGLISH;\n\n if (!options) return localeKey;\n\n // JSON.stringify is the most robust way to handle nested options objects\n // without a heavy custom hashing function.\n return `${localeKey}|${JSON.stringify(options)}`;\n};\n\n/**\n * Generic wrapper for any `new Intl.*()` constructor.\n */\nconst createCachedConstructor = <T extends new (...args: any[]) => any>(\n Ctor: T\n) => {\n // The cache lives here, inside the closure of the wrapped constructor.\n const cache = new Map<string, InstanceType<T>>();\n const MAX_CACHE_SIZE = 50;\n\n function Wrapped(locales?: LocalesValues | any, options?: any) {\n let resolvedLocales = locales;\n let resolvedOptions = options;\n\n // Handle case where first argument is an options object instead of locales\n if (\n typeof locales === 'object' &&\n !Array.isArray(locales) &&\n locales !== null\n ) {\n resolvedOptions = locales;\n resolvedLocales = locales.locale;\n }\n\n // Handle DisplayNames Polyfill warning\n if (\n Ctor.name === 'DisplayNames' &&\n typeof (Intl as any)?.DisplayNames !== 'function'\n ) {\n // ... (Existing polyfill logic would go here if needed, but let's keep it simple for now as it was empty in the read output)\n // Actually the read output had \"// ... (Your existing polyfill warning logic) ...\"\n // I should check what was there before or just preserve it.\n }\n\n // Generate Key\n const key = getCacheKey(resolvedLocales, resolvedOptions);\n\n // Check Cache\n let instance = cache.get(key);\n if (instance) return instance;\n\n // Create New Instance\n instance = new Ctor(resolvedLocales as never, resolvedOptions as never);\n\n // Smart Eviction (LRU-ish)\n // Map iterates in insertion order. Deleting the first key removes the \"oldest\".\n if (cache.size >= MAX_CACHE_SIZE) {\n const oldestKey = cache.keys().next().value;\n if (oldestKey) cache.delete(oldestKey);\n }\n\n cache.set(key, instance as InstanceType<T>);\n return instance as InstanceType<T>;\n }\n\n // Preserve prototype for `instanceof` checks\n (Wrapped as any).prototype = (Ctor as any).prototype;\n\n return Wrapped as unknown as ReplaceLocaleWithLocalesValues<T>;\n};\n\n/**\n * Factory that turns the global `Intl` into a cached clone.\n */\nexport const createCachedIntl = (): WrappedIntl => {\n // We must cache the *wrapped constructors* themselves.\n // Otherwise, the Proxy creates a new `Wrapped` function (and a new empty Map)\n // on every single property access.\n const constructorCache = new Map<string | symbol, any>();\n\n return new Proxy(Intl as IntlConstructors, {\n get: (target, prop, receiver) => {\n // Fast return if we already wrapped this constructor\n if (constructorCache.has(prop)) {\n return constructorCache.get(prop);\n }\n\n const value = Reflect.get(target, prop, receiver);\n\n // Wrap only Constructors (Heuristic: Function + starts with Uppercase)\n // This prevents wrapping static methods like `Intl.getCanonicalLocales`\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n const wrapped = createCachedConstructor(value);\n constructorCache.set(prop, wrapped);\n return wrapped;\n }\n\n // Pass through everything else (static methods, constants)\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\nexport const CachedIntl = createCachedIntl();\n\n/**\n * Creates a proxied Intl object with a preset locale.\n *\n * @example\n * const intl = bindIntl(Locales.FRENCH);\n * new intl.NumberFormat(undefined, { style: 'currency', currency: 'EUR' }).format(10);\n * // Uses 'fr' automatically\n */\nexport const bindIntl = (locale: LocalesValues): WrappedIntl => {\n return new Proxy(CachedIntl, {\n get: (target, prop) => {\n const value = Reflect.get(target, prop);\n\n // We only want to intercept Constructors (e.g., NumberFormat, DateTimeFormat)\n // to inject the locale into their arguments.\n if (\n typeof value === 'function' &&\n typeof prop === 'string' &&\n /^[A-Z]/.test(prop)\n ) {\n return new Proxy(value, {\n construct: (Ctor, args) => {\n let [locales, options] = args;\n\n // If the user provided a locale (args[0]), respect it.\n // If args[0] is undefined, inject the bound locale.\n // If args[0] is an object (not array), it's the options object.\n if (\n typeof locales === 'object' &&\n !Array.isArray(locales) &&\n locales !== null\n ) {\n options = locales;\n locales = options.locale ?? locale;\n } else if (locales === undefined) {\n locales = locale;\n }\n\n // We pass it to `CachedIntl` which handles caching logic.\n return new Ctor(locales, options);\n },\n // Ensure static methods (like supportedLocalesOf) still work\n get: (Ctor, key) => Reflect.get(Ctor, key),\n });\n }\n\n // Return constants or static methods as-is\n return value;\n },\n }) as unknown as WrappedIntl;\n};\n\n// new CachedIntl.DisplayNames(Locales.FRENCH, { type: 'language' });\n// new CachedIntl.DisplayNames('fr', { type: 'language' });\n// new CachedIntl.DateTimeFormat('fr', {\n// year: 'numeric',\n// month: 'long',\n// day: 'numeric',\n// });\n// new CachedIntl.NumberFormat('fr', {\n// style: 'currency',\n// currency: 'EUR',\n// });\n// new CachedIntl.Collator('fr', { sensitivity: 'base' });\n// new CachedIntl.PluralRules('fr');\n// new CachedIntl.RelativeTimeFormat('fr', { numeric: 'auto' });\n// new CachedIntl.ListFormat('fr', { type: 'conjunction' });\nexport { CachedIntl as Intl };\n"],"mappings":"gL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,CAoCvC,OA/BE,OAAO,GAAU,YACjB,OAAO,GAAS,UAChB,SAAS,KAAK,EAAK,CAEZ,IAAI,MAAM,EAAO,CACtB,WAAY,EAAM,IAAS,CACzB,GAAI,CAAC,EAAS,GAAW,EAiBzB,OAXE,OAAO,GAAY,UACnB,CAAC,MAAM,QAAQ,EAAQ,EACvB,IAAY,MAEZ,EAAU,EACV,EAAU,EAAQ,QAAU,GACnB,IAAY,IAAA,KACrB,EAAU,GAIL,IAAI,EAAK,EAAS,EAAQ,EAGnC,KAAM,EAAM,IAAQ,QAAQ,IAAI,EAAM,EAAI,CAC3C,CAAC,CAIG,GAEV,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"isSameKeyPath.cjs","names":[],"sources":["../../../src/utils/isSameKeyPath.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/types';\n\ntype KeyPathWithKey = KeyPath & { key: string };\n\nexport const isSameKeyPath = (keyPath1: KeyPath[], keyPath2: KeyPath[]) =>\n keyPath1.every(\n (element, index) =>\n keyPath2[index] &&\n (keyPath2[index] as KeyPathWithKey).key ===\n (element as KeyPathWithKey).key &&\n keyPath2[index].type === element.type\n );\n"],"mappings":"mEAIA,MAAa,GAAiB,EAAqB,IACjD,EAAS,OACN,EAAS,IACR,EAAS,IACR,EAAS,GAA0B,MACjC,EAA2B,KAC9B,EAAS,GAAO,OAAS,EAAQ,KACpC"}
1
+ {"version":3,"file":"isSameKeyPath.cjs","names":[],"sources":["../../../src/utils/isSameKeyPath.ts"],"sourcesContent":["import type { KeyPath } from '@intlayer/types/keyPath';\n\ntype KeyPathWithKey = KeyPath & { key: string };\n\nexport const isSameKeyPath = (keyPath1: KeyPath[], keyPath2: KeyPath[]) =>\n keyPath1.every(\n (element, index) =>\n keyPath2[index] &&\n (keyPath2[index] as KeyPathWithKey).key ===\n (element as KeyPathWithKey).key &&\n keyPath2[index].type === element.type\n );\n"],"mappings":"mEAIA,MAAa,GAAiB,EAAqB,IACjD,EAAS,OACN,EAAS,IACR,EAAS,IACR,EAAS,GAA0B,MACjC,EAA2B,KAC9B,EAAS,GAAO,OAAS,EAAQ,KACpC"}
@@ -1 +1 @@
1
- {"version":3,"file":"localeStorage.cjs","names":["configuration","getStorageAttributes","getCookie"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { CookiesAttributes, Locale, LocalesValues } from '@intlayer/types';\nimport { getStorageAttributes } from '../getStorageAttributes';\nimport { getCookie } from './getCookie';\n\ntype CookieBuildAttributes = {\n /**\n * Cookie domain to store the locale information\n *\n * Default: undefined\n *\n * Define the domain where the cookie is available. Defaults to\n * the domain of the page where the cookie was created.\n */\n domain?: string;\n /**\n * Cookie path to store the locale information\n *\n * Default: undefined\n *\n * Define the path where the cookie is available. Defaults to '/'\n */\n path?: string;\n /**\n * Cookie secure to store the locale information\n *\n * Default: undefined\n *\n * A Boolean indicating if the cookie transmission requires a\n * secure protocol (https). Defaults to false.\n */\n secure?: boolean;\n /**\n * Cookie httpOnly to store the locale information\n *\n * Default: undefined\n *\n * The cookie httpOnly where the locale information is stored.\n */\n httpOnly?: boolean;\n /**\n * Cookie sameSite to store the locale information\n *\n * Default: undefined\n *\n * Asserts that a cookie must not be sent with cross-origin requests,\n * providing some protection against cross-site request forgery\n * attacks (CSRF)\n */\n sameSite?: 'strict' | 'lax' | 'none';\n\n /**\n * Cookie expires to store the locale information\n *\n * Default: undefined\n *\n * Define when the cookie will be removed. Value can be a Number\n * which will be interpreted as days from time of creation or a\n * Date instance. If omitted, the cookie becomes a session cookie.\n */\n expires?: number | undefined;\n};\n\nconst buildCookieString = (\n name: string,\n value: string,\n attributes: Omit<CookiesAttributes, 'name' | 'type'>\n): string => {\n const encodedValue = encodeURIComponent(value);\n const parts: string[] = [`${name}=${encodedValue}`];\n\n if (attributes.path) parts.push(`Path=${attributes.path}`);\n if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n if (attributes.expires instanceof Date)\n parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\n if (attributes.secure) parts.push('Secure');\n if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n return parts.join('; ');\n};\n\nexport type LocaleStorageOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { routing, internationalization } = configuration;\n const { locales } = internationalization;\n const { storage } = routing;\n\n // If storage is disabled, return undefined\n if (storage === false || options?.isCookieEnabled === false) return undefined;\n\n const storageAttributes = getStorageAttributes(storage);\n\n const isValidLocale = (value: string | null | undefined): value is Locale => {\n if (!value) return false;\n\n return locales.includes(value as Locale);\n };\n\n const readCookie = (name: string): string | undefined => {\n // Prefer provided getter (server or custom environment)\n try {\n const fromOption = options?.getCookie?.(name);\n\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n\n // Fallback to browser cookie parsing\n return getCookie(name);\n };\n\n // Check cookies first\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name } = storageAttributes.cookies[i];\n\n const value = readCookie(name);\n\n if (isValidLocale(value)) return value;\n }\n\n // Then check localStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const value = options?.getLocaleStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // Check sessionStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const value = options?.getSessionStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // Finally check header candidates (server only)\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n const value = options?.getHeader?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n};\n\n/**\n * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @param locale - The locale to store\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n // If storage is disabled, do nothing\n if (\n configuration.routing.storage === false ||\n options?.isCookieEnabled === false\n )\n return;\n\n const storageAttributes = getStorageAttributes(configuration.routing.storage);\n\n // Write to cookies (server via setCookie, client via cookieStore/document)\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name, attributes } = storageAttributes.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options?.setCookieStore?.(name, locale, {\n ...attributes,\n expires:\n attributes.expires instanceof Date\n ? attributes.expires.getTime()\n : attributes.expires,\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n const cookieString = buildCookieString(name, locale, attributes);\n\n options?.setCookieString?.(name, cookieString);\n }\n } catch {}\n }\n }\n\n // Write to localStorage (browser only)\n if (options?.setLocaleStorage) {\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getLocaleStorage) {\n const existing = options?.getLocaleStorage?.(name);\n if (existing) continue;\n }\n options?.setLocaleStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to sessionStorage (browser only)\n if (options?.setSessionStorage) {\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getSessionStorage) {\n const existing = options?.getSessionStorage?.(name);\n if (existing) continue;\n }\n\n options?.setSessionStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to headers (server only)\n if (options?.setHeader) {\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n options?.setHeader?.(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in the storage by considering the configuration\n *\n * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":"qPA+DA,MAAM,GACJ,EACA,EACA,IACW,CAEX,IAAM,EAAkB,CAAC,GAAG,EAAK,GADZ,mBAAmB,EAAM,GACK,CASnD,OAPI,EAAW,MAAM,EAAM,KAAK,QAAQ,EAAW,OAAO,CACtD,EAAW,QAAQ,EAAM,KAAK,UAAU,EAAW,SAAS,CAC5D,EAAW,mBAAmB,MAChC,EAAM,KAAK,WAAW,EAAW,QAAQ,aAAa,GAAG,CAEvD,EAAW,QAAQ,EAAM,KAAK,SAAS,CACvC,EAAW,UAAU,EAAM,KAAK,YAAY,EAAW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E"}
1
+ {"version":3,"file":"localeStorage.cjs","names":["configuration","getStorageAttributes","getCookie"],"sources":["../../../src/utils/localeStorage.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { CookiesAttributes } from '@intlayer/types/config';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport { getStorageAttributes } from '../getStorageAttributes';\nimport { getCookie } from './getCookie';\n\ntype CookieBuildAttributes = {\n /**\n * Cookie domain to store the locale information\n *\n * Default: undefined\n *\n * Define the domain where the cookie is available. Defaults to\n * the domain of the page where the cookie was created.\n */\n domain?: string;\n /**\n * Cookie path to store the locale information\n *\n * Default: undefined\n *\n * Define the path where the cookie is available. Defaults to '/'\n */\n path?: string;\n /**\n * Cookie secure to store the locale information\n *\n * Default: undefined\n *\n * A Boolean indicating if the cookie transmission requires a\n * secure protocol (https). Defaults to false.\n */\n secure?: boolean;\n /**\n * Cookie httpOnly to store the locale information\n *\n * Default: undefined\n *\n * The cookie httpOnly where the locale information is stored.\n */\n httpOnly?: boolean;\n /**\n * Cookie sameSite to store the locale information\n *\n * Default: undefined\n *\n * Asserts that a cookie must not be sent with cross-origin requests,\n * providing some protection against cross-site request forgery\n * attacks (CSRF)\n */\n sameSite?: 'strict' | 'lax' | 'none';\n\n /**\n * Cookie expires to store the locale information\n *\n * Default: undefined\n *\n * Define when the cookie will be removed. Value can be a Number\n * which will be interpreted as days from time of creation or a\n * Date instance. If omitted, the cookie becomes a session cookie.\n */\n expires?: number | undefined;\n};\n\nconst buildCookieString = (\n name: string,\n value: string,\n attributes: Omit<CookiesAttributes, 'name' | 'type'>\n): string => {\n const encodedValue = encodeURIComponent(value);\n const parts: string[] = [`${name}=${encodedValue}`];\n\n if (attributes.path) parts.push(`Path=${attributes.path}`);\n if (attributes.domain) parts.push(`Domain=${attributes.domain}`);\n if (attributes.expires instanceof Date)\n parts.push(`Expires=${attributes.expires.toUTCString()}`);\n\n if (attributes.secure) parts.push('Secure');\n if (attributes.sameSite) parts.push(`SameSite=${attributes.sameSite}`);\n return parts.join('; ');\n};\n\nexport type LocaleStorageOptions = {\n overwrite?: boolean;\n isCookieEnabled?: boolean;\n setCookieStore?: (\n name: string,\n value: string,\n cookie: CookieBuildAttributes\n ) => void;\n setCookieString?: (name: string, cookie: string) => void;\n getCookie?: (name: string) => string | undefined | null;\n setSessionStorage?: (name: string, value: string) => void;\n getSessionStorage?: (name: string) => string | undefined | null;\n setLocaleStorage?: (name: string, value: string) => void;\n getLocaleStorage?: (name: string) => string | undefined | null;\n getHeader?: (name: string) => string | undefined | null;\n setHeader?: (name: string, value: string) => void;\n};\n\n/**\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const getLocaleFromStorage = (\n options: Pick<\n LocaleStorageOptions,\n | 'getCookie'\n | 'getSessionStorage'\n | 'getLocaleStorage'\n | 'getHeader'\n | 'isCookieEnabled'\n >\n): Locale | undefined => {\n const { routing, internationalization } = configuration;\n const { locales } = internationalization;\n const { storage } = routing;\n\n // If storage is disabled, return undefined\n if (storage === false || options?.isCookieEnabled === false) return undefined;\n\n const storageAttributes = getStorageAttributes(storage);\n\n const isValidLocale = (value: string | null | undefined): value is Locale => {\n if (!value) return false;\n\n return locales.includes(value as Locale);\n };\n\n const readCookie = (name: string): string | undefined => {\n // Prefer provided getter (server or custom environment)\n try {\n const fromOption = options?.getCookie?.(name);\n\n if (fromOption !== null && fromOption !== undefined) return fromOption;\n } catch {}\n\n // Fallback to browser cookie parsing\n return getCookie(name);\n };\n\n // Check cookies first\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name } = storageAttributes.cookies[i];\n\n const value = readCookie(name);\n\n if (isValidLocale(value)) return value;\n }\n\n // Then check localStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const value = options?.getLocaleStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // Check sessionStorage candidates (browser only)\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const value = options?.getSessionStorage?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n\n // Finally check header candidates (server only)\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n const value = options?.getHeader?.(name);\n\n if (isValidLocale(value)) return value;\n } catch {}\n }\n};\n\n/**\n * Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @param locale - The locale to store\n */\nexport const setLocaleInStorage = (\n locale: LocalesValues,\n options?: LocaleStorageOptions\n): void => {\n // If storage is disabled, do nothing\n if (\n configuration.routing.storage === false ||\n options?.isCookieEnabled === false\n )\n return;\n\n const storageAttributes = getStorageAttributes(configuration.routing.storage);\n\n // Write to cookies (server via setCookie, client via cookieStore/document)\n for (let i = 0; i < storageAttributes.cookies.length; i++) {\n const { name, attributes } = storageAttributes.cookies[i];\n\n try {\n if (options?.setCookieStore) {\n options?.setCookieStore?.(name, locale, {\n ...attributes,\n expires:\n attributes.expires instanceof Date\n ? attributes.expires.getTime()\n : attributes.expires,\n });\n }\n } catch {\n try {\n if (options?.setCookieString) {\n const cookieString = buildCookieString(name, locale, attributes);\n\n options?.setCookieString?.(name, cookieString);\n }\n } catch {}\n }\n }\n\n // Write to localStorage (browser only)\n if (options?.setLocaleStorage) {\n for (let i = 0; i < storageAttributes.localStorage.length; i++) {\n const { name } = storageAttributes.localStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getLocaleStorage) {\n const existing = options?.getLocaleStorage?.(name);\n if (existing) continue;\n }\n options?.setLocaleStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to sessionStorage (browser only)\n if (options?.setSessionStorage) {\n for (let i = 0; i < storageAttributes.sessionStorage.length; i++) {\n const { name } = storageAttributes.sessionStorage[i];\n\n try {\n const shouldOverwrite = options?.overwrite ?? true;\n\n if (!shouldOverwrite && options?.getSessionStorage) {\n const existing = options?.getSessionStorage?.(name);\n if (existing) continue;\n }\n\n options?.setSessionStorage?.(name, locale);\n } catch {}\n }\n }\n\n // Write to headers (server only)\n if (options?.setHeader) {\n for (let i = 0; i < storageAttributes.headers.length; i++) {\n const { name } = storageAttributes.headers[i];\n\n try {\n options?.setHeader?.(name, locale);\n } catch {}\n }\n }\n};\n\n/**\n * Utility object to get and set the locale in the storage by considering the configuration\n *\n * @property getLocale - Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * Retrieves the locale from various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function checks storage locations in order of priority as defined in the configuration.\n *\n * @property setLocale - Stores the locale in various storage mechanisms (cookies, localStorage, sessionStorage, headers).\n * The function writes to all configured storage locations according to their attributes.\n * Respects overwrite flags for localStorage and sessionStorage.\n *\n * @returns The locale if found in any storage, or undefined if not found\n */\nexport const LocaleStorage = (options: LocaleStorageOptions) => ({\n getLocale: () => getLocaleFromStorage(options),\n setLocale: (locale: LocalesValues) => setLocaleInStorage(locale, options),\n});\n"],"mappings":"qPAiEA,MAAM,GACJ,EACA,EACA,IACW,CAEX,IAAM,EAAkB,CAAC,GAAG,EAAK,GADZ,mBAAmB,EAAM,GACK,CASnD,OAPI,EAAW,MAAM,EAAM,KAAK,QAAQ,EAAW,OAAO,CACtD,EAAW,QAAQ,EAAM,KAAK,UAAU,EAAW,SAAS,CAC5D,EAAW,mBAAmB,MAChC,EAAM,KAAK,WAAW,EAAW,QAAQ,aAAa,GAAG,CAEvD,EAAW,QAAQ,EAAM,KAAK,SAAS,CACvC,EAAW,UAAU,EAAM,KAAK,YAAY,EAAW,WAAW,CAC/D,EAAM,KAAK,KAAK,EA2BZ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as e}from"../interpreter/getContent/deepTransform.mjs";import{getTranslation as t}from"../interpreter/getTranslation.mjs";import{t as n}from"../transpiler/translation/translation.mjs";import{NodeType as r}from"@intlayer/types";import i from"@intlayer/config/built";const a=e=>typeof e!=`object`||!e?!1:e?.nodeType===r.Translation?!0:Array.isArray(e)?e.some(a):Object.values(e).some(a),o=e=>{let t=new Set;if(typeof e!=`object`||!e)return t;for(let n in e)t.add(n);return t},s=(e,t)=>{if(typeof e!=`object`||typeof t!=`object`)return typeof e==typeof t;if(e===null||t===null)return e===t;if(Array.isArray(e)!==Array.isArray(t))return!1;let n=o(e),r=o(t);if(n.size!==r.size)return!1;for(let e of n)if(!r.has(e))return!1;return!0},c=e=>{let t=Object.keys(e),n=new Set;if(t.length<=1)return{hasInconsistency:!1,localesWithMissingKeys:n};let r=(e,t)=>{let n=new Set,i=new Set,a=new Map;for(let[e,n]of t.entries())if(typeof n==`object`&&n&&!Array.isArray(n)){a.set(e,n);let t=o(n);for(let e of t)i.add(e)}if(a.size===0)return n;for(let[e,t]of a.entries())o(t).size!==i.size&&n.add(e);for(let t of i){let i=new Map;for(let[e,n]of a.entries())n[t]!==void 0&&i.set(e,n[t]);if(i.size>1){let a=r(e?`${e}.${t}`:t,i);for(let e of a)n.add(e)}}return n},i=new Map;for(let n of t)i.set(n,e[n]);let a=r(``,i),s=a.size>0;for(let e of a)n.add(e);return{hasInconsistency:s,localesWithMissingKeys:n}},l=e=>{if(e.length<=1)return!0;let t=e[0];for(let n=1;n<e.length;n++)if(!s(t,e[n]))return!1;return!0},u=e=>({id:`filter-missing-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(o,s,u)=>{if(typeof o==`object`&&o?.nodeType===r.Translation){let a=structuredClone(o[r.Translation]),l=Object.keys(a).includes(e),{hasInconsistency:d,localesWithMissingKeys:f}=c(a),p=d&&f.has(e);if(l&&!p)return;for(let e in a){let t={...s,children:a[e],keyPath:[...s.keyPath,{type:r.Translation,key:e}]};a[e]=u(a[e],{...t,plugins:[...(s.plugins??[]).filter(e=>e.id!==`filter-missing-translations-only-plugin`)]})}let m=i?.internationalization?.defaultLocale,h=Object.keys(a);if(h.length===0)return;let g=h.includes(m)?m:h[0],_=t(a,m,g);return n({[g]:_})}else if(typeof o==`object`&&o&&!Array.isArray(o)&&!o?.nodeType){let e={},t=!1,n=[],i=[];for(let c in o){let l=o[c],d=u(l,{...s,children:l,keyPath:[...s.keyPath,{type:r.Object,key:c}]});if(l===null||typeof l!=`object`&&typeof l!=`function`){l!==void 0&&i.push(l);continue}d!==void 0&&(a(l)||Array.isArray(l))&&(e[c]=d,t=!0,Array.isArray(d)&&n.push(c))}if(n.length>0&&i.length>0){let r=n[0];Array.isArray(e[r])&&(e[r]=[...e[r],...i],t=!0)}return t?e:void 0}else if(Array.isArray(o)){let e=l(o),t=o.map((e,t)=>u(e,{...s,children:e,keyPath:[...s.keyPath,{type:r.Array,key:t}]})).filter(e=>e!=null);return!e&&t.length===0?o:t.length>0?t:void 0}return o}}),d=(t,n,r)=>{let i=[u(n),...r.plugins??[]],a=e(t,{...r,plugins:i});return a===void 0?{}:JSON.parse(JSON.stringify(a))},f=(e,t)=>({...e,content:d(e.content,t,{dictionaryKey:e.key,keyPath:[],plugins:[]})});export{u as filterMissingTranslationsOnlyPlugin,d as getFilterMissingTranslationsContent,f as getFilterMissingTranslationsDictionary};
1
+ import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{getTranslation as t}from"../interpreter/getTranslation.mjs";import{t as n}from"../transpiler/translation/translation.mjs";import{NodeType as r}from"@intlayer/types/nodeType";import i from"@intlayer/config/built";const a=e=>typeof e!=`object`||!e?!1:e?.nodeType===r.Translation?!0:Array.isArray(e)?e.some(a):Object.values(e).some(a),o=e=>{let t=new Set;if(typeof e!=`object`||!e)return t;for(let n in e)t.add(n);return t},s=(e,t)=>{if(typeof e!=`object`||typeof t!=`object`)return typeof e==typeof t;if(e===null||t===null)return e===t;if(Array.isArray(e)!==Array.isArray(t))return!1;let n=o(e),r=o(t);if(n.size!==r.size)return!1;for(let e of n)if(!r.has(e))return!1;return!0},c=e=>{let t=Object.keys(e),n=new Set;if(t.length<=1)return{hasInconsistency:!1,localesWithMissingKeys:n};let r=(e,t)=>{let n=new Set,i=new Set,a=new Map;for(let[e,n]of t.entries())if(typeof n==`object`&&n&&!Array.isArray(n)){a.set(e,n);let t=o(n);for(let e of t)i.add(e)}if(a.size===0)return n;for(let[e,t]of a.entries())o(t).size!==i.size&&n.add(e);for(let t of i){let i=new Map;for(let[e,n]of a.entries())n[t]!==void 0&&i.set(e,n[t]);if(i.size>1){let a=r(e?`${e}.${t}`:t,i);for(let e of a)n.add(e)}}return n},i=new Map;for(let n of t)i.set(n,e[n]);let a=r(``,i),s=a.size>0;for(let e of a)n.add(e);return{hasInconsistency:s,localesWithMissingKeys:n}},l=e=>{if(e.length<=1)return!0;let t=e[0];for(let n=1;n<e.length;n++)if(!s(t,e[n]))return!1;return!0},u=e=>({id:`filter-missing-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(o,s,u)=>{if(typeof o==`object`&&o?.nodeType===r.Translation){let a=structuredClone(o[r.Translation]),l=Object.keys(a).includes(e),{hasInconsistency:d,localesWithMissingKeys:f}=c(a),p=d&&f.has(e);if(l&&!p)return;for(let e in a){let t={...s,children:a[e],keyPath:[...s.keyPath,{type:r.Translation,key:e}]};a[e]=u(a[e],{...t,plugins:[...(s.plugins??[]).filter(e=>e.id!==`filter-missing-translations-only-plugin`)]})}let m=i?.internationalization?.defaultLocale,h=Object.keys(a);if(h.length===0)return;let g=h.includes(m)?m:h[0],_=t(a,m,g);return n({[g]:_})}else if(typeof o==`object`&&o&&!Array.isArray(o)&&!o?.nodeType){let e={},t=!1,n=[],i=[];for(let c in o){let l=o[c],d=u(l,{...s,children:l,keyPath:[...s.keyPath,{type:r.Object,key:c}]});if(l===null||typeof l!=`object`&&typeof l!=`function`){l!==void 0&&i.push(l);continue}d!==void 0&&(a(l)||Array.isArray(l))&&(e[c]=d,t=!0,Array.isArray(d)&&n.push(c))}if(n.length>0&&i.length>0){let r=n[0];Array.isArray(e[r])&&(e[r]=[...e[r],...i],t=!0)}return t?e:void 0}else if(Array.isArray(o)){let e=l(o),t=o.map((e,t)=>u(e,{...s,children:e,keyPath:[...s.keyPath,{type:r.Array,key:t}]})).filter(e=>e!=null);return!e&&t.length===0?o:t.length>0?t:void 0}return o}}),d=(t,n,r)=>{let i=[u(n),...r.plugins??[]],a=e(t,{...r,plugins:i});return a===void 0?{}:JSON.parse(JSON.stringify(a))},f=(e,t)=>({...e,content:d(e.content,t,{dictionaryKey:e.key,keyPath:[],plugins:[]})});export{u as filterMissingTranslationsOnlyPlugin,d as getFilterMissingTranslationsContent,f as getFilterMissingTranslationsDictionary};
2
2
  //# sourceMappingURL=getFilterMissingTranslationsContent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilterMissingTranslationsContent.mjs","names":["tCore"],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport { type TranslationContent, t as tCore } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/**\n * Get all keys from an object, recursively\n */\nconst getObjectKeys = (obj: any): Set<string> => {\n const keys = new Set<string>();\n\n if (typeof obj !== 'object' || obj === null) {\n return keys;\n }\n\n for (const key in obj) {\n keys.add(key);\n }\n\n return keys;\n};\n\n/**\n * Check if two objects have the same structure (same keys)\n */\nconst hasSameStructure = (obj1: any, obj2: any): boolean => {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {\n return typeof obj1 === typeof obj2;\n }\n\n if (obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n\n if (Array.isArray(obj1) !== Array.isArray(obj2)) {\n return false;\n }\n\n const keys1 = getObjectKeys(obj1);\n const keys2 = getObjectKeys(obj2);\n\n if (keys1.size !== keys2.size) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.has(key)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Check if all locales in a translation node have the same structure (recursively)\n * Returns an object with locales that have missing keys\n */\nconst checkTranslationStructureConsistency = (\n translationNode: Record<string, any>\n): { hasInconsistency: boolean; localesWithMissingKeys: Set<string> } => {\n const locales = Object.keys(translationNode);\n const localesWithMissingKeys = new Set<string>();\n\n if (locales.length <= 1) {\n return { hasInconsistency: false, localesWithMissingKeys };\n }\n\n // Helper function to check structure recursively\n const checkStructureRecursive = (\n path: string,\n localeValues: Map<string, any>\n ): Set<string> => {\n const localesWithIssues = new Set<string>();\n\n // Get all unique keys across all locale values at this path\n const allKeys = new Set<string>();\n const objectLocales = new Map<string, any>();\n\n for (const [locale, value] of localeValues.entries()) {\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n objectLocales.set(locale, value);\n const keys = getObjectKeys(value);\n for (const key of keys) {\n allKeys.add(key);\n }\n }\n }\n\n // If no objects at this level, no inconsistency\n if (objectLocales.size === 0) {\n return localesWithIssues;\n }\n\n // Check if each locale has all the keys at this level\n for (const [locale, value] of objectLocales.entries()) {\n const keys = getObjectKeys(value);\n if (keys.size !== allKeys.size) {\n localesWithIssues.add(locale);\n }\n }\n\n // Recursively check nested objects\n for (const key of allKeys) {\n const nestedValues = new Map<string, any>();\n for (const [locale, value] of objectLocales.entries()) {\n if (value[key] !== undefined) {\n nestedValues.set(locale, value[key]);\n }\n }\n\n if (nestedValues.size > 1) {\n const nestedIssues = checkStructureRecursive(\n path ? `${path}.${key}` : key,\n nestedValues\n );\n for (const locale of nestedIssues) {\n localesWithIssues.add(locale);\n }\n }\n }\n\n return localesWithIssues;\n };\n\n // Start recursive check from root\n const rootValues = new Map<string, any>();\n for (const locale of locales) {\n rootValues.set(locale, translationNode[locale]);\n }\n\n const issuesFound = checkStructureRecursive('', rootValues);\n const hasInconsistency = issuesFound.size > 0;\n\n for (const locale of issuesFound) {\n localesWithMissingKeys.add(locale);\n }\n\n return { hasInconsistency, localesWithMissingKeys };\n};\n\n/**\n * Check if array elements have consistent structures\n */\nconst checkArrayStructureConsistency = (arr: any[]): boolean => {\n if (arr.length <= 1) {\n return true;\n }\n\n const firstElement = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (!hasSameStructure(firstElement, arr[i])) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterMissingTranslationsOnlyPlugin = (\n localeToCheck: LocalesValues\n): Plugins => ({\n id: 'filter-missing-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);\n\n // Check for structural inconsistencies across locales\n const { hasInconsistency, localesWithMissingKeys } =\n checkTranslationStructureConsistency(result);\n\n // If there's a structural inconsistency and the locale being checked\n // has missing keys, treat it as a missing translation\n const hasStructuralIssue =\n hasInconsistency && localesWithMissingKeys.has(localeToCheck);\n\n if (hasLocaleTranslation && !hasStructuralIssue) {\n return undefined; // Return undefined to remove the node\n }\n\n // Transform nested content\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) =>\n plugin.id !== 'filter-missing-translations-only-plugin'\n ),\n ],\n }\n );\n }\n\n // Return the base locale content as a translation node\n // If base locale is missing, use any available locale as fallback\n const baseLocale = configuration?.internationalization?.defaultLocale;\n const availableLocales = Object.keys(result);\n\n if (availableLocales.length === 0) {\n return undefined; // No translations available\n }\n\n // Try to get the base locale first, then any available locale as fallback\n const fallbackLocale = availableLocales.includes(baseLocale)\n ? baseLocale\n : availableLocales[0];\n\n const fallbackValue = getTranslation(result, baseLocale, fallbackLocale);\n\n // Return the translation node structure with only the fallback locale\n return tCore({ [fallbackLocale]: fallbackValue });\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, include only children that are related to translations\n // - Keep children that contain translation nodes (directly or nested)\n // - Keep arrays (they may mix translated and non-translated values)\n // - Exclude primitive values (string/number/boolean/null/undefined) at object level\n const result: Record<string, any> = {};\n let hasMissingTranslations = false;\n const arrayKeysIncluded: string[] = [];\n const primitiveSiblingsToAppend: any[] = [];\n\n for (const key in node as any) {\n const originalChild = (node as any)[key];\n const childProps = {\n ...props,\n children: originalChild,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n const transformedChild = deepTransformNode(originalChild, childProps);\n\n const isPrimitiveSibling =\n originalChild === null ||\n (typeof originalChild !== 'object' &&\n typeof originalChild !== 'function');\n\n if (isPrimitiveSibling) {\n // Defer primitives; they may be appended to an array sibling later\n if (originalChild !== undefined) {\n primitiveSiblingsToAppend.push(originalChild);\n }\n continue;\n }\n\n const includeChild =\n transformedChild !== undefined &&\n (hasTranslationNodes(originalChild) || Array.isArray(originalChild));\n\n if (includeChild) {\n result[key] = transformedChild;\n hasMissingTranslations = true;\n if (Array.isArray(transformedChild)) {\n arrayKeysIncluded.push(key);\n }\n }\n }\n\n // If any array child is present, append primitive siblings into the first array\n if (\n arrayKeysIncluded.length > 0 &&\n primitiveSiblingsToAppend.length > 0\n ) {\n const targetArrayKey = arrayKeysIncluded[0];\n // Ensure array exists in result (it should, but be defensive)\n if (Array.isArray(result[targetArrayKey])) {\n result[targetArrayKey] = [\n ...result[targetArrayKey],\n ...primitiveSiblingsToAppend,\n ];\n hasMissingTranslations = true;\n }\n }\n\n // Only return the object if it has missing translations-related content\n return hasMissingTranslations ? result : undefined;\n } else if (Array.isArray(node)) {\n // Check if array elements have consistent structures\n const hasConsistentStructure = checkArrayStructureConsistency(node);\n\n // For arrays, only include items that have missing translations\n const result = node\n .map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n })\n .filter((item) => item !== null && item !== undefined);\n\n // If there's structural inconsistency in the array, include it\n // even if it has no missing translations, to flag the issue\n if (!hasConsistentStructure && result.length === 0) {\n // Return a marker to indicate structural inconsistency\n return node; // Return original array to show the issue\n }\n\n // Only return the array if it has items with missing translations\n return result.length > 0 ? result : undefined;\n }\n\n return node; // Return non-translation content as is\n },\n});\n\n/**\n * For each translation node, it compare is both localeToCheck and baseLocale are present.\n *\n * If yes, it should remove the node from the content.\n * If no, it should keep the node\n *\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * locale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\nexport const getFilterMissingTranslationsContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n localeToCheck: L,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterMissingTranslationsOnlyPlugin(localeToCheck),\n ...(nodeProps.plugins ?? []),\n ];\n\n const result = deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n // Stringify the result to remove the undefined values\n if (result === undefined) {\n // No missing translations found\n return {} as DeepTransformContent<T>;\n }\n return JSON.parse(JSON.stringify(result));\n};\n\nexport const getFilterMissingTranslationsDictionary = (\n dictionary: Dictionary,\n localeToCheck: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterMissingTranslationsContent(\n dictionary.content,\n localeToCheck,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n ),\n});\n"],"mappings":"kSAmBA,MAAM,EAAuB,GACvB,OAAO,GAAS,WAAY,EACvB,GAGL,GAAM,WAAa,EAAS,YACvB,GAGL,MAAM,QAAQ,EAAK,CACd,EAAK,KAAK,EAAoB,CAGhC,OAAO,OAAO,EAAK,CAAC,KAAK,EAAoB,CAMhD,EAAiB,GAA0B,CAC/C,IAAM,EAAO,IAAI,IAEjB,GAAI,OAAO,GAAQ,WAAY,EAC7B,OAAO,EAGT,IAAK,IAAM,KAAO,EAChB,EAAK,IAAI,EAAI,CAGf,OAAO,GAMH,GAAoB,EAAW,IAAuB,CAC1D,GAAI,OAAO,GAAS,UAAY,OAAO,GAAS,SAC9C,OAAO,OAAO,GAAS,OAAO,EAGhC,GAAI,IAAS,MAAQ,IAAS,KAC5B,OAAO,IAAS,EAGlB,GAAI,MAAM,QAAQ,EAAK,GAAK,MAAM,QAAQ,EAAK,CAC7C,MAAO,GAGT,IAAM,EAAQ,EAAc,EAAK,CAC3B,EAAQ,EAAc,EAAK,CAEjC,GAAI,EAAM,OAAS,EAAM,KACvB,MAAO,GAGT,IAAK,IAAM,KAAO,EAChB,GAAI,CAAC,EAAM,IAAI,EAAI,CACjB,MAAO,GAIX,MAAO,IAOH,EACJ,GACuE,CACvE,IAAM,EAAU,OAAO,KAAK,EAAgB,CACtC,EAAyB,IAAI,I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,CACX,QAAS,EAAE,CACZ,CACF,CACF"}
1
+ {"version":3,"file":"getFilterMissingTranslationsContent.mjs","names":["tCore"],"sources":["../../../src/deepTransformPlugins/getFilterMissingTranslationsContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport { type TranslationContent, t as tCore } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/**\n * Get all keys from an object, recursively\n */\nconst getObjectKeys = (obj: any): Set<string> => {\n const keys = new Set<string>();\n\n if (typeof obj !== 'object' || obj === null) {\n return keys;\n }\n\n for (const key in obj) {\n keys.add(key);\n }\n\n return keys;\n};\n\n/**\n * Check if two objects have the same structure (same keys)\n */\nconst hasSameStructure = (obj1: any, obj2: any): boolean => {\n if (typeof obj1 !== 'object' || typeof obj2 !== 'object') {\n return typeof obj1 === typeof obj2;\n }\n\n if (obj1 === null || obj2 === null) {\n return obj1 === obj2;\n }\n\n if (Array.isArray(obj1) !== Array.isArray(obj2)) {\n return false;\n }\n\n const keys1 = getObjectKeys(obj1);\n const keys2 = getObjectKeys(obj2);\n\n if (keys1.size !== keys2.size) {\n return false;\n }\n\n for (const key of keys1) {\n if (!keys2.has(key)) {\n return false;\n }\n }\n\n return true;\n};\n\n/**\n * Check if all locales in a translation node have the same structure (recursively)\n * Returns an object with locales that have missing keys\n */\nconst checkTranslationStructureConsistency = (\n translationNode: Record<string, any>\n): { hasInconsistency: boolean; localesWithMissingKeys: Set<string> } => {\n const locales = Object.keys(translationNode);\n const localesWithMissingKeys = new Set<string>();\n\n if (locales.length <= 1) {\n return { hasInconsistency: false, localesWithMissingKeys };\n }\n\n // Helper function to check structure recursively\n const checkStructureRecursive = (\n path: string,\n localeValues: Map<string, any>\n ): Set<string> => {\n const localesWithIssues = new Set<string>();\n\n // Get all unique keys across all locale values at this path\n const allKeys = new Set<string>();\n const objectLocales = new Map<string, any>();\n\n for (const [locale, value] of localeValues.entries()) {\n if (\n typeof value === 'object' &&\n value !== null &&\n !Array.isArray(value)\n ) {\n objectLocales.set(locale, value);\n const keys = getObjectKeys(value);\n for (const key of keys) {\n allKeys.add(key);\n }\n }\n }\n\n // If no objects at this level, no inconsistency\n if (objectLocales.size === 0) {\n return localesWithIssues;\n }\n\n // Check if each locale has all the keys at this level\n for (const [locale, value] of objectLocales.entries()) {\n const keys = getObjectKeys(value);\n if (keys.size !== allKeys.size) {\n localesWithIssues.add(locale);\n }\n }\n\n // Recursively check nested objects\n for (const key of allKeys) {\n const nestedValues = new Map<string, any>();\n for (const [locale, value] of objectLocales.entries()) {\n if (value[key] !== undefined) {\n nestedValues.set(locale, value[key]);\n }\n }\n\n if (nestedValues.size > 1) {\n const nestedIssues = checkStructureRecursive(\n path ? `${path}.${key}` : key,\n nestedValues\n );\n for (const locale of nestedIssues) {\n localesWithIssues.add(locale);\n }\n }\n }\n\n return localesWithIssues;\n };\n\n // Start recursive check from root\n const rootValues = new Map<string, any>();\n for (const locale of locales) {\n rootValues.set(locale, translationNode[locale]);\n }\n\n const issuesFound = checkStructureRecursive('', rootValues);\n const hasInconsistency = issuesFound.size > 0;\n\n for (const locale of issuesFound) {\n localesWithMissingKeys.add(locale);\n }\n\n return { hasInconsistency, localesWithMissingKeys };\n};\n\n/**\n * Check if array elements have consistent structures\n */\nconst checkArrayStructureConsistency = (arr: any[]): boolean => {\n if (arr.length <= 1) {\n return true;\n }\n\n const firstElement = arr[0];\n\n for (let i = 1; i < arr.length; i++) {\n if (!hasSameStructure(firstElement, arr[i])) {\n return false;\n }\n }\n\n return true;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterMissingTranslationsOnlyPlugin = (\n localeToCheck: LocalesValues\n): Plugins => ({\n id: 'filter-missing-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);\n\n // Check for structural inconsistencies across locales\n const { hasInconsistency, localesWithMissingKeys } =\n checkTranslationStructureConsistency(result);\n\n // If there's a structural inconsistency and the locale being checked\n // has missing keys, treat it as a missing translation\n const hasStructuralIssue =\n hasInconsistency && localesWithMissingKeys.has(localeToCheck);\n\n if (hasLocaleTranslation && !hasStructuralIssue) {\n return undefined; // Return undefined to remove the node\n }\n\n // Transform nested content\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) =>\n plugin.id !== 'filter-missing-translations-only-plugin'\n ),\n ],\n }\n );\n }\n\n // Return the base locale content as a translation node\n // If base locale is missing, use any available locale as fallback\n const baseLocale = configuration?.internationalization?.defaultLocale;\n const availableLocales = Object.keys(result);\n\n if (availableLocales.length === 0) {\n return undefined; // No translations available\n }\n\n // Try to get the base locale first, then any available locale as fallback\n const fallbackLocale = availableLocales.includes(baseLocale)\n ? baseLocale\n : availableLocales[0];\n\n const fallbackValue = getTranslation(result, baseLocale, fallbackLocale);\n\n // Return the translation node structure with only the fallback locale\n return tCore({ [fallbackLocale]: fallbackValue });\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, include only children that are related to translations\n // - Keep children that contain translation nodes (directly or nested)\n // - Keep arrays (they may mix translated and non-translated values)\n // - Exclude primitive values (string/number/boolean/null/undefined) at object level\n const result: Record<string, any> = {};\n let hasMissingTranslations = false;\n const arrayKeysIncluded: string[] = [];\n const primitiveSiblingsToAppend: any[] = [];\n\n for (const key in node as any) {\n const originalChild = (node as any)[key];\n const childProps = {\n ...props,\n children: originalChild,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n const transformedChild = deepTransformNode(originalChild, childProps);\n\n const isPrimitiveSibling =\n originalChild === null ||\n (typeof originalChild !== 'object' &&\n typeof originalChild !== 'function');\n\n if (isPrimitiveSibling) {\n // Defer primitives; they may be appended to an array sibling later\n if (originalChild !== undefined) {\n primitiveSiblingsToAppend.push(originalChild);\n }\n continue;\n }\n\n const includeChild =\n transformedChild !== undefined &&\n (hasTranslationNodes(originalChild) || Array.isArray(originalChild));\n\n if (includeChild) {\n result[key] = transformedChild;\n hasMissingTranslations = true;\n if (Array.isArray(transformedChild)) {\n arrayKeysIncluded.push(key);\n }\n }\n }\n\n // If any array child is present, append primitive siblings into the first array\n if (\n arrayKeysIncluded.length > 0 &&\n primitiveSiblingsToAppend.length > 0\n ) {\n const targetArrayKey = arrayKeysIncluded[0];\n // Ensure array exists in result (it should, but be defensive)\n if (Array.isArray(result[targetArrayKey])) {\n result[targetArrayKey] = [\n ...result[targetArrayKey],\n ...primitiveSiblingsToAppend,\n ];\n hasMissingTranslations = true;\n }\n }\n\n // Only return the object if it has missing translations-related content\n return hasMissingTranslations ? result : undefined;\n } else if (Array.isArray(node)) {\n // Check if array elements have consistent structures\n const hasConsistentStructure = checkArrayStructureConsistency(node);\n\n // For arrays, only include items that have missing translations\n const result = node\n .map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n })\n .filter((item) => item !== null && item !== undefined);\n\n // If there's structural inconsistency in the array, include it\n // even if it has no missing translations, to flag the issue\n if (!hasConsistentStructure && result.length === 0) {\n // Return a marker to indicate structural inconsistency\n return node; // Return original array to show the issue\n }\n\n // Only return the array if it has items with missing translations\n return result.length > 0 ? result : undefined;\n }\n\n return node; // Return non-translation content as is\n },\n});\n\n/**\n * For each translation node, it compare is both localeToCheck and baseLocale are present.\n *\n * If yes, it should remove the node from the content.\n * If no, it should keep the node\n *\n * In complete mode, for large dictionaries, we want to filter all content that is already translated\n *\n * locale: fr\n *\n * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}\n * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }\n *\n */\nexport const getFilterMissingTranslationsContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n localeToCheck: L,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n filterMissingTranslationsOnlyPlugin(localeToCheck),\n ...(nodeProps.plugins ?? []),\n ];\n\n const result = deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n // Stringify the result to remove the undefined values\n if (result === undefined) {\n // No missing translations found\n return {} as DeepTransformContent<T>;\n }\n return JSON.parse(JSON.stringify(result));\n};\n\nexport const getFilterMissingTranslationsDictionary = (\n dictionary: Dictionary,\n localeToCheck: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterMissingTranslationsContent(\n dictionary.content,\n localeToCheck,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n }\n ),\n});\n"],"mappings":"2SAoBA,MAAM,EAAuB,GAC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,EAAO,GAAkB,CACvB,GAAG,EAAO,GACV,GAAG,EACJ,CACD,EAAyB,IAK7B,OAAO,EAAyB,EAAS,IAAA,WAChC,MAAM,QAAQ,EAAK,CAAE,CAE9B,IAAM,EAAyB,EAA+B,EAAK,CAG7D,EAAS,EACZ,KAAK,EAAO,IASJ,EAAkB,EARN,CACjB,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,MAAO,IAAK,EAAO,CACrC,CACF,CAC0C,CAC3C,CACD,OAAQ,GAAS,GAAS,KAA2B,CAUxD,MANI,CAAC,GAA0B,EAAO,SAAW,EAExC,EAIF,EAAO,OAAS,EAAI,EAAS,IAAA,GAGtC,OAAO,GAEV,EAgBY,GAIX,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAAoC,EAAc,CAClD,GAAI,EAAU,SAAW,EAAE,CAC5B,CAEK,EAAS,EAAkB,EAAM,CACrC,GAAG,EACH,UACD,CAAC,CAOF,OAJI,IAAW,IAAA,GAEN,EAAE,CAEJ,KAAK,MAAM,KAAK,UAAU,EAAO,CAAC,EAG9B,GACX,EACA,KACI,CACJ,GAAG,EACH,QAAS,EACP,EAAW,QACX,EACA,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,EAAE,CACZ,CACF,CACF"}
@@ -1,2 +1,2 @@
1
- import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{getTranslation as t}from"../interpreter/getTranslation.mjs";import{NodeType as n}from"@intlayer/types";import r from"@intlayer/config/built";const i=e=>typeof e!=`object`||!e?!1:e?.nodeType===n.Translation?!0:Array.isArray(e)?e.some(i):Object.values(e).some(i),a=(e,r)=>({id:`filter-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(a,o,s)=>{if(typeof a==`object`&&a?.nodeType===n.Translation){let i=structuredClone(a[n.Translation]);for(let e in i){let t={...o,children:i[e],keyPath:[...o.keyPath,{type:n.Translation,key:e}]};i[e]=s(i[e],{...t,plugins:[...(o.plugins??[]).filter(e=>e.id!==`filter-translations-only-plugin`)]})}return t(i,e,r)}else if(typeof a==`object`&&a&&!Array.isArray(a)&&!a?.nodeType){let e={};for(let t in a)if(i(a[t])){let r={...o,children:a[t],keyPath:[...o.keyPath,{type:n.Object,key:t}]};e[t]=s(a[t],r)}return e}else if(Array.isArray(a))return a.map((e,t)=>s(e,{...o,children:e,keyPath:[...o.keyPath,{type:n.Array,key:t}]}));return`to remove from the object`}}),o=(t,n=r?.internationalization?.defaultLocale,i,o)=>{let s=[a(n,o),...i.plugins??[]];return e(t,{...i,plugins:s})},s=(e,t=r?.internationalization?.defaultLocale,n)=>({...e,content:o(e.content,t,{dictionaryKey:e.key,keyPath:[]},n)});export{a as filterTranslationsOnlyPlugin,o as getFilterTranslationsOnlyContent,s as getFilterTranslationsOnlyDictionary};
1
+ import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{getTranslation as t}from"../interpreter/getTranslation.mjs";import{NodeType as n}from"@intlayer/types/nodeType";import r from"@intlayer/config/built";const i=e=>typeof e!=`object`||!e?!1:e?.nodeType===n.Translation?!0:Array.isArray(e)?e.some(i):Object.values(e).some(i),a=(e,r)=>({id:`filter-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(a,o,s)=>{if(typeof a==`object`&&a?.nodeType===n.Translation){let i=structuredClone(a[n.Translation]);for(let e in i){let t={...o,children:i[e],keyPath:[...o.keyPath,{type:n.Translation,key:e}]};i[e]=s(i[e],{...t,plugins:[...(o.plugins??[]).filter(e=>e.id!==`filter-translations-only-plugin`)]})}return t(i,e,r)}else if(typeof a==`object`&&a&&!Array.isArray(a)&&!a?.nodeType){let e={};for(let t in a)if(i(a[t])){let r={...o,children:a[t],keyPath:[...o.keyPath,{type:n.Object,key:t}]};e[t]=s(a[t],r)}return e}else if(Array.isArray(a))return a.map((e,t)=>s(e,{...o,children:e,keyPath:[...o.keyPath,{type:n.Array,key:t}]}));return`to remove from the object`}}),o=(t,n=r?.internationalization?.defaultLocale,i,o)=>{let s=[a(n,o),...i.plugins??[]];return e(t,{...i,plugins:s})},s=(e,t=r?.internationalization?.defaultLocale,n)=>({...e,content:o(e.content,t,{dictionaryKey:e.key,keyPath:[]},n)});export{a as filterTranslationsOnlyPlugin,o as getFilterTranslationsOnlyContent,s as getFilterTranslationsOnlyDictionary};
2
2
  //# sourceMappingURL=getFilterTranslationsOnlyContent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilterTranslationsOnlyContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type {\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport { type ContentNode, type KeyPath, NodeType } from '@intlayer/types';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterTranslationsOnlyPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'filter-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'filter-translations-only-plugin'\n ),\n ],\n }\n );\n }\n return getTranslation(result, locale, fallback);\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, filter out properties that don't contain translations\n const result: Record<string, any> = {};\n for (const key in node as any) {\n if (hasTranslationNodes(node[key as unknown as keyof typeof node])) {\n const childProps = {\n ...props,\n children: node[key as unknown as keyof typeof node],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n node[key as unknown as keyof typeof node],\n childProps\n );\n }\n }\n return result;\n } else if (Array.isArray(node)) {\n // For arrays, keep all items but transform them\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n return 'to remove from the object';\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getFilterTranslationsOnlyContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L = configuration?.internationalization?.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues\n) => {\n const plugins: Plugins[] = [\n filterTranslationsOnlyPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getFilterTranslationsOnlyDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues = configuration?.internationalization\n ?.defaultLocale as LocalesValues,\n fallback?: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterTranslationsOnlyContent(\n dictionary.content,\n locale,\n { dictionaryKey: dictionary.key, keyPath: [] },\n fallback\n ),\n});\n"],"mappings":"oOAmBA,MAAM,EAAuB,GACvB,OAAO,GAAS,WAAY,EACvB,GAGL,GAAM,WAAa,EAAS,YACvB,GAGL,MAAM,QAAQ,EAAK,CACd,EAAK,KAAK,EAAoB,CAGhC,OAAO,OAAO,EAAK,CAAC,KAAK,EAAoB,CAIzC,GACX,EACA,KACa,CACb,GAAI,kCACJ,UAAY,GAEH,OAAO,GAAS,YAAY,EAErC,WAAY,EAAmB,EAAO,IAAsB,CAC1D,GAAI,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,YAAa,CACvE,IAAM,EAAS,gBACZ,EAA4B,EAAS,aACvC,CAED,IAAK,IAAM,KAAO,EAAQ,CACxB,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAO,GACjB,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,YAAa,MAAK,CACpC,CACF,CACD,EAAO,GAAyC,EAC9C,EAAO,GACP,CACE,GAAG,EACH,QAAS,CACP,IAAI,EAAM,SAAY,EAAE,EAAgB,OACrC,GAAW,EAAO,KAAO,kCAC3B,CACF,CACF,CACF,CAEH,OAAO,EAAe,EAAQ,EAAQ,EAAS,SAE/C,OAAO,GAAS,UAChB,GACA,CAAC,MAAM,QAAQ,EAAK,EACpB,CAAC,GAAM,SACP,CAEA,IAAM,EAA8B,EAAE,CACtC,IAAK,IAAM,KAAO,EAChB,GAAI,EAAoB,EAAK,GAAqC,CAAE,CAClE,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAK,GACf,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,OAAQ,MAAK,CAC/B,CACF,CACD,EAAO,GAAO,EACZ,EAAK,GACL,EACD,CAGL,OAAO,UACE,MAAM,QAAQ,EAAK,CAE5B,OAAO,EAAK,KAAK,EAAO,IASf,EAAkB,EARN,CACjB,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,MAAO,IAAK,EAAO,CACrC,CACF,CAC0C,CAC3C,CAGJ,MAAO,6BAEV,EAQY,GAIX,EACA,EAAY,GAAe,sBAAsB,cACjD,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAA6B,EAAQ,EAAS,CAC9C,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GACX,EACA,EAAwB,GAAe,sBACnC,cACJ,KACI,CACJ,GAAG,EACH,QAAS,EACP,EAAW,QACX,EACA,CAAE,cAAe,EAAW,IAAK,QAAS,EAAE,CAAE,CAC9C,EACD,CACF"}
1
+ {"version":3,"file":"getFilterTranslationsOnlyContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type {\n DeclaredLocales,\n LocalesValues,\n} from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n type DeepTransformContent,\n getTranslation,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Helper function to check if a node or its children contain translation nodes\n */\nconst hasTranslationNodes = (node: any): boolean => {\n if (typeof node !== 'object' || node === null) {\n return false;\n }\n\n if (node?.nodeType === NodeType.Translation) {\n return true;\n }\n\n if (Array.isArray(node)) {\n return node.some(hasTranslationNodes);\n }\n\n return Object.values(node).some(hasTranslationNodes);\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const filterTranslationsOnlyPlugin = (\n locale: LocalesValues,\n fallback?: LocalesValues\n): Plugins => ({\n id: 'filter-translations-only-plugin',\n canHandle: (node: ContentNode) => {\n // Only handle objects and arrays, not primitives\n return typeof node === 'object' && node !== null;\n },\n transform: (node: ContentNode, props, deepTransformNode) => {\n if (typeof node === 'object' && node?.nodeType === NodeType.Translation) {\n const result = structuredClone(\n (node as TranslationContent)[NodeType.Translation]\n );\n\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Translation, key } as KeyPath,\n ],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n {\n ...childProps,\n plugins: [\n ...(props.plugins ?? ([] as Plugins[])).filter(\n (plugin) => plugin.id !== 'filter-translations-only-plugin'\n ),\n ],\n }\n );\n }\n return getTranslation(result, locale, fallback);\n } else if (\n typeof node === 'object' &&\n node !== null &&\n !Array.isArray(node) &&\n !node?.nodeType\n ) {\n // For regular objects, filter out properties that don't contain translations\n const result: Record<string, any> = {};\n for (const key in node as any) {\n if (hasTranslationNodes(node[key as unknown as keyof typeof node])) {\n const childProps = {\n ...props,\n children: node[key as unknown as keyof typeof node],\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key } as KeyPath,\n ],\n };\n result[key] = deepTransformNode(\n node[key as unknown as keyof typeof node],\n childProps\n );\n }\n }\n return result;\n } else if (Array.isArray(node)) {\n // For arrays, keep all items but transform them\n return node.map((child, index) => {\n const childProps = {\n ...props,\n children: child,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Array, key: index } as KeyPath,\n ],\n };\n return deepTransformNode(child, childProps);\n });\n }\n\n return 'to remove from the object';\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getFilterTranslationsOnlyContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L = configuration?.internationalization?.defaultLocale as L,\n nodeProps: NodeProps,\n fallback?: LocalesValues\n) => {\n const plugins: Plugins[] = [\n filterTranslationsOnlyPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getFilterTranslationsOnlyDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues = configuration?.internationalization\n ?.defaultLocale as LocalesValues,\n fallback?: LocalesValues\n) => ({\n ...dictionary,\n content: getFilterTranslationsOnlyContent(\n dictionary.content,\n locale,\n { dictionaryKey: dictionary.key, keyPath: [] },\n fallback\n ),\n});\n"],"mappings":"6OAoBA,MAAM,EAAuB,GACvB,OAAO,GAAS,WAAY,EACvB,GAGL,GAAM,WAAa,EAAS,YACvB,GAGL,MAAM,QAAQ,EAAK,CACd,EAAK,KAAK,EAAoB,CAGhC,OAAO,OAAO,EAAK,CAAC,KAAK,EAAoB,CAIzC,GACX,EACA,KACa,CACb,GAAI,kCACJ,UAAY,GAEH,OAAO,GAAS,YAAY,EAErC,WAAY,EAAmB,EAAO,IAAsB,CAC1D,GAAI,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,YAAa,CACvE,IAAM,EAAS,gBACZ,EAA4B,EAAS,aACvC,CAED,IAAK,IAAM,KAAO,EAAQ,CACxB,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAO,GACjB,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,YAAa,MAAK,CACpC,CACF,CACD,EAAO,GAAyC,EAC9C,EAAO,GACP,CACE,GAAG,EACH,QAAS,CACP,IAAI,EAAM,SAAY,EAAE,EAAgB,OACrC,GAAW,EAAO,KAAO,kCAC3B,CACF,CACF,CACF,CAEH,OAAO,EAAe,EAAQ,EAAQ,EAAS,SAE/C,OAAO,GAAS,UAChB,GACA,CAAC,MAAM,QAAQ,EAAK,EACpB,CAAC,GAAM,SACP,CAEA,IAAM,EAA8B,EAAE,CACtC,IAAK,IAAM,KAAO,EAChB,GAAI,EAAoB,EAAK,GAAqC,CAAE,CAClE,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAK,GACf,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,OAAQ,MAAK,CAC/B,CACF,CACD,EAAO,GAAO,EACZ,EAAK,GACL,EACD,CAGL,OAAO,UACE,MAAM,QAAQ,EAAK,CAE5B,OAAO,EAAK,KAAK,EAAO,IASf,EAAkB,EARN,CACjB,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,MAAO,IAAK,EAAO,CACrC,CACF,CAC0C,CAC3C,CAGJ,MAAO,6BAEV,EAQY,GAIX,EACA,EAAY,GAAe,sBAAsB,cACjD,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAA6B,EAAQ,EAAS,CAC9C,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GACX,EACA,EAAwB,GAAe,sBACnC,cACJ,KACI,CACJ,GAAG,EACH,QAAS,EACP,EAAW,QACX,EACA,CAAE,cAAe,EAAW,IAAK,QAAS,EAAE,CAAE,CAC9C,EACD,CACF"}
@@ -1,2 +1,2 @@
1
- import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{NodeType as t}from"@intlayer/types";const n=e=>({id:`filter-translations-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.Translation,transform:(n,r,i)=>{let a=n.translation,o=Object.fromEntries(Object.entries(a).filter(([t])=>e.includes(t)));return{...n,translation:i(o,{...r,keyPath:[...r.keyPath,{type:t.Object,key:t.Translation}]})}}}),r=(t,r,i)=>{let a=[n(Array.isArray(r)?r:[r]),...i.plugins??[]];return e(t,{...i,plugins:a})},i=(e,t)=>{let n=Array.isArray(t)?t:[t];return{...e,content:r(e.content,n,{dictionaryKey:e.key,keyPath:[]})}};export{r as getFilteredLocalesContent,i as getFilteredLocalesDictionary};
1
+ import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{NodeType as t}from"@intlayer/types/nodeType";const n=e=>({id:`filter-translations-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.Translation,transform:(n,r,i)=>{let a=n.translation,o=Object.fromEntries(Object.entries(a).filter(([t])=>e.includes(t)));return{...n,translation:i(o,{...r,keyPath:[...r.keyPath,{type:t.Object,key:t.Translation}]})}}}),r=(t,r,i)=>{let a=[n(Array.isArray(r)?r:[r]),...i.plugins??[]];return e(t,{...i,plugins:a})},i=(e,t)=>{let n=Array.isArray(t)?t:[t];return{...e,content:r(e.content,n,{dictionaryKey:e.key,keyPath:[]})}};export{r as getFilteredLocalesContent,i as getFilteredLocalesDictionary};
2
2
  //# sourceMappingURL=getFilteredLocalesContent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilteredLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type Dictionary,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst filterTranslationsPlugin = (locales: LocalesValues[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<LocalesValues, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as LocalesValues)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locales: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const localesArray = Array.isArray(locales) ? locales : [locales];\n\n const plugins: Plugins[] = [\n filterTranslationsPlugin(localesArray),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n\n/*\n * Remove all unneeded translation from translation node\n *\n * locale: fr\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ fr: 'Bonjour' })\n *\n * locales: [fr, en]\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ en: 'Hello', fr: 'Bonjour' })\n */\nexport const getFilteredLocalesDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues | LocalesValues[]\n) => {\n const localesArray = Array.isArray(locale) ? locale : [locale];\n\n return {\n ...dictionary,\n content: getFilteredLocalesContent(dictionary.content, localesArray, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n }),\n };\n};\n"],"mappings":"2HAYA,MAAM,EAA4B,IAAuC,CACvE,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,YAC1D,WAAY,EAAM,EAAO,IAAsB,CAC7C,IAAM,EAAiB,EAAK,YAEtB,EAAyB,OAAO,YACpC,OAAO,QAAQ,EAAe,CAAC,QAAQ,CAAC,KACtC,EAAQ,SAAS,EAAqB,CACvC,CACF,CAED,MAAO,CACL,GAAG,EACH,YAAa,EAAkB,EAAwB,CACrD,GAAG,EACH,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,OAAQ,IAAK,EAAS,YAAa,CACrD,CACF,CAAC,CACH,EAEJ,EAEY,GACX,EACA,EACA,IACG,CAGH,IAAM,EAAqB,CACzB,EAHmB,MAAM,QAAQ,EAAQ,CAAG,EAAU,CAAC,EAAQ,CAGzB,CACtC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAYS,GACX,EACA,IACG,CACH,IAAM,EAAe,MAAM,QAAQ,EAAO,CAAG,EAAS,CAAC,EAAO,CAE9D,MAAO,CACL,GAAG,EACH,QAAS,EAA0B,EAAW,QAAS,EAAc,CACnE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACZ,CAAC,CACH"}
1
+ {"version":3,"file":"getFilteredLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getFilteredLocalesContent.ts"],"sourcesContent":["import type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';;\nimport { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst filterTranslationsPlugin = (locales: LocalesValues[]): Plugins => ({\n id: 'filter-translations-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node, props, deepTransformNode) => {\n const translationMap = node.translation as Record<LocalesValues, string>;\n\n const filteredTranslationMap = Object.fromEntries(\n Object.entries(translationMap).filter(([key]) =>\n locales.includes(key as LocalesValues)\n )\n );\n\n return {\n ...node,\n translation: deepTransformNode(filteredTranslationMap, {\n ...props,\n keyPath: [\n ...props.keyPath,\n { type: NodeType.Object, key: NodeType.Translation },\n ],\n }),\n };\n },\n});\n\nexport const getFilteredLocalesContent = (\n node: ContentNode,\n locales: LocalesValues | LocalesValues[],\n nodeProps: NodeProps\n) => {\n const localesArray = Array.isArray(locales) ? locales : [locales];\n\n const plugins: Plugins[] = [\n filterTranslationsPlugin(localesArray),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n });\n};\n\n/*\n * Remove all unneeded translation from translation node\n *\n * locale: fr\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ fr: 'Bonjour' })\n *\n * locales: [fr, en]\n * t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' }) -> t({ en: 'Hello', fr: 'Bonjour' })\n */\nexport const getFilteredLocalesDictionary = (\n dictionary: Dictionary,\n locale: LocalesValues | LocalesValues[]\n) => {\n const localesArray = Array.isArray(locale) ? locale : [locale];\n\n return {\n ...dictionary,\n content: getFilteredLocalesContent(dictionary.content, localesArray, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n }),\n };\n};\n"],"mappings":"oIASA,MAAM,EAA4B,IAAuC,CACvE,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAa,EAAS,YAC1D,WAAY,EAAM,EAAO,IAAsB,CAC7C,IAAM,EAAiB,EAAK,YAEtB,EAAyB,OAAO,YACpC,OAAO,QAAQ,EAAe,CAAC,QAAQ,CAAC,KACtC,EAAQ,SAAS,EAAqB,CACvC,CACF,CAED,MAAO,CACL,GAAG,EACH,YAAa,EAAkB,EAAwB,CACrD,GAAG,EACH,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAS,OAAQ,IAAK,EAAS,YAAa,CACrD,CACF,CAAC,CACH,EAEJ,EAEY,GACX,EACA,EACA,IACG,CAGH,IAAM,EAAqB,CACzB,EAHmB,MAAM,QAAQ,EAAQ,CAAG,EAAU,CAAC,EAAQ,CAGzB,CACtC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAYS,GACX,EACA,IACG,CACH,IAAM,EAAe,MAAM,QAAQ,EAAO,CAAG,EAAS,CAAC,EAAO,CAE9D,MAAO,CACL,GAAG,EACH,QAAS,EAA0B,EAAW,QAAS,EAAc,CACnE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACZ,CAAC,CACH"}
@@ -1 +1 @@
1
- {"version":3,"file":"getLocalizedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getLocalizedContent.ts"],"sourcesContent":["import type {\n ContentNode,\n DeclaredLocales,\n Dictionary,\n LocalesValues,\n} from '@intlayer/types';\nimport {\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n translationPlugin,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n * In comparison to `getContent`, this function will only apply the translation plugin.\n * It will not transform enumerations, insertions, or other content types.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getLocalizedContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L,\n nodeProps: NodeProps,\n fallback?: LocalesValues // fallback mean that if field is not translated, it will use the default locale\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getPerLocaleDictionary = <\n T extends Dictionary,\n L extends LocalesValues,\n>(\n dictionary: T,\n locale: L,\n fallback?: LocalesValues\n): Dictionary => ({\n ...dictionary,\n locale,\n content: getLocalizedContent(\n dictionary.content,\n locale,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n },\n fallback\n ),\n});\n"],"mappings":"0JAsBA,MAAa,GAIX,EACA,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAAkB,EAAQ,EAAS,CACnC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GAIX,EACA,EACA,KACgB,CAChB,GAAG,EACH,SACA,QAAS,EACP,EAAW,QACX,EACA,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,EAAE,CACZ,CACD,EACD,CACF"}
1
+ {"version":3,"file":"getLocalizedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getLocalizedContent.ts"],"sourcesContent":["import type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { DeclaredLocales, LocalesValues } from '@intlayer/types/module_augmentation';\nimport {\n type DeepTransformContent,\n type NodeProps,\n type Plugins,\n translationPlugin,\n} from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\n\n/**\n * Transforms a node in a single pass, applying each plugin as needed.\n * In comparison to `getContent`, this function will only apply the translation plugin.\n * It will not transform enumerations, insertions, or other content types.\n *\n * @param node The node to transform.\n * @param locale The locale to use if your transformers need it (e.g. for translations).\n */\nexport const getLocalizedContent = <\n T extends ContentNode,\n L extends LocalesValues = DeclaredLocales,\n>(\n node: T,\n locale: L,\n nodeProps: NodeProps,\n fallback?: LocalesValues // fallback mean that if field is not translated, it will use the default locale\n) => {\n const plugins: Plugins[] = [\n translationPlugin(locale, fallback),\n ...(nodeProps.plugins ?? []),\n ];\n\n return deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n};\n\nexport const getPerLocaleDictionary = <\n T extends Dictionary,\n L extends LocalesValues,\n>(\n dictionary: T,\n locale: L,\n fallback?: LocalesValues\n): Dictionary => ({\n ...dictionary,\n locale,\n content: getLocalizedContent(\n dictionary.content,\n locale,\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [],\n },\n fallback\n ),\n});\n"],"mappings":"0JAkBA,MAAa,GAIX,EACA,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAAkB,EAAQ,EAAS,CACnC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAO,EAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GAIX,EACA,EACA,KACgB,CAChB,GAAG,EACH,SACA,QAAS,EACP,EAAW,QACX,EACA,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,EAAE,CACZ,CACD,EACD,CACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"getMaskContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMaskContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types';\nimport { deepTransformNode, type Plugins } from '../interpreter';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const getMaskContent = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":"gFAGA,MAAM,EAA+B,CACnC,GAAI,yBACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAO,GAAM,UAAa,SACxD,WAAY,EAAM,EAAO,IACvB,EAAkB,EAAK,EAAK,UAAW,EAAM,CAChD,CAGY,EAA2B,CACtC,GAAI,oBACJ,UAAY,GAAS,OAAO,GAAS,UAAY,OAAO,GAAS,SACjE,cAAiB,GAClB,CAEY,EAAkB,IAA6B,CAC1D,GAAG,EACH,QAAS,EAAkB,EAAO,QAAS,CACzC,cAAe,EAAO,IACtB,QAAS,EAAE,CACX,QAAS,CAAC,EAAqB,EAAgB,CAChD,CAAC,CACH"}
1
+ {"version":3,"file":"getMaskContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMaskContent.ts"],"sourcesContent":["import type { Dictionary } from '@intlayer/types/dictionary';\nimport { deepTransformNode, type Plugins } from '../interpreter';\n\nconst passTypedNodePlugin: Plugins = {\n id: 'pass-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node, props, deepTransformNode) =>\n deepTransformNode(node[node.nodeType], props),\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const buildMaskPlugin: Plugins = {\n id: 'build-mask-plugin',\n canHandle: (node) => typeof node === 'string' || typeof node === 'number',\n transform: () => true,\n};\n\nexport const getMaskContent = (source: Dictionary): any => ({\n ...source,\n content: deepTransformNode(source.content, {\n dictionaryKey: source.key,\n keyPath: [],\n plugins: [passTypedNodePlugin, buildMaskPlugin],\n }),\n});\n"],"mappings":"gFAGA,MAAM,EAA+B,CACnC,GAAI,yBACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAO,GAAM,UAAa,SACxD,WAAY,EAAM,EAAO,IACvB,EAAkB,EAAK,EAAK,UAAW,EAAM,CAChD,CAGY,EAA2B,CACtC,GAAI,oBACJ,UAAY,GAAS,OAAO,GAAS,UAAY,OAAO,GAAS,SACjE,cAAiB,GAClB,CAEY,EAAkB,IAA6B,CAC1D,GAAG,EACH,QAAS,EAAkB,EAAO,QAAS,CACzC,cAAe,EAAO,IACtB,QAAS,EAAE,CACX,QAAS,CAAC,EAAqB,EAAgB,CAChD,CAAC,CACH"}
@@ -1,2 +1,2 @@
1
- import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{NodeType as t}from"@intlayer/types";import n from"@intlayer/config/built";const r=(e,t=[])=>typeof e!=`object`||!e||Array.isArray(e)?[]:Object.keys(e).flatMap(n=>{let i=[...t,n],a=e[n];return a===null?[i]:[i,...r(a,i)]}),i=(e,t=[])=>typeof e!=`object`||!e||Array.isArray(e)?[]:Object.keys(e).flatMap(n=>{let r=[...t,n],a=e[n];return a===null?[]:[r,...i(a,r)]}),a=(e,t)=>{let n=e;for(let e of t){if(typeof n!=`object`||!n||!(e in n))return!1;n=n[e]}return!0},o=(e,t)=>{let n=e;for(let e of t){if(typeof n!=`object`||!n||!(e in n))return!1;n=n[e]}return n!==null},s=(e,n)=>({id:`check-missing-locales-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.Translation,transform:(s,c,l)=>{let u=s[t.Translation],d=new Set,f=new Set;for(let t of e){let e=u[t];e&&typeof e==`object`&&!Array.isArray(e)&&(r(e).forEach(e=>{d.add(JSON.stringify(e))}),i(e).forEach(e=>{f.add(JSON.stringify(e))}))}let p=e.some(e=>u[e]!==void 0&&u[e]!==null);for(let t of e){let e=u[t];if(e===null){p&&n(t);continue}if(!e){n(t);continue}let r=!1;for(let i of d)if(!a(e,JSON.parse(i))){n(t),r=!0;break}if(!r){for(let r of f)if(!o(e,JSON.parse(r))){n(t);break}}}for(let e in u){let t=u[e];l(t,{...c,children:t})}return s}}),c=(t,r=n?.internationalization?.locales,i)=>{let a=new Set,o=[s(r,e=>a.add(e)),...i.plugins??[]];return e(t,{...i,plugins:o}),Array.from(a)},l=(e,t=n?.internationalization?.locales)=>c(e.content,t,{dictionaryKey:e.key,keyPath:[]});export{s as checkMissingLocalesPlugin,c as getMissingLocalesContent,l as getMissingLocalesContentFromDictionary};
1
+ import{deepTransformNode as e}from"../interpreter/getContent/deepTransform.mjs";import{NodeType as t}from"@intlayer/types/nodeType";import n from"@intlayer/config/built";const r=(e,t=[])=>typeof e!=`object`||!e||Array.isArray(e)?[]:Object.keys(e).flatMap(n=>{let i=[...t,n],a=e[n];return a===null?[i]:[i,...r(a,i)]}),i=(e,t=[])=>typeof e!=`object`||!e||Array.isArray(e)?[]:Object.keys(e).flatMap(n=>{let r=[...t,n],a=e[n];return a===null?[]:[r,...i(a,r)]}),a=(e,t)=>{let n=e;for(let e of t){if(typeof n!=`object`||!n||!(e in n))return!1;n=n[e]}return!0},o=(e,t)=>{let n=e;for(let e of t){if(typeof n!=`object`||!n||!(e in n))return!1;n=n[e]}return n!==null},s=(e,n)=>({id:`check-missing-locales-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.Translation,transform:(s,c,l)=>{let u=s[t.Translation],d=new Set,f=new Set;for(let t of e){let e=u[t];e&&typeof e==`object`&&!Array.isArray(e)&&(r(e).forEach(e=>{d.add(JSON.stringify(e))}),i(e).forEach(e=>{f.add(JSON.stringify(e))}))}let p=e.some(e=>u[e]!==void 0&&u[e]!==null);for(let t of e){let e=u[t];if(e===null){p&&n(t);continue}if(!e){n(t);continue}let r=!1;for(let i of d)if(!a(e,JSON.parse(i))){n(t),r=!0;break}if(!r){for(let r of f)if(!o(e,JSON.parse(r))){n(t);break}}}for(let e in u){let t=u[e];l(t,{...c,children:t})}return s}}),c=(t,r=n?.internationalization?.locales,i)=>{let a=new Set,o=[s(r,e=>a.add(e)),...i.plugins??[]];return e(t,{...i,plugins:o}),Array.from(a)},l=(e,t=n?.internationalization?.locales)=>c(e.content,t,{dictionaryKey:e.key,keyPath:[]});export{s as checkMissingLocalesPlugin,c as getMissingLocalesContent,l as getMissingLocalesContentFromDictionary};
2
2
  //# sourceMappingURL=getMissingLocalesContent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getMissingLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Dictionary } from '@intlayer/types';\nimport {\n type ContentNode,\n type Locale,\n type LocalesValues,\n NodeType,\n} from '@intlayer/types';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Returns all key paths present in obj, INCLUDING those whose leaf value is null.\n * Used for structural presence checks (a locale must have every key another locale has,\n * even if the value is a null placeholder).\n */\nconst getAllKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Stop recursing into null — include the path but don't descend further\n if (value === null) {\n return [newPath];\n }\n return [newPath, ...getAllKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns key paths whose leaf value is non-null.\n * Used for translation value checks (a locale must not have null where another locale\n * already has a real translated value).\n */\nconst getNonNullKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Skip null-valued keys entirely\n if (value === null) {\n return [];\n }\n return [newPath, ...getNonNullKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns true if the key path EXISTS in obj (even if the terminal value is null).\n * Used for the structural presence check.\n */\nconst hasKey = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n return true; // key exists; value may be null\n};\n\n/**\n * Returns true if the key path exists in obj AND the terminal value is non-null.\n * Used for the translation value check.\n */\nconst hasNonNullValue = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n // null is treated as a missing translation (e.g., i18next-scanner sets null for untranslated keys)\n return current !== null;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const translations = node[NodeType.Translation] as Record<string, any>;\n\n /**\n * Two path sets built from all locales' content:\n *\n * presentPaths — every key path that exists in ANY locale, even those whose value\n * is null. A locale that is missing a path from this set is structurally incomplete\n * (the key doesn't exist at all).\n *\n * nonNullPaths — every key path that has a non-null value in at least one locale.\n * A locale that has the key but with null, when another locale already has a real\n * value, needs translation.\n */\n const presentPaths = new Set<string>();\n const nonNullPaths = new Set<string>();\n\n for (const locale of locales) {\n const value = translations[locale];\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n getAllKeyPaths(value).forEach((path) => {\n presentPaths.add(JSON.stringify(path));\n });\n\n getNonNullKeyPaths(value).forEach((path) => {\n nonNullPaths.add(JSON.stringify(path));\n });\n }\n }\n\n // If no locale has any content at all (all are null/undefined), the key is\n // universally pending — don't flag anyone.\n const hasAnyDefinedValue = locales.some(\n (locale) =>\n translations[locale] !== undefined && translations[locale] !== null\n );\n\n for (const locale of locales) {\n const value = translations[locale];\n\n if (value === null) {\n // Entire locale content is a null placeholder.\n // Flag only when some other locale already has real content.\n if (hasAnyDefinedValue) {\n onMissingLocale(locale);\n }\n continue;\n }\n\n if (!value) {\n // undefined / entirely absent\n onMissingLocale(locale);\n continue;\n }\n\n let flagged = false;\n\n // Structural check: every key that exists in any locale must also exist here\n // (even if the local value is null — at least the key must be present).\n for (const pathStr of presentPaths) {\n if (!hasKey(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n flagged = true;\n break;\n }\n }\n\n if (!flagged) {\n // Value check: every key that has a non-null value in some locale must also\n // be non-null here (null = untranslated, needs filling).\n for (const pathStr of nonNullPaths) {\n if (!hasNonNullValue(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n break;\n }\n }\n }\n }\n\n // Continue traversal inside the translation values\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"iKAiBA,MAAM,GAAkB,EAAU,EAAmB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AS,CACtC,EAAa,IAAI,KAAK,UAAU,EAAK,CAAC,EACtC,CAEF,EAAmB,EAAM,CAAC,QAAS,GAAS,CAC1C,EAAa,IAAI,KAAK,UAAU,EAAK,CAAC,EACtC,EAMN,IAAM,EAAqB,EAAQ,KAChC,GACC,EAAa,KAAY,IAAA,IAAa,EAAa,KAAY,KAClE,CAED,IAAK,IAAM,KAAU,EAAS,CAC5B,IAAM,EAAQ,EAAa,GAE3B,GAAI,IAAU,KAAM,CAGd,GACF,EAAgB,EAAO,CAEzB,SAGF,GAAI,CAAC,EAAO,CAEV,EAAgB,EAAO,CACvB,SAGF,IAAI,EAAU,GAId,IAAK,IAAM,KAAW,EACpB,GAAI,CAAC,EAAO,EAAO,KAAK,MAAM,EAAQ,CAAC,CAAE,CACvC,EAAgB,EAAO,CACvB,EAAU,GACV,MAIJ,GAAI,CAAC,OAGE,IAAM,KAAW,EACpB,GAAI,CAAC,EAAgB,EAAO,KAAK,MAAM,EAAQ,CAAC,CAAE,CAChD,EAAgB,EAAO,CACvB,QAOR,IAAK,IAAM,KAAO,EAAc,CAC9B,IAAM,EAAQ,EAAa,GAC3B,EAAkB,EAAO,CACvB,GAAG,EACH,SAAU,EACX,CAAC,CAIJ,OAAO,GAEV,EAQY,GACX,EACA,EAA2B,GAAe,sBAAsB,QAChE,IACa,CACb,IAAM,EAAiB,IAAI,IAErB,EAAqB,CACzB,EAA0B,EAAsB,GAC9C,EAAe,IAAI,EAAO,CAC3B,CACD,GAAI,EAAU,SAAW,EAAE,CAC5B,CAOD,OALA,EAAkB,EAAM,CACtB,GAAG,EACH,UACD,CAAC,CAEK,MAAM,KAAK,EAAe,EAGtB,GACX,EACA,EAA2B,GAAe,sBAAsB,UAEhE,EAAyB,EAAW,QAAS,EAAS,CACpD,cAAe,EAAW,IAC1B,QAAS,EAAE,CACZ,CAAC"}
1
+ {"version":3,"file":"getMissingLocalesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getMissingLocalesContent.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { Locale } from '@intlayer/types/allLocales';\nimport type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { LocalesValues } from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\nimport type { DeepTransformContent, NodeProps, Plugins } from '../interpreter';\nimport { deepTransformNode } from '../interpreter/getContent/deepTransform';\nimport type { TranslationContent } from '../transpiler';\n\n/**\n * Returns all key paths present in obj, INCLUDING those whose leaf value is null.\n * Used for structural presence checks (a locale must have every key another locale has,\n * even if the value is a null placeholder).\n */\nconst getAllKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Stop recursing into null — include the path but don't descend further\n if (value === null) {\n return [newPath];\n }\n return [newPath, ...getAllKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns key paths whose leaf value is non-null.\n * Used for translation value checks (a locale must not have null where another locale\n * already has a real translated value).\n */\nconst getNonNullKeyPaths = (obj: any, prefix: string[] = []): string[][] => {\n if (typeof obj !== 'object' || obj === null || Array.isArray(obj)) {\n return [];\n }\n\n return Object.keys(obj).flatMap((key) => {\n const newPath = [...prefix, key];\n const value = obj[key];\n // Skip null-valued keys entirely\n if (value === null) {\n return [];\n }\n return [newPath, ...getNonNullKeyPaths(value, newPath)];\n });\n};\n\n/**\n * Returns true if the key path EXISTS in obj (even if the terminal value is null).\n * Used for the structural presence check.\n */\nconst hasKey = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n return true; // key exists; value may be null\n};\n\n/**\n * Returns true if the key path exists in obj AND the terminal value is non-null.\n * Used for the translation value check.\n */\nconst hasNonNullValue = (obj: any, keyPath: string[]): boolean => {\n let current = obj;\n for (const key of keyPath) {\n if (\n current === undefined ||\n current === null ||\n typeof current !== 'object'\n ) {\n return false;\n }\n if (!(key in current)) {\n return false;\n }\n current = current[key];\n }\n // null is treated as a missing translation (e.g., i18next-scanner sets null for untranslated keys)\n return current !== null;\n};\n\n/** Translation plugin. Replaces node with a locale string if nodeType = Translation. */\nexport const checkMissingLocalesPlugin = (\n locales: Locale[],\n onMissingLocale: (locale: Locale) => void\n): Plugins => ({\n id: 'check-missing-locales-plugin',\n canHandle: (node) =>\n typeof node === 'object' && node?.nodeType === NodeType.Translation,\n transform: (node: TranslationContent, props, deepTransformNode) => {\n const translations = node[NodeType.Translation] as Record<string, any>;\n\n /**\n * Two path sets built from all locales' content:\n *\n * presentPaths — every key path that exists in ANY locale, even those whose value\n * is null. A locale that is missing a path from this set is structurally incomplete\n * (the key doesn't exist at all).\n *\n * nonNullPaths — every key path that has a non-null value in at least one locale.\n * A locale that has the key but with null, when another locale already has a real\n * value, needs translation.\n */\n const presentPaths = new Set<string>();\n const nonNullPaths = new Set<string>();\n\n for (const locale of locales) {\n const value = translations[locale];\n if (value && typeof value === 'object' && !Array.isArray(value)) {\n getAllKeyPaths(value).forEach((path) => {\n presentPaths.add(JSON.stringify(path));\n });\n\n getNonNullKeyPaths(value).forEach((path) => {\n nonNullPaths.add(JSON.stringify(path));\n });\n }\n }\n\n // If no locale has any content at all (all are null/undefined), the key is\n // universally pending — don't flag anyone.\n const hasAnyDefinedValue = locales.some(\n (locale) =>\n translations[locale] !== undefined && translations[locale] !== null\n );\n\n for (const locale of locales) {\n const value = translations[locale];\n\n if (value === null) {\n // Entire locale content is a null placeholder.\n // Flag only when some other locale already has real content.\n if (hasAnyDefinedValue) {\n onMissingLocale(locale);\n }\n continue;\n }\n\n if (!value) {\n // undefined / entirely absent\n onMissingLocale(locale);\n continue;\n }\n\n let flagged = false;\n\n // Structural check: every key that exists in any locale must also exist here\n // (even if the local value is null — at least the key must be present).\n for (const pathStr of presentPaths) {\n if (!hasKey(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n flagged = true;\n break;\n }\n }\n\n if (!flagged) {\n // Value check: every key that has a non-null value in some locale must also\n // be non-null here (null = untranslated, needs filling).\n for (const pathStr of nonNullPaths) {\n if (!hasNonNullValue(value, JSON.parse(pathStr))) {\n onMissingLocale(locale);\n break;\n }\n }\n }\n }\n\n // Continue traversal inside the translation values\n for (const key in translations) {\n const child = translations[key];\n deepTransformNode(child, {\n ...props,\n children: child,\n });\n }\n\n // Return the original node; the return value is ignored by the caller\n return node;\n },\n});\n\n/**\n * Return the content of a node with only the translation plugin.\n *\n * @param node The node to transform.\n * @param locales The locales to check for missing translations.\n */\nexport const getMissingLocalesContent = <T extends ContentNode>(\n node: T,\n locales: LocalesValues[] = configuration?.internationalization?.locales,\n nodeProps: NodeProps\n): Locale[] => {\n const missingLocales = new Set<Locale>();\n\n const plugins: Plugins[] = [\n checkMissingLocalesPlugin(locales as Locale[], (locale) =>\n missingLocales.add(locale)\n ),\n ...(nodeProps.plugins ?? []),\n ];\n\n deepTransformNode(node, {\n ...nodeProps,\n plugins,\n }) as DeepTransformContent<T>;\n\n return Array.from(missingLocales);\n};\n\nexport const getMissingLocalesContentFromDictionary = (\n dictionary: Dictionary,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n) =>\n getMissingLocalesContent(dictionary.content, locales, {\n dictionaryKey: dictionary.key,\n keyPath: [],\n });\n"],"mappings":"0KAcA,MAAM,GAAkB,EAAU,EAAmB,EAAE,GACjD,OAAO,GAAQ,WAAY,GAAgB,MAAM,QAAQ,EAAI,CACxD,EAAE,CAGJ,OAAO,KAAK,EAAI,CAAC,QAAS,GAAQ,CACvC,IAAM,EAAU,CAAC,GAAG,EAAQ,EAAI,CAC1B,EAAQ,EAAI,GAKlB,OAHI,IAAU,KACL,CAAC,EAAQ,CAEX,CAAC,EAAS,GAAG,EAAe,EAAO,EAAQ,CAAC,EACnD,CAQE,GAAsB,EAAU,EAAmB,EA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Gd,GACF,EAAgB,EAAO,CAEzB,SAGF,GAAI,CAAC,EAAO,CAEV,EAAgB,EAAO,CACvB,SAGF,IAAI,EAAU,GAId,IAAK,IAAM,KAAW,EACpB,GAAI,CAAC,EAAO,EAAO,KAAK,MAAM,EAAQ,CAAC,CAAE,CACvC,EAAgB,EAAO,CACvB,EAAU,GACV,MAIJ,GAAI,CAAC,OAGE,IAAM,KAAW,EACpB,GAAI,CAAC,EAAgB,EAAO,KAAK,MAAM,EAAQ,CAAC,CAAE,CAChD,EAAgB,EAAO,CACvB,QAOR,IAAK,IAAM,KAAO,EAAc,CAC9B,IAAM,EAAQ,EAAa,GAC3B,EAAkB,EAAO,CACvB,GAAG,EACH,SAAU,EACX,CAAC,CAIJ,OAAO,GAEV,EAQY,GACX,EACA,EAA2B,GAAe,sBAAsB,QAChE,IACa,CACb,IAAM,EAAiB,IAAI,IAErB,EAAqB,CACzB,EAA0B,EAAsB,GAC9C,EAAe,IAAI,EAAO,CAC3B,CACD,GAAI,EAAU,SAAW,EAAE,CAC5B,CAOD,OALA,EAAkB,EAAM,CACtB,GAAG,EACH,UACD,CAAC,CAEK,MAAM,KAAK,EAAe,EAGtB,GACX,EACA,EAA2B,GAAe,sBAAsB,UAEhE,EAAyB,EAAW,QAAS,EAAS,CACpD,cAAe,EAAW,IAC1B,QAAS,EAAE,CACZ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"getMultilingualDictionary.mjs","names":["t"],"sources":["../../../src/deepTransformPlugins/getMultilingualDictionary.ts"],"sourcesContent":["import type { Dictionary, KeyPath, NodeType, TypedNode } from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { t } from '../transpiler';\n\n/**\n * Transform a per-locale dictionary into a multilingual dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"myContent\": \"English content\"\n * }\n * }\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"content\": {\n * \"myContent\": t({\n * \"en\": \"English content\",\n * })\n * }\n * }\n * ```\n */\nexport const getMultilingualDictionary = (\n dictionary: Dictionary\n): Dictionary => {\n if (!dictionary.locale) {\n return dictionary;\n }\n\n const locale = dictionary.locale;\n\n const wrapPrimitiveInTranslationPlugin: Plugins = {\n id: 'wrap-primitive-in-translation',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: (node) => t({ [locale]: node } as Record<string, unknown>),\n };\n\n const traverseTypedNodePlugin: Plugins = {\n id: 'traverse-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof (node as any)?.nodeType === 'string',\n transform: (node: TypedNode, props, transformFn) => {\n const nodeType = (node as any).nodeType as NodeType;\n const inner = structuredClone(\n (node as any)[nodeType as unknown as keyof TypedNode] as any\n );\n\n if (typeof inner !== 'object' || inner === null) {\n const transformed = transformFn(inner, {\n ...props,\n children: inner,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformed,\n };\n }\n\n for (const key in inner) {\n const childProps: NodeProps = {\n ...props,\n children: inner[key as unknown as keyof typeof inner],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n inner[key as unknown as keyof typeof inner] = transformFn(\n inner[key as unknown as keyof typeof inner],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: inner };\n },\n };\n\n const transformedContent = deepTransformNode(\n JSON.parse(JSON.stringify(dictionary.content)),\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [traverseTypedNodePlugin, wrapPrimitiveInTranslationPlugin],\n }\n );\n\n const { locale: _omitLocale, ...rest } = dictionary as any;\n return {\n ...rest,\n content: transformedContent,\n } as Dictionary;\n};\n"],"mappings":"yIAiCA,MAAa,EACX,GACe,CACf,GAAI,CAAC,EAAW,OACd,OAAO,EAGT,IAAM,EAAS,EAAW,OAoDpB,EAAqB,EACzB,KAAK,MAAM,KAAK,UAAU,EAAW,QAAQ,CAAC,CAC9C,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,CA9C4B,CACvC,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAQ,GAAc,UAAa,SACjE,WAAY,EAAiB,EAAO,IAAgB,CAClD,IAAM,EAAY,EAAa,SACzB,EAAQ,gBACX,EAAa,GACf,CAED,GAAI,OAAO,GAAU,WAAY,EAAgB,CAC/C,IAAM,EAAc,EAAY,EAAO,CACrC,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAU,IAAK,EAAU,CAClC,CACF,CAAC,CACF,MAAO,CACL,GAAG,GACF,GAAyC,EAC3C,CAGH,IAAK,IAAM,KAAO,EAAO,CACvB,IAAM,EAAwB,CAC5B,GAAG,EACH,SAAU,EAAM,GAChB,QAAS,CAAC,GAAG,EAAM,QAAS,CAAE,KAAM,EAAU,MAAK,CAAY,CAChE,CACD,EAAM,GAAwC,EAC5C,EAAM,GACN,EACD,CAGH,MAAO,CAAE,GAAG,GAAO,GAAyC,EAAO,EAEtE,CAhDiD,CAChD,GAAI,gCACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,UAClB,UAAY,GAASA,EAAE,EAAG,GAAS,EAAM,CAA4B,CACtE,CAgDuE,CACrE,CACF,CAEK,CAAE,OAAQ,EAAa,GAAG,GAAS,EACzC,MAAO,CACL,GAAG,EACH,QAAS,EACV"}
1
+ {"version":3,"file":"getMultilingualDictionary.mjs","names":["t"],"sources":["../../../src/deepTransformPlugins/getMultilingualDictionary.ts"],"sourcesContent":["import type { Dictionary, TypedNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\nimport { t } from '../transpiler';\n\n/**\n * Transform a per-locale dictionary into a multilingual dictionary.\n *\n * Example:\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"locale\": \"en\",\n * \"content\": {\n * \"myContent\": \"English content\"\n * }\n * }\n * ```\n *\n * ```json\n * {\n * \"key\": \"about-page\",\n * \"content\": {\n * \"myContent\": t({\n * \"en\": \"English content\",\n * })\n * }\n * }\n * ```\n */\nexport const getMultilingualDictionary = (\n dictionary: Dictionary\n): Dictionary => {\n if (!dictionary.locale) {\n return dictionary;\n }\n\n const locale = dictionary.locale;\n\n const wrapPrimitiveInTranslationPlugin: Plugins = {\n id: 'wrap-primitive-in-translation',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: (node) => t({ [locale]: node } as Record<string, unknown>),\n };\n\n const traverseTypedNodePlugin: Plugins = {\n id: 'traverse-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof (node as any)?.nodeType === 'string',\n transform: (node: TypedNode, props, transformFn) => {\n const nodeType = (node as any).nodeType as NodeType;\n const inner = structuredClone(\n (node as any)[nodeType as unknown as keyof TypedNode] as any\n );\n\n if (typeof inner !== 'object' || inner === null) {\n const transformed = transformFn(inner, {\n ...props,\n children: inner,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformed,\n };\n }\n\n for (const key in inner) {\n const childProps: NodeProps = {\n ...props,\n children: inner[key as unknown as keyof typeof inner],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n inner[key as unknown as keyof typeof inner] = transformFn(\n inner[key as unknown as keyof typeof inner],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: inner };\n },\n };\n\n const transformedContent = deepTransformNode(\n JSON.parse(JSON.stringify(dictionary.content)),\n {\n dictionaryKey: dictionary.key,\n keyPath: [],\n plugins: [traverseTypedNodePlugin, wrapPrimitiveInTranslationPlugin],\n }\n );\n\n const { locale: _omitLocale, ...rest } = dictionary as any;\n return {\n ...rest,\n content: transformedContent,\n } as Dictionary;\n};\n"],"mappings":"yIAmCA,MAAa,EACX,GACe,CACf,GAAI,CAAC,EAAW,OACd,OAAO,EAGT,IAAM,EAAS,EAAW,OAoDpB,EAAqB,EACzB,KAAK,MAAM,KAAK,UAAU,EAAW,QAAQ,CAAC,CAC9C,CACE,cAAe,EAAW,IAC1B,QAAS,EAAE,CACX,QAAS,CA9C4B,CACvC,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAQ,GAAc,UAAa,SACjE,WAAY,EAAiB,EAAO,IAAgB,CAClD,IAAM,EAAY,EAAa,SACzB,EAAQ,gBACX,EAAa,GACf,CAED,GAAI,OAAO,GAAU,WAAY,EAAgB,CAC/C,IAAM,EAAc,EAAY,EAAO,CACrC,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAU,IAAK,EAAU,CAClC,CACF,CAAC,CACF,MAAO,CACL,GAAG,GACF,GAAyC,EAC3C,CAGH,IAAK,IAAM,KAAO,EAAO,CACvB,IAAM,EAAwB,CAC5B,GAAG,EACH,SAAU,EAAM,GAChB,QAAS,CAAC,GAAG,EAAM,QAAS,CAAE,KAAM,EAAU,MAAK,CAAY,CAChE,CACD,EAAM,GAAwC,EAC5C,EAAM,GACN,EACD,CAGH,MAAO,CAAE,GAAG,GAAO,GAAyC,EAAO,EAEtE,CAhDiD,CAChD,GAAI,gCACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,UAClB,UAAY,GAASA,EAAE,EAAG,GAAS,EAAM,CAA4B,CACtE,CAgDuE,CACrE,CACF,CAEK,CAAE,OAAQ,EAAa,GAAG,GAAS,EACzC,MAAO,CACL,GAAG,EACH,QAAS,EACV"}
@@ -1 +1 @@
1
- {"version":3,"file":"getReplacedValuesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import type {\n ContentNode,\n KeyPath,\n NodeType,\n TypedNode,\n} from '@intlayer/types';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"gFAYA,MAAM,EAAuB,IAA+C,CAC1E,GAAI,wBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,UAClB,cAAiB,EAClB,EAEK,EAA+B,CACnC,GAAI,yBACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAO,GAAM,UAAa,SACxD,WAAY,EAAiB,EAAO,IAAsB,CACxD,IAAM,EAAW,EAAK,SAChB,EAAS,gBACb,EAAK,GACN,CAID,GAAI,OAAO,GAAW,WAAY,EAAiB,CACjD,IAAM,EAAoB,EAAkB,EAAQ,CAClD,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAU,IAAK,EAAU,CAClC,CACF,CAAC,CACF,MAAO,CACL,GAAG,GACF,GAAyC,EAC3C,CAIH,IAAK,IAAM,KAAO,EAAQ,CACxB,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAO,GACjB,QAAS,CAAC,GAAG,EAAM,QAAS,CAAE,KAAM,EAAU,MAAK,CAAY,CAChE,CACD,EAAO,GAAyC,EAC9C,EAAO,GACP,EACD,CAGH,MAAO,CAAE,GAAG,GAAO,GAAyC,EAAQ,EAEvE,CAEY,GACX,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EACA,EAAoB,EAAM,CAC1B,GAAI,EAAU,SAAW,EAAE,CAC5B,CAID,OAAO,EAFU,KAAK,MAAM,KAAK,UAAU,EAAK,CAAC,CAEd,CACjC,GAAG,EACH,UACD,CAAC"}
1
+ {"version":3,"file":"getReplacedValuesContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getReplacedValuesContent.ts"],"sourcesContent":["import type { ContentNode, TypedNode } from '@intlayer/types/dictionary';\nimport type { KeyPath } from '@intlayer/types/keyPath';\nimport type { NodeType } from '@intlayer/types/nodeType';\nimport {\n deepTransformNode,\n type NodeProps,\n type Plugins,\n} from '../interpreter';\n\nconst replaceValuesPlugin = (value: string | number | boolean): Plugins => ({\n id: 'replace-values-plugin',\n canHandle: (node) =>\n typeof node === 'string' ||\n typeof node === 'number' ||\n typeof node === 'boolean',\n transform: () => value,\n});\n\nconst skipTypedNodePlugin: Plugins = {\n id: 'skip-typed-node-plugin',\n canHandle: (node) =>\n typeof node === 'object' && typeof node?.nodeType === 'string',\n transform: (node: TypedNode, props, deepTransformNode) => {\n const nodeType = node.nodeType as NodeType;\n const result = structuredClone(\n node[nodeType as unknown as keyof TypedNode] as any\n );\n\n // If the result is a primitive value (string, number, boolean),\n // we need to transform it directly instead of iterating over its properties\n if (typeof result !== 'object' || result === null) {\n const transformedResult = deepTransformNode(result, {\n ...props,\n children: result,\n keyPath: [\n ...props.keyPath,\n { type: nodeType, key: nodeType } as KeyPath,\n ],\n });\n return {\n ...node,\n [nodeType as unknown as keyof TypedNode]: transformedResult,\n };\n }\n\n // For objects and arrays, iterate over their properties\n for (const key in result) {\n const childProps = {\n ...props,\n children: result[key as unknown as keyof typeof result],\n keyPath: [...props.keyPath, { type: nodeType, key } as KeyPath],\n };\n result[key as unknown as keyof typeof result] = deepTransformNode(\n result[key as unknown as keyof typeof result],\n childProps\n );\n }\n\n return { ...node, [nodeType as unknown as keyof TypedNode]: result };\n },\n};\n\nexport const getReplacedValuesContent = (\n node: ContentNode,\n value: string | number | boolean,\n nodeProps: NodeProps\n) => {\n const plugins: Plugins[] = [\n skipTypedNodePlugin,\n replaceValuesPlugin(value),\n ...(nodeProps.plugins ?? []),\n ];\n\n const JSONNode = JSON.parse(JSON.stringify(node));\n\n return deepTransformNode(JSONNode, {\n ...nodeProps,\n plugins,\n });\n};\n"],"mappings":"gFASA,MAAM,EAAuB,IAA+C,CAC1E,GAAI,wBACJ,UAAY,GACV,OAAO,GAAS,UAChB,OAAO,GAAS,UAChB,OAAO,GAAS,UAClB,cAAiB,EAClB,EAEK,EAA+B,CACnC,GAAI,yBACJ,UAAY,GACV,OAAO,GAAS,UAAY,OAAO,GAAM,UAAa,SACxD,WAAY,EAAiB,EAAO,IAAsB,CACxD,IAAM,EAAW,EAAK,SAChB,EAAS,gBACb,EAAK,GACN,CAID,GAAI,OAAO,GAAW,WAAY,EAAiB,CACjD,IAAM,EAAoB,EAAkB,EAAQ,CAClD,GAAG,EACH,SAAU,EACV,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAM,EAAU,IAAK,EAAU,CAClC,CACF,CAAC,CACF,MAAO,CACL,GAAG,GACF,GAAyC,EAC3C,CAIH,IAAK,IAAM,KAAO,EAAQ,CACxB,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAO,GACjB,QAAS,CAAC,GAAG,EAAM,QAAS,CAAE,KAAM,EAAU,MAAK,CAAY,CAChE,CACD,EAAO,GAAyC,EAC9C,EAAO,GACP,EACD,CAGH,MAAO,CAAE,GAAG,GAAO,GAAyC,EAAQ,EAEvE,CAEY,GACX,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EACA,EAAoB,EAAM,CAC1B,GAAI,EAAU,SAAW,EAAE,CAC5B,CAID,OAAO,EAFU,KAAK,MAAM,KAAK,UAAU,EAAK,CAAC,CAEd,CACjC,GAAG,EACH,UACD,CAAC"}
@@ -1,2 +1,2 @@
1
- import{NodeType as e}from"@intlayer/types";const t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=e=>t(e)&&typeof e.nodeType==`string`,r=(e,i)=>{if(e===void 0)return i;if(i===void 0)return e;if(Array.isArray(e)&&Array.isArray(i))return[...e,...i];if(t(e)&&t(i)&&!n(e)&&!n(i)){let t={...e};for(let e of Object.keys(i))t[e]=r(t[e],i[e]);return t}return i},i=(e,t)=>{let n={...e};n.common=r(e.common,t.common);let i=new Set([...Object.keys(e).filter(e=>e!==`common`),...Object.keys(t).filter(e=>e!==`common`)]);for(let a of i)n[a]=r(e[a],t[a]);return n},a=o=>{if(t(o)&&o?.nodeType===e.Translation){let t=o[e.Translation],n={};for(let e of Object.keys(t)){let i=t[e],o=a(i),s=r(o.common,void 0),c;for(let e of Object.keys(o))e!==`common`&&(c=r(c,o[e]));let l=r(s,c);l!==void 0&&(n[e]=l)}return n}if(Array.isArray(o)){let e=[],t={};o.forEach(n=>{let r=a(n);r.common!==void 0&&e.push(r.common);for(let e of Object.keys(r)){if(e===`common`)continue;t[e]||(t[e]=[]);let n=r[e];n!==void 0&&t[e].push(n)}});let n={};e.length>0&&(n.common=e);for(let e of Object.keys(t))n[e]=t[e];return n}if(t(o)&&!n(o)){let e={};for(let t of Object.keys(o)){let n=a(o[t]);n.common!==void 0&&(e=i(e,{common:{[t]:n.common}}));for(let r of Object.keys(n))r!==`common`&&(e=i(e,{[r]:{[t]:n[r]}}))}return e}return{common:o}},o=e=>{let t=a(e),n={};t.common!==void 0&&(n.common=t.common);for(let e of Object.keys(t)){if(e===`common`)continue;let r=t[e];r!==void 0&&(n[e]=r)}return n},s=e=>o(e.content);export{o as getSplittedContent,s as getSplittedDictionaryContent};
1
+ import{NodeType as e}from"@intlayer/types/nodeType";const t=e=>typeof e==`object`&&!!e&&!Array.isArray(e),n=e=>t(e)&&typeof e.nodeType==`string`,r=(e,i)=>{if(e===void 0)return i;if(i===void 0)return e;if(Array.isArray(e)&&Array.isArray(i))return[...e,...i];if(t(e)&&t(i)&&!n(e)&&!n(i)){let t={...e};for(let e of Object.keys(i))t[e]=r(t[e],i[e]);return t}return i},i=(e,t)=>{let n={...e};n.common=r(e.common,t.common);let i=new Set([...Object.keys(e).filter(e=>e!==`common`),...Object.keys(t).filter(e=>e!==`common`)]);for(let a of i)n[a]=r(e[a],t[a]);return n},a=o=>{if(t(o)&&o?.nodeType===e.Translation){let t=o[e.Translation],n={};for(let e of Object.keys(t)){let i=t[e],o=a(i),s=r(o.common,void 0),c;for(let e of Object.keys(o))e!==`common`&&(c=r(c,o[e]));let l=r(s,c);l!==void 0&&(n[e]=l)}return n}if(Array.isArray(o)){let e=[],t={};o.forEach(n=>{let r=a(n);r.common!==void 0&&e.push(r.common);for(let e of Object.keys(r)){if(e===`common`)continue;t[e]||(t[e]=[]);let n=r[e];n!==void 0&&t[e].push(n)}});let n={};e.length>0&&(n.common=e);for(let e of Object.keys(t))n[e]=t[e];return n}if(t(o)&&!n(o)){let e={};for(let t of Object.keys(o)){let n=a(o[t]);n.common!==void 0&&(e=i(e,{common:{[t]:n.common}}));for(let r of Object.keys(n))r!==`common`&&(e=i(e,{[r]:{[t]:n[r]}}))}return e}return{common:o}},o=e=>{let t=a(e),n={};t.common!==void 0&&(n.common=t.common);for(let e of Object.keys(t)){if(e===`common`)continue;let r=t[e];r!==void 0&&(n[e]=r)}return n},s=e=>o(e.content);export{o as getSplittedContent,s as getSplittedDictionaryContent};
2
2
  //# sourceMappingURL=getSplittedContent.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getSplittedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import {\n type ContentNode,\n type DeclaredLocales,\n type Dictionary,\n NodeType,\n} from '@intlayer/types';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeType.Translation) {\n const translations = (node as any)[NodeType.Translation] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":"2CAeA,MAAM,EAAY,GAChB,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,EAAM,CAEhE,EAAe,GACnB,EAAS,EAAM,EAAI,OAAQ,EAAc,UAAa,SAElD,GACJ,EACA,IAC4B,CAC5B,GAAI,IAAM,IAAA,GAAW,OAAO,EAC5B,GAAI,IAAM,IAAA,GAAW,OAAO,EAE5B,GAAI,MAAM,QAAQ,EAAE,EAAI,MAAM,QAAQ,EAAE,CAEtC,MAAO,CAAC,GAAG,EAAG,GAAG,EAAE,CAGrB,GAAI,EAAS,EAAE,EAAI,EAAS,EAAE,EAAI,CAAC,EAAY,EAAE,EAAI,CAAC,EAAY,EAAE,CAAE,CACpE,IAAM,EAA8B,CAAE,GAAG,EAAG,CAC5C,IAAK,IAAM,KAAO,OAAO,KAAK,EAAE,CAC9B,EAAO,GAAO,EACZ,EAAO,GACN,EAA0B,GAC5B,CAEH,OAAO,EAIT,OAAO,GAGH,GACJ,EACA,IACgB,CAChB,IAAM,EAAsB,CAAE,GAAG,EAAM,CAGvC,EAAO,OAAS,EAAY,EAAK,OAAQ,EAAS,OAAO,CAGzD,IAAM,EAAa,IAAI,IAAY,CACjC,GAAG,OAAO,KAAK,EAAK,CAAC,OAAQ,GAAM,IAAM,SAAS,CAClD,GAAG,OAAO,KAAK,EAAS,CAAC,OAAQ,GAAM,IAAM,SAAS,CACvD,CAAC,CAEF,IAAK,IAAM,KAAO,EAEhB,EAAO,GAAO,EACZ,EAAK,GACL,EAAS,GACV,CAGH,OAAO,GAGH,EAAa,GAAmC,CAEpD,GAAI,EAAS,EAAK,EAAK,GAAc,WAAa,EAAS,YAAa,CACtE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IAAW,WACf,EAAc,EAAkB,EAAa,EAE1C,GAAS,EAAG,GAAM,EAAW,GAAS,CACxC,CAAC,EAIN,OAAO,EAIT,MAAO,CAAE,OAAQ,EAAM,EAGZ,EACX,GAC0B,CAC1B,IAAM,EAAQ,EAAU,EAAQ,CAG1B,EAAsC,EAAE,CAC1C,EAAM,SAAW,IAAA,KACnB,EAAO,OAAS,EAAM,QAExB,IAAK,IAAM,KAAO,OAAO,KAAK,EAAM,CAAE,CACpC,GAAI,IAAQ,SAAU,SACtB,IAAM,EAAQ,EAAM,GAChB,IAAU,IAAA,KACZ,EAAO,GAAO,GAIlB,OAAO,GAkCI,EACX,GAEA,EAAmB,EAAW,QAAQ"}
1
+ {"version":3,"file":"getSplittedContent.mjs","names":[],"sources":["../../../src/deepTransformPlugins/getSplittedContent.ts"],"sourcesContent":["import type { ContentNode, Dictionary } from '@intlayer/types/dictionary';\nimport type { DeclaredLocales } from '@intlayer/types/module_augmentation';\nimport { NodeType } from '@intlayer/types/nodeType';\n\ntype SplittedContentOutput<T = ContentNode> = Record<DeclaredLocales, T> & {\n common: T;\n};\n\ntype SplitResult = Record<string, ContentNode | undefined> & {\n common?: ContentNode;\n};\n\nconst isObject = (value: unknown): value is Record<string, any> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\nconst hasNodeType = (value: unknown): value is { nodeType: string } =>\n isObject(value) && typeof (value as any).nodeType === 'string';\n\nconst mergeValues = (\n a: ContentNode | undefined,\n b: ContentNode | undefined\n): ContentNode | undefined => {\n if (a === undefined) return b;\n if (b === undefined) return a;\n\n if (Array.isArray(a) && Array.isArray(b)) {\n // Concatenate arrays when merging sibling results\n return [...a, ...b] as unknown as ContentNode;\n }\n\n if (isObject(a) && isObject(b) && !hasNodeType(a) && !hasNodeType(b)) {\n const result: Record<string, any> = { ...a };\n for (const key of Object.keys(b)) {\n result[key] = mergeValues(\n result[key] as unknown as ContentNode | undefined,\n (b as Record<string, any>)[key] as unknown as ContentNode | undefined\n );\n }\n return result as ContentNode;\n }\n\n // For primitives or differing structures, prefer b (more recent)\n return b;\n};\n\nconst mergeSplitResults = (\n base: SplitResult,\n addition: SplitResult\n): SplitResult => {\n const result: SplitResult = { ...base };\n\n // Merge common\n result.common = mergeValues(base.common, addition.common);\n\n // Merge each locale key present in either side\n const localeKeys = new Set<string>([\n ...Object.keys(base).filter((k) => k !== 'common'),\n ...Object.keys(addition).filter((k) => k !== 'common'),\n ]);\n\n for (const key of localeKeys) {\n // @ts-ignore: dynamic keys for locales\n result[key] = mergeValues(\n base[key] as ContentNode | undefined,\n addition[key] as ContentNode | undefined\n );\n }\n\n return result;\n};\n\nconst splitNode = (node: ContentNode): SplitResult => {\n // Translation node: allocate entirely to per-locale buckets\n if (isObject(node) && (node as any)?.nodeType === NodeType.Translation) {\n const translations = (node as any)[NodeType.Translation] as Record<\n string,\n ContentNode\n >;\n\n const result: SplitResult = {};\n for (const locale of Object.keys(translations)) {\n const child = translations[locale];\n const childSplit = splitNode(child);\n\n // The content under a translation belongs to the locale, not common\n // Merge common portion of the child (if any) into the locale as well\n const mergedForLocale = mergeValues(childSplit.common, undefined);\n\n // Compose locale content: prefer the fully rebuilt child by resolving deeper translations recursively\n // which are already split inside childSplit. We need to recompose a single node for this locale.\n // Recompose by merging all keys in childSplit except 'common' into a single node, then merge child's common.\n let recomposed: ContentNode | undefined;\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n recomposed = mergeValues(\n recomposed,\n childSplit[key] as ContentNode | undefined\n );\n }\n const finalLocaleNode = mergeValues(mergedForLocale, recomposed);\n\n if (finalLocaleNode !== undefined) {\n // @ts-ignore dynamic locale key\n result[locale] = finalLocaleNode;\n }\n }\n\n return result;\n }\n\n // Arrays: split each element and merge results index-wise\n if (Array.isArray(node)) {\n const commonArray: any[] = [];\n const perLocaleArrays: Record<string, any[]> = {};\n\n node.forEach((child) => {\n const childSplit = splitNode(child as ContentNode);\n\n if (childSplit.common !== undefined) {\n commonArray.push(childSplit.common);\n }\n\n for (const key of Object.keys(childSplit)) {\n if (key === 'common') continue;\n if (!perLocaleArrays[key]) perLocaleArrays[key] = [];\n const value = childSplit[key];\n if (value !== undefined) perLocaleArrays[key].push(value);\n }\n });\n\n const result: SplitResult = {};\n if (commonArray.length > 0)\n result.common = commonArray as unknown as ContentNode;\n for (const key of Object.keys(perLocaleArrays)) {\n // @ts-ignore dynamic locale key\n result[key] = perLocaleArrays[key] as unknown as ContentNode;\n }\n return result;\n }\n\n // Objects (non-typed): recursively split properties\n if (isObject(node) && !hasNodeType(node)) {\n let accumulated: SplitResult = {};\n\n for (const key of Object.keys(node)) {\n const childSplit = splitNode((node as any)[key] as ContentNode);\n\n // Assign property into common\n if (childSplit.common !== undefined) {\n accumulated = mergeSplitResults(accumulated, {\n common: { [key]: childSplit.common } as unknown as ContentNode,\n });\n }\n\n // Assign property into each locale bucket\n for (const locale of Object.keys(childSplit)) {\n if (locale === 'common') continue;\n accumulated = mergeSplitResults(accumulated, {\n // @ts-ignore dynamic locale key\n [locale]: { [key]: childSplit[locale] } as unknown as ContentNode,\n });\n }\n }\n\n return accumulated;\n }\n\n // Primitives or typed nodes (non-translation): entirely common\n return { common: node } as SplitResult;\n};\n\nexport const getSplittedContent = (\n content: ContentNode\n): SplittedContentOutput => {\n const split = splitNode(content);\n\n // Build final output with only defined sections\n const output: Record<string, ContentNode> = {};\n if (split.common !== undefined) {\n output.common = split.common;\n }\n for (const key of Object.keys(split)) {\n if (key === 'common') continue;\n const value = split[key] as ContentNode | undefined;\n if (value !== undefined) {\n output[key] = value;\n }\n }\n\n return output as unknown as SplittedContentOutput;\n};\n\n/**\n * Splits the `content` field of a Dictionary into \"common\" and per-locale buckets.\n *\n * Given a dictionary like:\n * ```js\n * {\n * key: \"my-key\",\n * content: {\n * commonContent: \"common content\",\n * multilingualContent: t({\n * en: \"english content\",\n * fr: \"french content\",\n * de: \"german content\",\n * }),\n * },\n * }\n * ```\n *\n * It produces:\n * ```js\n * {\n * common: { commonContent: \"common content\" },\n * en: { multilingualContent: \"english content\" },\n * fr: { multilingualContent: \"french content\" },\n * de: { multilingualContent: \"german content\" },\n * }\n * ```\n *\n * @param dictionary - The input dictionary object with possible multilingual or common content.\n * @returns An object mapping \"common\" and each locale to their corresponding content subtrees.\n */\nexport const getSplittedDictionaryContent = (\n dictionary: Dictionary\n): SplittedContentOutput<Dictionary['content']> =>\n getSplittedContent(dictionary.content);\n"],"mappings":"oDAYA,MAAM,EAAY,GAChB,OAAO,GAAU,YAAY,GAAkB,CAAC,MAAM,QAAQ,EAAM,CAEhE,EAAe,GACnB,EAAS,EAAM,EAAI,OAAQ,EAAc,UAAa,SAElD,GACJ,EACA,IAC4B,CAC5B,GAAI,IAAM,IAAA,GAAW,OAAO,EAC5B,GAAI,IAAM,IAAA,GAAW,OAAO,EAE5B,GAAI,MAAM,QAAQ,EAAE,EAAI,MAAM,QAAQ,EAAE,CAEtC,MAAO,CAAC,GAAG,EAAG,GAAG,EAAE,CAGrB,GAAI,EAAS,EAAE,EAAI,EAAS,EAAE,EAAI,CAAC,EAAY,EAAE,EAAI,CAAC,EAAY,EAAE,CAAE,CACpE,IAAM,EAA8B,CAAE,GAAG,EAAG,CAC5C,IAAK,IAAM,KAAO,OAAO,KAAK,EAAE,CAC9B,EAAO,GAAO,EACZ,EAAO,GACN,EAA0B,GAC5B,CAEH,OAAO,EAIT,OAAO,GAGH,GACJ,EACA,IACgB,CAChB,IAAM,EAAsB,CAAE,GAAG,EAAM,CAGvC,EAAO,OAAS,EAAY,EAAK,OAAQ,EAAS,OAAO,CAGzD,IAAM,EAAa,IAAI,IAAY,CACjC,GAAG,OAAO,KAAK,EAAK,CAAC,OAAQ,GAAM,IAAM,SAAS,CAClD,GAAG,OAAO,KAAK,EAAS,CAAC,OAAQ,GAAM,IAAM,SAAS,CACvD,CAAC,CAEF,IAAK,IAAM,KAAO,EAEhB,EAAO,GAAO,EACZ,EAAK,GACL,EAAS,GACV,CAGH,OAAO,GAGH,EAAa,GAAmC,CAE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,CAAC,EAIJ,IAAK,IAAM,KAAU,OAAO,KAAK,EAAW,CACtC,IAAW,WACf,EAAc,EAAkB,EAAa,EAE1C,GAAS,EAAG,GAAM,EAAW,GAAS,CACxC,CAAC,EAIN,OAAO,EAIT,MAAO,CAAE,OAAQ,EAAM,EAGZ,EACX,GAC0B,CAC1B,IAAM,EAAQ,EAAU,EAAQ,CAG1B,EAAsC,EAAE,CAC1C,EAAM,SAAW,IAAA,KACnB,EAAO,OAAS,EAAM,QAExB,IAAK,IAAM,KAAO,OAAO,KAAK,EAAM,CAAE,CACpC,GAAI,IAAQ,SAAU,SACtB,IAAM,EAAQ,EAAM,GAChB,IAAU,IAAA,KACZ,EAAO,GAAO,GAIlB,OAAO,GAkCI,EACX,GAEA,EAAmB,EAAW,QAAQ"}
@@ -1,2 +1,2 @@
1
- import{NodeType as e}from"@intlayer/types";const t=(r,i,a)=>{if(i==null)return r;if(r==null)if(Array.isArray(i))r=[];else if(typeof i==`object`)r={};else return i;if(r&&typeof r==`object`&&r.nodeType===e.Translation)if(a){let e=r.translation[a],n;return n=typeof i==`object`&&!Array.isArray(i)?t(e,i,void 0):i,{...r,translation:{...r.translation,[a]:n}}}else if(typeof i==`object`&&!Array.isArray(i)&&i.nodeType===e.Translation)return{...r,translation:{...r.translation,...i.translation}};else return n(i,a);if(Array.isArray(i))if(a&&Array.isArray(r)){let e=[],o=Math.max(i.length,r.length);for(let s=0;s<o;s++)s<i.length?s<r.length&&r[s]!==void 0?e[s]=t(r[s],i[s],a):e[s]=n(i[s],a):e[s]=r[s];return e}else return i.map(t=>t&&typeof t==`object`&&t.nodeType===e.Translation?t:n(t,a));if(typeof i==`object`&&!Array.isArray(i)){(typeof r!=`object`||Array.isArray(r))&&(r={});let e={...r};for(let o in i)Object.hasOwn(i,o)&&(r[o]===void 0?e[o]=n(i[o],a):e[o]=t(r[o],i[o],a));return e}return i},n=(t,r)=>{if(t==null||t&&typeof t==`object`&&t.nodeType===e.Translation)return t;if(Array.isArray(t))return t.map(e=>n(e,r));if(t&&typeof t==`object`){let e={};for(let i in t)Object.hasOwn(t,i)&&(e[i]=n(t[i],r));return e}return r?{nodeType:e.Translation,translation:{[r]:t}}:t},r=(e,n,r)=>{let i=t(Array.isArray(e.content)?[...e.content]:{...e.content},n,r);return{...e,content:i}};export{r as insertContentInDictionary};
1
+ import{NodeType as e}from"@intlayer/types/nodeType";const t=(r,i,a)=>{if(i==null)return r;if(r==null)if(Array.isArray(i))r=[];else if(typeof i==`object`)r={};else return i;if(r&&typeof r==`object`&&r.nodeType===e.Translation)if(a){let e=r.translation[a],n;return n=typeof i==`object`&&!Array.isArray(i)?t(e,i,void 0):i,{...r,translation:{...r.translation,[a]:n}}}else if(typeof i==`object`&&!Array.isArray(i)&&i.nodeType===e.Translation)return{...r,translation:{...r.translation,...i.translation}};else return n(i,a);if(Array.isArray(i))if(a&&Array.isArray(r)){let e=[],o=Math.max(i.length,r.length);for(let s=0;s<o;s++)s<i.length?s<r.length&&r[s]!==void 0?e[s]=t(r[s],i[s],a):e[s]=n(i[s],a):e[s]=r[s];return e}else return i.map(t=>t&&typeof t==`object`&&t.nodeType===e.Translation?t:n(t,a));if(typeof i==`object`&&!Array.isArray(i)){(typeof r!=`object`||Array.isArray(r))&&(r={});let e={...r};for(let o in i)Object.hasOwn(i,o)&&(r[o]===void 0?e[o]=n(i[o],a):e[o]=t(r[o],i[o],a));return e}return i},n=(t,r)=>{if(t==null||t&&typeof t==`object`&&t.nodeType===e.Translation)return t;if(Array.isArray(t))return t.map(e=>n(e,r));if(t&&typeof t==`object`){let e={};for(let i in t)Object.hasOwn(t,i)&&(e[i]=n(t[i],r));return e}return r?{nodeType:e.Translation,translation:{[r]:t}}:t},r=(e,n,r)=>{let i=t(Array.isArray(e.content)?[...e.content]:{...e.content},n,r);return{...e,content:i}};export{r as insertContentInDictionary};
2
2
  //# sourceMappingURL=insertContentInDictionary.mjs.map