@intlayer/core 8.1.2 → 8.1.3-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 (407) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +1 -29
  2. package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs +1 -212
  3. package/dist/cjs/deepTransformPlugins/getFilterMissingTranslationsContent.cjs.map +1 -1
  4. package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs +1 -94
  5. package/dist/cjs/deepTransformPlugins/getFilterTranslationsOnlyContent.cjs.map +1 -1
  6. package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs +1 -45
  7. package/dist/cjs/deepTransformPlugins/getFilteredLocalesContent.cjs.map +1 -1
  8. package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs +1 -33
  9. package/dist/cjs/deepTransformPlugins/getLocalizedContent.cjs.map +1 -1
  10. package/dist/cjs/deepTransformPlugins/getMaskContent.cjs +1 -27
  11. package/dist/cjs/deepTransformPlugins/getMaskContent.cjs.map +1 -1
  12. package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs +1 -82
  13. package/dist/cjs/deepTransformPlugins/getMissingLocalesContent.cjs.map +1 -1
  14. package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs +1 -87
  15. package/dist/cjs/deepTransformPlugins/getMultilingualDictionary.cjs.map +1 -1
  16. package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs +1 -60
  17. package/dist/cjs/deepTransformPlugins/getReplacedValuesContent.cjs.map +1 -1
  18. package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs +1 -122
  19. package/dist/cjs/deepTransformPlugins/getSplittedContent.cjs.map +1 -1
  20. package/dist/cjs/deepTransformPlugins/index.cjs +1 -32
  21. package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs +1 -106
  22. package/dist/cjs/deepTransformPlugins/insertContentInDictionary.cjs.map +1 -1
  23. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs +1 -64
  24. package/dist/cjs/dictionaryManipulator/editDictionaryByKeyPath.cjs.map +1 -1
  25. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs +1 -18
  26. package/dist/cjs/dictionaryManipulator/getContentNodeByKeyPath.cjs.map +1 -1
  27. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs +1 -55
  28. package/dist/cjs/dictionaryManipulator/getDefaultNode.cjs.map +1 -1
  29. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs +1 -26
  30. package/dist/cjs/dictionaryManipulator/getEmptyNode.cjs.map +1 -1
  31. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs +1 -23
  32. package/dist/cjs/dictionaryManipulator/getNodeChildren.cjs.map +1 -1
  33. package/dist/cjs/dictionaryManipulator/getNodeType.cjs +1 -36
  34. package/dist/cjs/dictionaryManipulator/getNodeType.cjs.map +1 -1
  35. package/dist/cjs/dictionaryManipulator/index.cjs +1 -27
  36. package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs +1 -69
  37. package/dist/cjs/dictionaryManipulator/mergeDictionaries.cjs.map +1 -1
  38. package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs +1 -30
  39. package/dist/cjs/dictionaryManipulator/normalizeDictionary.cjs.map +1 -1
  40. package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs +1 -48
  41. package/dist/cjs/dictionaryManipulator/orderDictionaries.cjs.map +1 -1
  42. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs +1 -31
  43. package/dist/cjs/dictionaryManipulator/removeContentNodeByKeyPath.cjs.map +1 -1
  44. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs +1 -39
  45. package/dist/cjs/dictionaryManipulator/renameContentNodeByKeyPath.cjs.map +1 -1
  46. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs +1 -38
  47. package/dist/cjs/dictionaryManipulator/updateNodeChildren.cjs.map +1 -1
  48. package/dist/cjs/formatters/compact.cjs +1 -25
  49. package/dist/cjs/formatters/compact.cjs.map +1 -1
  50. package/dist/cjs/formatters/currency.cjs +1 -29
  51. package/dist/cjs/formatters/currency.cjs.map +1 -1
  52. package/dist/cjs/formatters/date.cjs +1 -60
  53. package/dist/cjs/formatters/date.cjs.map +1 -1
  54. package/dist/cjs/formatters/index.cjs +1 -18
  55. package/dist/cjs/formatters/list.cjs +1 -30
  56. package/dist/cjs/formatters/list.cjs.map +1 -1
  57. package/dist/cjs/formatters/number.cjs +1 -18
  58. package/dist/cjs/formatters/number.cjs.map +1 -1
  59. package/dist/cjs/formatters/percentage.cjs +1 -25
  60. package/dist/cjs/formatters/percentage.cjs.map +1 -1
  61. package/dist/cjs/formatters/relativeTime.cjs +1 -33
  62. package/dist/cjs/formatters/relativeTime.cjs.map +1 -1
  63. package/dist/cjs/formatters/units.cjs +1 -23
  64. package/dist/cjs/formatters/units.cjs.map +1 -1
  65. package/dist/cjs/getStorageAttributes.cjs +1 -134
  66. package/dist/cjs/getStorageAttributes.cjs.map +1 -1
  67. package/dist/cjs/index.cjs +1 -300
  68. package/dist/cjs/interpreter/getCondition.cjs +1 -27
  69. package/dist/cjs/interpreter/getCondition.cjs.map +1 -1
  70. package/dist/cjs/interpreter/getContent/deepTransform.cjs +1 -41
  71. package/dist/cjs/interpreter/getContent/deepTransform.cjs.map +1 -1
  72. package/dist/cjs/interpreter/getContent/getContent.cjs +1 -34
  73. package/dist/cjs/interpreter/getContent/getContent.cjs.map +1 -1
  74. package/dist/cjs/interpreter/getContent/index.cjs +1 -14
  75. package/dist/cjs/interpreter/getContent/plugins.cjs +1 -161
  76. package/dist/cjs/interpreter/getContent/plugins.cjs.map +1 -1
  77. package/dist/cjs/interpreter/getDictionary.cjs +1 -24
  78. package/dist/cjs/interpreter/getDictionary.cjs.map +1 -1
  79. package/dist/cjs/interpreter/getEnumeration.cjs +1 -72
  80. package/dist/cjs/interpreter/getEnumeration.cjs.map +1 -1
  81. package/dist/cjs/interpreter/getGender.cjs +1 -38
  82. package/dist/cjs/interpreter/getGender.cjs.map +1 -1
  83. package/dist/cjs/interpreter/getHTML.cjs +1 -121
  84. package/dist/cjs/interpreter/getHTML.cjs.map +1 -1
  85. package/dist/cjs/interpreter/getInsertion.cjs +1 -22
  86. package/dist/cjs/interpreter/getInsertion.cjs.map +1 -1
  87. package/dist/cjs/interpreter/getIntlayer.cjs +1 -40
  88. package/dist/cjs/interpreter/getIntlayer.cjs.map +1 -1
  89. package/dist/cjs/interpreter/getNesting.cjs +1 -36
  90. package/dist/cjs/interpreter/getNesting.cjs.map +1 -1
  91. package/dist/cjs/interpreter/getTranslation.cjs +1 -112
  92. package/dist/cjs/interpreter/getTranslation.cjs.map +1 -1
  93. package/dist/cjs/interpreter/index.cjs +1 -31
  94. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs +1 -55
  95. package/dist/cjs/interpreter/splitAndJoinInsertion.cjs.map +1 -1
  96. package/dist/cjs/localization/getBrowserLocale.cjs +1 -143
  97. package/dist/cjs/localization/getBrowserLocale.cjs.map +1 -1
  98. package/dist/cjs/localization/getHTMLTextDir.cjs +1 -64
  99. package/dist/cjs/localization/getHTMLTextDir.cjs.map +1 -1
  100. package/dist/cjs/localization/getLocale.cjs +1 -27
  101. package/dist/cjs/localization/getLocale.cjs.map +1 -1
  102. package/dist/cjs/localization/getLocaleFromPath.cjs +1 -45
  103. package/dist/cjs/localization/getLocaleFromPath.cjs.map +1 -1
  104. package/dist/cjs/localization/getLocaleLang.cjs +1 -20
  105. package/dist/cjs/localization/getLocaleLang.cjs.map +1 -1
  106. package/dist/cjs/localization/getLocaleName.cjs +1 -10
  107. package/dist/cjs/localization/getLocaleName.cjs.map +1 -1
  108. package/dist/cjs/localization/getLocalizedUrl.cjs +1 -82
  109. package/dist/cjs/localization/getLocalizedUrl.cjs.map +1 -1
  110. package/dist/cjs/localization/getMultilingualUrls.cjs +1 -63
  111. package/dist/cjs/localization/getMultilingualUrls.cjs.map +1 -1
  112. package/dist/cjs/localization/getPathWithoutLocale.cjs +1 -55
  113. package/dist/cjs/localization/getPathWithoutLocale.cjs.map +1 -1
  114. package/dist/cjs/localization/getPrefix.cjs +1 -63
  115. package/dist/cjs/localization/getPrefix.cjs.map +1 -1
  116. package/dist/cjs/localization/index.cjs +1 -39
  117. package/dist/cjs/localization/localeDetector.cjs +1 -133
  118. package/dist/cjs/localization/localeDetector.cjs.map +1 -1
  119. package/dist/cjs/localization/localeMapper.cjs +1 -119
  120. package/dist/cjs/localization/localeMapper.cjs.map +1 -1
  121. package/dist/cjs/localization/localeResolver.cjs +1 -28
  122. package/dist/cjs/localization/localeResolver.cjs.map +1 -1
  123. package/dist/cjs/localization/rewriteUtils.cjs +1 -110
  124. package/dist/cjs/localization/rewriteUtils.cjs.map +1 -1
  125. package/dist/cjs/localization/validatePrefix.cjs +1 -54
  126. package/dist/cjs/localization/validatePrefix.cjs.map +1 -1
  127. package/dist/cjs/markdown/compiler.cjs +10 -810
  128. package/dist/cjs/markdown/compiler.cjs.map +1 -1
  129. package/dist/cjs/markdown/constants.cjs +1 -328
  130. package/dist/cjs/markdown/constants.cjs.map +1 -1
  131. package/dist/cjs/markdown/index.cjs +1 -120
  132. package/dist/cjs/markdown/parser.cjs +1 -66
  133. package/dist/cjs/markdown/parser.cjs.map +1 -1
  134. package/dist/cjs/markdown/renderer.cjs +1 -61
  135. package/dist/cjs/markdown/renderer.cjs.map +1 -1
  136. package/dist/cjs/markdown/utils.cjs +6 -391
  137. package/dist/cjs/markdown/utils.cjs.map +1 -1
  138. package/dist/cjs/messageFormat/ICU.cjs +1 -319
  139. package/dist/cjs/messageFormat/ICU.cjs.map +1 -1
  140. package/dist/cjs/messageFormat/i18next.cjs +1 -330
  141. package/dist/cjs/messageFormat/i18next.cjs.map +1 -1
  142. package/dist/cjs/messageFormat/index.cjs +1 -11
  143. package/dist/cjs/messageFormat/verify-icu-format.cjs +2 -64
  144. package/dist/cjs/messageFormat/verify-icu-format.cjs.map +1 -1
  145. package/dist/cjs/messageFormat/vue-i18n.cjs +1 -166
  146. package/dist/cjs/messageFormat/vue-i18n.cjs.map +1 -1
  147. package/dist/cjs/transpiler/condition/condition.cjs +1 -26
  148. package/dist/cjs/transpiler/condition/condition.cjs.map +1 -1
  149. package/dist/cjs/transpiler/condition/index.cjs +1 -4
  150. package/dist/cjs/transpiler/enumeration/enumeration.cjs +1 -28
  151. package/dist/cjs/transpiler/enumeration/enumeration.cjs.map +1 -1
  152. package/dist/cjs/transpiler/enumeration/index.cjs +1 -4
  153. package/dist/cjs/transpiler/file/file.cjs +1 -52
  154. package/dist/cjs/transpiler/file/file.cjs.map +1 -1
  155. package/dist/cjs/transpiler/file/fileBrowser.cjs +1 -25
  156. package/dist/cjs/transpiler/file/fileBrowser.cjs.map +1 -1
  157. package/dist/cjs/transpiler/file/index.cjs +1 -5
  158. package/dist/cjs/transpiler/gender/gender.cjs +1 -26
  159. package/dist/cjs/transpiler/gender/gender.cjs.map +1 -1
  160. package/dist/cjs/transpiler/gender/index.cjs +1 -4
  161. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs +1 -44
  162. package/dist/cjs/transpiler/html/getHTMLCustomComponents.cjs.map +1 -1
  163. package/dist/cjs/transpiler/html/html.cjs +1 -37
  164. package/dist/cjs/transpiler/html/html.cjs.map +1 -1
  165. package/dist/cjs/transpiler/html/htmlTags.cjs +1 -116
  166. package/dist/cjs/transpiler/html/htmlTags.cjs.map +1 -1
  167. package/dist/cjs/transpiler/html/index.cjs +1 -6
  168. package/dist/cjs/transpiler/index.cjs +1 -24
  169. package/dist/cjs/transpiler/insertion/getInsertionValues.cjs +1 -11
  170. package/dist/cjs/transpiler/insertion/getInsertionValues.cjs.map +1 -1
  171. package/dist/cjs/transpiler/insertion/index.cjs +1 -6
  172. package/dist/cjs/transpiler/insertion/insertion.cjs +1 -36
  173. package/dist/cjs/transpiler/insertion/insertion.cjs.map +1 -1
  174. package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs +2 -23
  175. package/dist/cjs/transpiler/markdown/getMarkdownMetadata.cjs.map +1 -1
  176. package/dist/cjs/transpiler/markdown/index.cjs +1 -6
  177. package/dist/cjs/transpiler/markdown/markdown.cjs +1 -54
  178. package/dist/cjs/transpiler/markdown/markdown.cjs.map +1 -1
  179. package/dist/cjs/transpiler/nesting/index.cjs +1 -4
  180. package/dist/cjs/transpiler/nesting/nesting.cjs +1 -27
  181. package/dist/cjs/transpiler/nesting/nesting.cjs.map +1 -1
  182. package/dist/cjs/transpiler/translation/index.cjs +1 -4
  183. package/dist/cjs/transpiler/translation/translation.cjs +1 -29
  184. package/dist/cjs/transpiler/translation/translation.cjs.map +1 -1
  185. package/dist/cjs/utils/checkIsURLAbsolute.cjs +1 -7
  186. package/dist/cjs/utils/checkIsURLAbsolute.cjs.map +1 -1
  187. package/dist/cjs/utils/getCookie.cjs +1 -32
  188. package/dist/cjs/utils/getCookie.cjs.map +1 -1
  189. package/dist/cjs/utils/index.cjs +1 -0
  190. package/dist/cjs/utils/intl.cjs +1 -91
  191. package/dist/cjs/utils/intl.cjs.map +1 -1
  192. package/dist/cjs/utils/isSameKeyPath.cjs +1 -7
  193. package/dist/cjs/utils/isSameKeyPath.cjs.map +1 -1
  194. package/dist/cjs/utils/isValidReactElement.cjs +1 -14
  195. package/dist/cjs/utils/isValidReactElement.cjs.map +1 -1
  196. package/dist/cjs/utils/localeStorage.cjs +1 -140
  197. package/dist/cjs/utils/localeStorage.cjs.map +1 -1
  198. package/dist/cjs/utils/parseYaml.cjs +16 -322
  199. package/dist/cjs/utils/parseYaml.cjs.map +1 -1
  200. package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs +1 -207
  201. package/dist/esm/deepTransformPlugins/getFilterMissingTranslationsContent.mjs.map +1 -1
  202. package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs +1 -89
  203. package/dist/esm/deepTransformPlugins/getFilterTranslationsOnlyContent.mjs.map +1 -1
  204. package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs +1 -42
  205. package/dist/esm/deepTransformPlugins/getFilteredLocalesContent.mjs.map +1 -1
  206. package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs +1 -31
  207. package/dist/esm/deepTransformPlugins/getLocalizedContent.mjs.map +1 -1
  208. package/dist/esm/deepTransformPlugins/getMaskContent.mjs +1 -25
  209. package/dist/esm/deepTransformPlugins/getMaskContent.mjs.map +1 -1
  210. package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs +1 -77
  211. package/dist/esm/deepTransformPlugins/getMissingLocalesContent.mjs.map +1 -1
  212. package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs +1 -86
  213. package/dist/esm/deepTransformPlugins/getMultilingualDictionary.mjs.map +1 -1
  214. package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs +1 -59
  215. package/dist/esm/deepTransformPlugins/getReplacedValuesContent.mjs.map +1 -1
  216. package/dist/esm/deepTransformPlugins/getSplittedContent.mjs +1 -119
  217. package/dist/esm/deepTransformPlugins/getSplittedContent.mjs.map +1 -1
  218. package/dist/esm/deepTransformPlugins/index.mjs +1 -12
  219. package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs +1 -104
  220. package/dist/esm/deepTransformPlugins/insertContentInDictionary.mjs.map +1 -1
  221. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs +1 -62
  222. package/dist/esm/dictionaryManipulator/editDictionaryByKeyPath.mjs.map +1 -1
  223. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs +1 -16
  224. package/dist/esm/dictionaryManipulator/getContentNodeByKeyPath.mjs.map +1 -1
  225. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs +1 -53
  226. package/dist/esm/dictionaryManipulator/getDefaultNode.mjs.map +1 -1
  227. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs +1 -24
  228. package/dist/esm/dictionaryManipulator/getEmptyNode.mjs.map +1 -1
  229. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs +1 -21
  230. package/dist/esm/dictionaryManipulator/getNodeChildren.mjs.map +1 -1
  231. package/dist/esm/dictionaryManipulator/getNodeType.mjs +1 -34
  232. package/dist/esm/dictionaryManipulator/getNodeType.mjs.map +1 -1
  233. package/dist/esm/dictionaryManipulator/index.mjs +1 -14
  234. package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs +1 -66
  235. package/dist/esm/dictionaryManipulator/mergeDictionaries.mjs.map +1 -1
  236. package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs +1 -28
  237. package/dist/esm/dictionaryManipulator/normalizeDictionary.mjs.map +1 -1
  238. package/dist/esm/dictionaryManipulator/orderDictionaries.mjs +1 -45
  239. package/dist/esm/dictionaryManipulator/orderDictionaries.mjs.map +1 -1
  240. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs +1 -29
  241. package/dist/esm/dictionaryManipulator/removeContentNodeByKeyPath.mjs.map +1 -1
  242. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs +1 -37
  243. package/dist/esm/dictionaryManipulator/renameContentNodeByKeyPath.mjs.map +1 -1
  244. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs +1 -36
  245. package/dist/esm/dictionaryManipulator/updateNodeChildren.mjs.map +1 -1
  246. package/dist/esm/formatters/compact.mjs +1 -22
  247. package/dist/esm/formatters/compact.mjs.map +1 -1
  248. package/dist/esm/formatters/currency.mjs +1 -26
  249. package/dist/esm/formatters/currency.mjs.map +1 -1
  250. package/dist/esm/formatters/date.mjs +1 -57
  251. package/dist/esm/formatters/date.mjs.map +1 -1
  252. package/dist/esm/formatters/index.mjs +1 -10
  253. package/dist/esm/formatters/list.mjs +1 -27
  254. package/dist/esm/formatters/list.mjs.map +1 -1
  255. package/dist/esm/formatters/number.mjs +1 -15
  256. package/dist/esm/formatters/number.mjs.map +1 -1
  257. package/dist/esm/formatters/percentage.mjs +1 -22
  258. package/dist/esm/formatters/percentage.mjs.map +1 -1
  259. package/dist/esm/formatters/relativeTime.mjs +1 -30
  260. package/dist/esm/formatters/relativeTime.mjs.map +1 -1
  261. package/dist/esm/formatters/units.mjs +1 -20
  262. package/dist/esm/formatters/units.mjs.map +1 -1
  263. package/dist/esm/getStorageAttributes.mjs +1 -132
  264. package/dist/esm/getStorageAttributes.mjs.map +1 -1
  265. package/dist/esm/index.mjs +1 -82
  266. package/dist/esm/interpreter/getCondition.mjs +1 -25
  267. package/dist/esm/interpreter/getCondition.mjs.map +1 -1
  268. package/dist/esm/interpreter/getContent/deepTransform.mjs +1 -39
  269. package/dist/esm/interpreter/getContent/deepTransform.mjs.map +1 -1
  270. package/dist/esm/interpreter/getContent/getContent.mjs +1 -31
  271. package/dist/esm/interpreter/getContent/getContent.mjs.map +1 -1
  272. package/dist/esm/interpreter/getContent/index.mjs +1 -5
  273. package/dist/esm/interpreter/getContent/plugins.mjs +1 -153
  274. package/dist/esm/interpreter/getContent/plugins.mjs.map +1 -1
  275. package/dist/esm/interpreter/getDictionary.mjs +1 -23
  276. package/dist/esm/interpreter/getDictionary.mjs.map +1 -1
  277. package/dist/esm/interpreter/getEnumeration.mjs +1 -69
  278. package/dist/esm/interpreter/getEnumeration.mjs.map +1 -1
  279. package/dist/esm/interpreter/getGender.mjs +1 -36
  280. package/dist/esm/interpreter/getGender.mjs.map +1 -1
  281. package/dist/esm/interpreter/getHTML.mjs +1 -119
  282. package/dist/esm/interpreter/getHTML.mjs.map +1 -1
  283. package/dist/esm/interpreter/getInsertion.mjs +1 -20
  284. package/dist/esm/interpreter/getInsertion.mjs.map +1 -1
  285. package/dist/esm/interpreter/getIntlayer.mjs +1 -36
  286. package/dist/esm/interpreter/getIntlayer.mjs.map +1 -1
  287. package/dist/esm/interpreter/getNesting.mjs +1 -35
  288. package/dist/esm/interpreter/getNesting.mjs.map +1 -1
  289. package/dist/esm/interpreter/getTranslation.mjs +1 -110
  290. package/dist/esm/interpreter/getTranslation.mjs.map +1 -1
  291. package/dist/esm/interpreter/index.mjs +1 -13
  292. package/dist/esm/interpreter/splitAndJoinInsertion.mjs +1 -53
  293. package/dist/esm/interpreter/splitAndJoinInsertion.mjs.map +1 -1
  294. package/dist/esm/localization/getBrowserLocale.mjs +1 -138
  295. package/dist/esm/localization/getBrowserLocale.mjs.map +1 -1
  296. package/dist/esm/localization/getHTMLTextDir.mjs +1 -62
  297. package/dist/esm/localization/getHTMLTextDir.mjs.map +1 -1
  298. package/dist/esm/localization/getLocale.mjs +1 -24
  299. package/dist/esm/localization/getLocale.mjs.map +1 -1
  300. package/dist/esm/localization/getLocaleFromPath.mjs +1 -42
  301. package/dist/esm/localization/getLocaleFromPath.mjs.map +1 -1
  302. package/dist/esm/localization/getLocaleLang.mjs +1 -18
  303. package/dist/esm/localization/getLocaleLang.mjs.map +1 -1
  304. package/dist/esm/localization/getLocaleName.mjs +1 -9
  305. package/dist/esm/localization/getLocaleName.mjs.map +1 -1
  306. package/dist/esm/localization/getLocalizedUrl.mjs +1 -79
  307. package/dist/esm/localization/getLocalizedUrl.mjs.map +1 -1
  308. package/dist/esm/localization/getMultilingualUrls.mjs +1 -60
  309. package/dist/esm/localization/getMultilingualUrls.mjs.map +1 -1
  310. package/dist/esm/localization/getPathWithoutLocale.mjs +1 -52
  311. package/dist/esm/localization/getPathWithoutLocale.mjs.map +1 -1
  312. package/dist/esm/localization/getPrefix.mjs +1 -60
  313. package/dist/esm/localization/getPrefix.mjs.map +1 -1
  314. package/dist/esm/localization/index.mjs +1 -17
  315. package/dist/esm/localization/localeDetector.mjs +1 -131
  316. package/dist/esm/localization/localeDetector.mjs.map +1 -1
  317. package/dist/esm/localization/localeMapper.mjs +1 -114
  318. package/dist/esm/localization/localeMapper.mjs.map +1 -1
  319. package/dist/esm/localization/localeResolver.mjs +1 -25
  320. package/dist/esm/localization/localeResolver.mjs.map +1 -1
  321. package/dist/esm/localization/rewriteUtils.mjs +1 -104
  322. package/dist/esm/localization/rewriteUtils.mjs.map +1 -1
  323. package/dist/esm/localization/validatePrefix.mjs +1 -51
  324. package/dist/esm/localization/validatePrefix.mjs.map +1 -1
  325. package/dist/esm/markdown/compiler.mjs +10 -786
  326. package/dist/esm/markdown/compiler.mjs.map +1 -1
  327. package/dist/esm/markdown/constants.mjs +1 -247
  328. package/dist/esm/markdown/constants.mjs.map +1 -1
  329. package/dist/esm/markdown/index.mjs +1 -7
  330. package/dist/esm/markdown/parser.mjs +1 -65
  331. package/dist/esm/markdown/parser.mjs.map +1 -1
  332. package/dist/esm/markdown/renderer.mjs +1 -59
  333. package/dist/esm/markdown/renderer.mjs.map +1 -1
  334. package/dist/esm/markdown/utils.mjs +6 -361
  335. package/dist/esm/markdown/utils.mjs.map +1 -1
  336. package/dist/esm/messageFormat/ICU.mjs +1 -316
  337. package/dist/esm/messageFormat/ICU.mjs.map +1 -1
  338. package/dist/esm/messageFormat/i18next.mjs +1 -327
  339. package/dist/esm/messageFormat/i18next.mjs.map +1 -1
  340. package/dist/esm/messageFormat/index.mjs +1 -5
  341. package/dist/esm/messageFormat/verify-icu-format.mjs +2 -64
  342. package/dist/esm/messageFormat/verify-icu-format.mjs.map +1 -1
  343. package/dist/esm/messageFormat/vue-i18n.mjs +1 -163
  344. package/dist/esm/messageFormat/vue-i18n.mjs.map +1 -1
  345. package/dist/esm/transpiler/condition/condition.mjs +1 -24
  346. package/dist/esm/transpiler/condition/condition.mjs.map +1 -1
  347. package/dist/esm/transpiler/condition/index.mjs +1 -3
  348. package/dist/esm/transpiler/enumeration/enumeration.mjs +1 -26
  349. package/dist/esm/transpiler/enumeration/enumeration.mjs.map +1 -1
  350. package/dist/esm/transpiler/enumeration/index.mjs +1 -3
  351. package/dist/esm/transpiler/file/file.mjs +1 -49
  352. package/dist/esm/transpiler/file/file.mjs.map +1 -1
  353. package/dist/esm/transpiler/file/fileBrowser.mjs +1 -24
  354. package/dist/esm/transpiler/file/fileBrowser.mjs.map +1 -1
  355. package/dist/esm/transpiler/file/index.mjs +1 -3
  356. package/dist/esm/transpiler/gender/gender.mjs +1 -24
  357. package/dist/esm/transpiler/gender/gender.mjs.map +1 -1
  358. package/dist/esm/transpiler/gender/index.mjs +1 -3
  359. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs +1 -43
  360. package/dist/esm/transpiler/html/getHTMLCustomComponents.mjs.map +1 -1
  361. package/dist/esm/transpiler/html/html.mjs +1 -35
  362. package/dist/esm/transpiler/html/html.mjs.map +1 -1
  363. package/dist/esm/transpiler/html/htmlTags.mjs +1 -114
  364. package/dist/esm/transpiler/html/htmlTags.mjs.map +1 -1
  365. package/dist/esm/transpiler/html/index.mjs +1 -4
  366. package/dist/esm/transpiler/index.mjs +1 -13
  367. package/dist/esm/transpiler/insertion/getInsertionValues.mjs +1 -9
  368. package/dist/esm/transpiler/insertion/getInsertionValues.mjs.map +1 -1
  369. package/dist/esm/transpiler/insertion/index.mjs +1 -4
  370. package/dist/esm/transpiler/insertion/insertion.mjs +1 -34
  371. package/dist/esm/transpiler/insertion/insertion.mjs.map +1 -1
  372. package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs +2 -22
  373. package/dist/esm/transpiler/markdown/getMarkdownMetadata.mjs.map +1 -1
  374. package/dist/esm/transpiler/markdown/index.mjs +1 -4
  375. package/dist/esm/transpiler/markdown/markdown.mjs +1 -52
  376. package/dist/esm/transpiler/markdown/markdown.mjs.map +1 -1
  377. package/dist/esm/transpiler/nesting/index.mjs +1 -3
  378. package/dist/esm/transpiler/nesting/nesting.mjs +1 -25
  379. package/dist/esm/transpiler/nesting/nesting.mjs.map +1 -1
  380. package/dist/esm/transpiler/translation/index.mjs +1 -3
  381. package/dist/esm/transpiler/translation/translation.mjs +1 -27
  382. package/dist/esm/transpiler/translation/translation.mjs.map +1 -1
  383. package/dist/esm/utils/checkIsURLAbsolute.mjs +1 -5
  384. package/dist/esm/utils/checkIsURLAbsolute.mjs.map +1 -1
  385. package/dist/esm/utils/getCookie.mjs +1 -30
  386. package/dist/esm/utils/getCookie.mjs.map +1 -1
  387. package/dist/esm/utils/index.mjs +1 -0
  388. package/dist/esm/utils/intl.mjs +1 -86
  389. package/dist/esm/utils/intl.mjs.map +1 -1
  390. package/dist/esm/utils/isSameKeyPath.mjs +1 -5
  391. package/dist/esm/utils/isSameKeyPath.mjs.map +1 -1
  392. package/dist/esm/utils/isValidReactElement.mjs +1 -12
  393. package/dist/esm/utils/isValidReactElement.mjs.map +1 -1
  394. package/dist/esm/utils/localeStorage.mjs +1 -135
  395. package/dist/esm/utils/localeStorage.mjs.map +1 -1
  396. package/dist/esm/utils/parseYaml.mjs +16 -320
  397. package/dist/esm/utils/parseYaml.mjs.map +1 -1
  398. package/dist/types/formatters/index.d.ts +2 -1
  399. package/dist/types/index.d.ts +8 -2
  400. package/dist/types/interpreter/getContent/plugins.d.ts +4 -4
  401. package/dist/types/interpreter/getContent/plugins.d.ts.map +1 -1
  402. package/dist/types/localization/index.d.ts +2 -1
  403. package/dist/types/markdown/index.d.ts +4 -1
  404. package/dist/types/markdown/types.d.ts +1 -1
  405. package/dist/types/markdown/types.d.ts.map +1 -1
  406. package/dist/types/utils/index.d.ts +8 -0
  407. package/package.json +65 -11
@@ -1,29 +1 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") {
10
- for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
11
- key = keys[i];
12
- if (!__hasOwnProp.call(to, key) && key !== except) {
13
- __defProp(to, key, {
14
- get: ((k) => from[k]).bind(null, key),
15
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
- });
17
- }
18
- }
19
- }
20
- return to;
21
- };
22
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
- value: mod,
24
- enumerable: true
25
- }) : target, mod));
26
-
27
- //#endregion
28
-
29
- exports.__toESM = __toESM;
1
+ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));exports.__toESM=s;
@@ -1,213 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
4
- const require_interpreter_getTranslation = require('../interpreter/getTranslation.cjs');
5
- const require_transpiler_translation_translation = require('../transpiler/translation/translation.cjs');
6
- let _intlayer_types = require("@intlayer/types");
7
- let _intlayer_config_built = require("@intlayer/config/built");
8
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
9
-
10
- //#region src/deepTransformPlugins/getFilterMissingTranslationsContent.ts
11
- /**
12
- * Helper function to check if a node or its children contain translation nodes
13
- */
14
- const hasTranslationNodes = (node) => {
15
- if (typeof node !== "object" || node === null) return false;
16
- if (node?.nodeType === _intlayer_types.NodeType.Translation) return true;
17
- if (Array.isArray(node)) return node.some(hasTranslationNodes);
18
- return Object.values(node).some(hasTranslationNodes);
19
- };
20
- /**
21
- * Get all keys from an object, recursively
22
- */
23
- const getObjectKeys = (obj) => {
24
- const keys = /* @__PURE__ */ new Set();
25
- if (typeof obj !== "object" || obj === null) return keys;
26
- for (const key in obj) keys.add(key);
27
- return keys;
28
- };
29
- /**
30
- * Check if two objects have the same structure (same keys)
31
- */
32
- const hasSameStructure = (obj1, obj2) => {
33
- if (typeof obj1 !== "object" || typeof obj2 !== "object") return typeof obj1 === typeof obj2;
34
- if (obj1 === null || obj2 === null) return obj1 === obj2;
35
- if (Array.isArray(obj1) !== Array.isArray(obj2)) return false;
36
- const keys1 = getObjectKeys(obj1);
37
- const keys2 = getObjectKeys(obj2);
38
- if (keys1.size !== keys2.size) return false;
39
- for (const key of keys1) if (!keys2.has(key)) return false;
40
- return true;
41
- };
42
- /**
43
- * Check if all locales in a translation node have the same structure (recursively)
44
- * Returns an object with locales that have missing keys
45
- */
46
- const checkTranslationStructureConsistency = (translationNode) => {
47
- const locales = Object.keys(translationNode);
48
- const localesWithMissingKeys = /* @__PURE__ */ new Set();
49
- if (locales.length <= 1) return {
50
- hasInconsistency: false,
51
- localesWithMissingKeys
52
- };
53
- const checkStructureRecursive = (path, localeValues) => {
54
- const localesWithIssues = /* @__PURE__ */ new Set();
55
- const allKeys = /* @__PURE__ */ new Set();
56
- const objectLocales = /* @__PURE__ */ new Map();
57
- for (const [locale, value] of localeValues.entries()) if (typeof value === "object" && value !== null && !Array.isArray(value)) {
58
- objectLocales.set(locale, value);
59
- const keys = getObjectKeys(value);
60
- for (const key of keys) allKeys.add(key);
61
- }
62
- if (objectLocales.size === 0) return localesWithIssues;
63
- for (const [locale, value] of objectLocales.entries()) if (getObjectKeys(value).size !== allKeys.size) localesWithIssues.add(locale);
64
- for (const key of allKeys) {
65
- const nestedValues = /* @__PURE__ */ new Map();
66
- for (const [locale, value] of objectLocales.entries()) if (value[key] !== void 0) nestedValues.set(locale, value[key]);
67
- if (nestedValues.size > 1) {
68
- const nestedIssues = checkStructureRecursive(path ? `${path}.${key}` : key, nestedValues);
69
- for (const locale of nestedIssues) localesWithIssues.add(locale);
70
- }
71
- }
72
- return localesWithIssues;
73
- };
74
- const rootValues = /* @__PURE__ */ new Map();
75
- for (const locale of locales) rootValues.set(locale, translationNode[locale]);
76
- const issuesFound = checkStructureRecursive("", rootValues);
77
- const hasInconsistency = issuesFound.size > 0;
78
- for (const locale of issuesFound) localesWithMissingKeys.add(locale);
79
- return {
80
- hasInconsistency,
81
- localesWithMissingKeys
82
- };
83
- };
84
- /**
85
- * Check if array elements have consistent structures
86
- */
87
- const checkArrayStructureConsistency = (arr) => {
88
- if (arr.length <= 1) return true;
89
- const firstElement = arr[0];
90
- for (let i = 1; i < arr.length; i++) if (!hasSameStructure(firstElement, arr[i])) return false;
91
- return true;
92
- };
93
- /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
94
- const filterMissingTranslationsOnlyPlugin = (localeToCheck) => ({
95
- id: "filter-missing-translations-only-plugin",
96
- canHandle: (node) => {
97
- return typeof node === "object" && node !== null;
98
- },
99
- transform: (node, props, deepTransformNode) => {
100
- if (typeof node === "object" && node?.nodeType === _intlayer_types.NodeType.Translation) {
101
- const result = structuredClone(node[_intlayer_types.NodeType.Translation]);
102
- const hasLocaleTranslation = Object.keys(result).includes(localeToCheck);
103
- const { hasInconsistency, localesWithMissingKeys } = checkTranslationStructureConsistency(result);
104
- const hasStructuralIssue = hasInconsistency && localesWithMissingKeys.has(localeToCheck);
105
- if (hasLocaleTranslation && !hasStructuralIssue) return;
106
- for (const key in result) {
107
- const childProps = {
108
- ...props,
109
- children: result[key],
110
- keyPath: [...props.keyPath, {
111
- type: _intlayer_types.NodeType.Translation,
112
- key
113
- }]
114
- };
115
- result[key] = deepTransformNode(result[key], {
116
- ...childProps,
117
- plugins: [...(props.plugins ?? []).filter((plugin) => plugin.id !== "filter-missing-translations-only-plugin")]
118
- });
119
- }
120
- const baseLocale = _intlayer_config_built.default?.internationalization?.defaultLocale;
121
- const availableLocales = Object.keys(result);
122
- if (availableLocales.length === 0) return;
123
- const fallbackLocale = availableLocales.includes(baseLocale) ? baseLocale : availableLocales[0];
124
- const fallbackValue = require_interpreter_getTranslation.getTranslation(result, baseLocale, fallbackLocale);
125
- return require_transpiler_translation_translation.t({ [fallbackLocale]: fallbackValue });
126
- } else if (typeof node === "object" && node !== null && !Array.isArray(node) && !node?.nodeType) {
127
- const result = {};
128
- let hasMissingTranslations = false;
129
- const arrayKeysIncluded = [];
130
- const primitiveSiblingsToAppend = [];
131
- for (const key in node) {
132
- const originalChild = node[key];
133
- const transformedChild = deepTransformNode(originalChild, {
134
- ...props,
135
- children: originalChild,
136
- keyPath: [...props.keyPath, {
137
- type: _intlayer_types.NodeType.Object,
138
- key
139
- }]
140
- });
141
- if (originalChild === null || typeof originalChild !== "object" && typeof originalChild !== "function") {
142
- if (originalChild !== void 0) primitiveSiblingsToAppend.push(originalChild);
143
- continue;
144
- }
145
- if (transformedChild !== void 0 && (hasTranslationNodes(originalChild) || Array.isArray(originalChild))) {
146
- result[key] = transformedChild;
147
- hasMissingTranslations = true;
148
- if (Array.isArray(transformedChild)) arrayKeysIncluded.push(key);
149
- }
150
- }
151
- if (arrayKeysIncluded.length > 0 && primitiveSiblingsToAppend.length > 0) {
152
- const targetArrayKey = arrayKeysIncluded[0];
153
- if (Array.isArray(result[targetArrayKey])) {
154
- result[targetArrayKey] = [...result[targetArrayKey], ...primitiveSiblingsToAppend];
155
- hasMissingTranslations = true;
156
- }
157
- }
158
- return hasMissingTranslations ? result : void 0;
159
- } else if (Array.isArray(node)) {
160
- const hasConsistentStructure = checkArrayStructureConsistency(node);
161
- const result = node.map((child, index) => {
162
- return deepTransformNode(child, {
163
- ...props,
164
- children: child,
165
- keyPath: [...props.keyPath, {
166
- type: _intlayer_types.NodeType.Array,
167
- key: index
168
- }]
169
- });
170
- }).filter((item) => item !== null && item !== void 0);
171
- if (!hasConsistentStructure && result.length === 0) return node;
172
- return result.length > 0 ? result : void 0;
173
- }
174
- return node;
175
- }
176
- });
177
- /**
178
- * For each translation node, it compare is both localeToCheck and baseLocale are present.
179
- *
180
- * If yes, it should remove the node from the content.
181
- * If no, it should keep the node
182
- *
183
- * In complete mode, for large dictionaries, we want to filter all content that is already translated
184
- *
185
- * locale: fr
186
- *
187
- * { test1: t({ ar: 'Hello', en: 'Hello', fr: 'Bonjour' } }) -> {}
188
- * { test2: t({ ar: 'Hello', en: 'Hello' }) } -> { test2: t({ ar: 'Hello', en: 'Hello' }) }
189
- *
190
- */
191
- const getFilterMissingTranslationsContent = (node, localeToCheck, nodeProps) => {
192
- const plugins = [filterMissingTranslationsOnlyPlugin(localeToCheck), ...nodeProps.plugins ?? []];
193
- const result = require_interpreter_getContent_deepTransform.deepTransformNode(node, {
194
- ...nodeProps,
195
- plugins
196
- });
197
- if (result === void 0) return {};
198
- return JSON.parse(JSON.stringify(result));
199
- };
200
- const getFilterMissingTranslationsDictionary = (dictionary, localeToCheck) => ({
201
- ...dictionary,
202
- content: getFilterMissingTranslationsContent(dictionary.content, localeToCheck, {
203
- dictionaryKey: dictionary.key,
204
- keyPath: [],
205
- plugins: []
206
- })
207
- });
208
-
209
- //#endregion
210
- exports.filterMissingTranslationsOnlyPlugin = filterMissingTranslationsOnlyPlugin;
211
- exports.getFilterMissingTranslationsContent = getFilterMissingTranslationsContent;
212
- exports.getFilterMissingTranslationsDictionary = getFilterMissingTranslationsDictionary;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../interpreter/getContent/deepTransform.cjs`),n=require(`../interpreter/getTranslation.cjs`),r=require(`../transpiler/translation/translation.cjs`);let i=require(`@intlayer/types`),a=require(`@intlayer/config/built`);a=e.__toESM(a);const o=e=>typeof e!=`object`||!e?!1:e?.nodeType===i.NodeType.Translation?!0:Array.isArray(e)?e.some(o):Object.values(e).some(o),s=e=>{let t=new Set;if(typeof e!=`object`||!e)return t;for(let n in e)t.add(n);return t},c=(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=s(e),r=s(t);if(n.size!==r.size)return!1;for(let e of n)if(!r.has(e))return!1;return!0},l=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=s(n);for(let e of t)i.add(e)}if(a.size===0)return n;for(let[e,t]of a.entries())s(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),o=a.size>0;for(let e of a)n.add(e);return{hasInconsistency:o,localesWithMissingKeys:n}},u=e=>{if(e.length<=1)return!0;let t=e[0];for(let n=1;n<e.length;n++)if(!c(t,e[n]))return!1;return!0},d=e=>({id:`filter-missing-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(t,s,c)=>{if(typeof t==`object`&&t?.nodeType===i.NodeType.Translation){let o=structuredClone(t[i.NodeType.Translation]),u=Object.keys(o).includes(e),{hasInconsistency:d,localesWithMissingKeys:f}=l(o),p=d&&f.has(e);if(u&&!p)return;for(let e in o){let t={...s,children:o[e],keyPath:[...s.keyPath,{type:i.NodeType.Translation,key:e}]};o[e]=c(o[e],{...t,plugins:[...(s.plugins??[]).filter(e=>e.id!==`filter-missing-translations-only-plugin`)]})}let m=a.default?.internationalization?.defaultLocale,h=Object.keys(o);if(h.length===0)return;let g=h.includes(m)?m:h[0],_=n.getTranslation(o,m,g);return r.t({[g]:_})}else if(typeof t==`object`&&t&&!Array.isArray(t)&&!t?.nodeType){let e={},n=!1,r=[],a=[];for(let l in t){let u=t[l],d=c(u,{...s,children:u,keyPath:[...s.keyPath,{type:i.NodeType.Object,key:l}]});if(u===null||typeof u!=`object`&&typeof u!=`function`){u!==void 0&&a.push(u);continue}d!==void 0&&(o(u)||Array.isArray(u))&&(e[l]=d,n=!0,Array.isArray(d)&&r.push(l))}if(r.length>0&&a.length>0){let t=r[0];Array.isArray(e[t])&&(e[t]=[...e[t],...a],n=!0)}return n?e:void 0}else if(Array.isArray(t)){let e=u(t),n=t.map((e,t)=>c(e,{...s,children:e,keyPath:[...s.keyPath,{type:i.NodeType.Array,key:t}]})).filter(e=>e!=null);return!e&&n.length===0?t:n.length>0?n:void 0}return t}}),f=(e,n,r)=>{let i=[d(n),...r.plugins??[]],a=t.deepTransformNode(e,{...r,plugins:i});return a===void 0?{}:JSON.parse(JSON.stringify(a))},p=(e,t)=>({...e,content:f(e.content,t,{dictionaryKey:e.key,keyPath:[],plugins:[]})});exports.filterMissingTranslationsOnlyPlugin=d,exports.getFilterMissingTranslationsContent=f,exports.getFilterMissingTranslationsDictionary=p;
213
2
  //# sourceMappingURL=getFilterMissingTranslationsContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilterMissingTranslationsContent.cjs","names":["NodeType","configuration","getTranslation","tCore","deepTransformNode"],"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":";;;;;;;;;;;;;AAmBA,MAAM,uBAAuB,SAAuB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;AAGT,KAAI,MAAM,aAAaA,yBAAS,YAC9B,QAAO;AAGT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,oBAAoB;AAGvC,QAAO,OAAO,OAAO,KAAK,CAAC,KAAK,oBAAoB;;;;;AAMtD,MAAM,iBAAiB,QAA0B;CAC/C,MAAM,uBAAO,IAAI,KAAa;AAE9B,KAAI,OAAO,QAAQ,YAAY,QAAQ,KACrC,QAAO;AAGT,MAAK,MAAM,OAAO,IAChB,MAAK,IAAI,IAAI;AAGf,QAAO;;;;;AAMT,MAAM,oBAAoB,MAAW,SAAuB;AAC1D,KAAI,OAAO,SAAS,YAAY,OAAO,SAAS,SAC9C,QAAO,OAAO,SAAS,OAAO;AAGhC,KAAI,SAAS,QAAQ,SAAS,KAC5B,QAAO,SAAS;AAGlB,KAAI,MAAM,QAAQ,KAAK,KAAK,MAAM,QAAQ,KAAK,CAC7C,QAAO;CAGT,MAAM,QAAQ,cAAc,KAAK;CACjC,MAAM,QAAQ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;KACV,SAAS,CACP,GAAG,MAAM,SACT;MAAE,MAAMA,yBAAS;MAAO,KAAK;MAAO,CACrC;KACF,CAC0C;KAC3C,CACD,QAAQ,SAAS,SAAS,QAAQ,SAAS,OAAU;AAIxD,OAAI,CAAC,0BAA0B,OAAO,WAAW,EAE/C,QAAO;AAIT,UAAO,OAAO,SAAS,IAAI,SAAS;;AAGtC,SAAO;;CAEV;;;;;;;;;;;;;;;AAgBD,MAAa,uCAIX,MACA,eACA,cACG;CACH,MAAM,UAAqB,CACzB,oCAAoC,cAAc,EAClD,GAAI,UAAU,WAAW,EAAE,CAC5B;CAED,MAAM,SAASI,+DAAkB,MAAM;EACrC,GAAG;EACH;EACD,CAAC;AAGF,KAAI,WAAW,OAEb,QAAO,EAAE;AAEX,QAAO,KAAK,MAAM,KAAK,UAAU,OAAO,CAAC;;AAG3C,MAAa,0CACX,YACA,mBACI;CACJ,GAAG;CACH,SAAS,oCACP,WAAW,SACX,eACA;EACE,eAAe,WAAW;EAC1B,SAAS,EAAE;EACX,SAAS,EAAE;EACZ,CACF;CACF"}
1
+ {"version":3,"file":"getFilterMissingTranslationsContent.cjs","names":["NodeType","configuration","getTranslation","tCore","deepTransformNode"],"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":"2WAmBA,MAAM,EAAuB,GACvB,OAAO,GAAS,WAAY,EACvB,GAGL,GAAM,WAAaA,EAAAA,SAAS,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,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CAEK,EAASI,EAAAA,kBAAkB,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,95 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
4
- const require_interpreter_getTranslation = require('../interpreter/getTranslation.cjs');
5
- let _intlayer_types = require("@intlayer/types");
6
- let _intlayer_config_built = require("@intlayer/config/built");
7
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
8
-
9
- //#region src/deepTransformPlugins/getFilterTranslationsOnlyContent.ts
10
- /**
11
- * Helper function to check if a node or its children contain translation nodes
12
- */
13
- const hasTranslationNodes = (node) => {
14
- if (typeof node !== "object" || node === null) return false;
15
- if (node?.nodeType === _intlayer_types.NodeType.Translation) return true;
16
- if (Array.isArray(node)) return node.some(hasTranslationNodes);
17
- return Object.values(node).some(hasTranslationNodes);
18
- };
19
- /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
20
- const filterTranslationsOnlyPlugin = (locale, fallback) => ({
21
- id: "filter-translations-only-plugin",
22
- canHandle: (node) => {
23
- return typeof node === "object" && node !== null;
24
- },
25
- transform: (node, props, deepTransformNode) => {
26
- if (typeof node === "object" && node?.nodeType === _intlayer_types.NodeType.Translation) {
27
- const result = structuredClone(node[_intlayer_types.NodeType.Translation]);
28
- for (const key in result) {
29
- const childProps = {
30
- ...props,
31
- children: result[key],
32
- keyPath: [...props.keyPath, {
33
- type: _intlayer_types.NodeType.Translation,
34
- key
35
- }]
36
- };
37
- result[key] = deepTransformNode(result[key], {
38
- ...childProps,
39
- plugins: [...(props.plugins ?? []).filter((plugin) => plugin.id !== "filter-translations-only-plugin")]
40
- });
41
- }
42
- return require_interpreter_getTranslation.getTranslation(result, locale, fallback);
43
- } else if (typeof node === "object" && node !== null && !Array.isArray(node) && !node?.nodeType) {
44
- const result = {};
45
- for (const key in node) if (hasTranslationNodes(node[key])) {
46
- const childProps = {
47
- ...props,
48
- children: node[key],
49
- keyPath: [...props.keyPath, {
50
- type: _intlayer_types.NodeType.Object,
51
- key
52
- }]
53
- };
54
- result[key] = deepTransformNode(node[key], childProps);
55
- }
56
- return result;
57
- } else if (Array.isArray(node)) return node.map((child, index) => {
58
- return deepTransformNode(child, {
59
- ...props,
60
- children: child,
61
- keyPath: [...props.keyPath, {
62
- type: _intlayer_types.NodeType.Array,
63
- key: index
64
- }]
65
- });
66
- });
67
- return "to remove from the object";
68
- }
69
- });
70
- /**
71
- * Return the content of a node with only the translation plugin.
72
- *
73
- * @param node The node to transform.
74
- * @param locale The locale to use if your transformers need it (e.g. for translations).
75
- */
76
- const getFilterTranslationsOnlyContent = (node, locale = _intlayer_config_built.default?.internationalization?.defaultLocale, nodeProps, fallback) => {
77
- const plugins = [filterTranslationsOnlyPlugin(locale, fallback), ...nodeProps.plugins ?? []];
78
- return require_interpreter_getContent_deepTransform.deepTransformNode(node, {
79
- ...nodeProps,
80
- plugins
81
- });
82
- };
83
- const getFilterTranslationsOnlyDictionary = (dictionary, locale = _intlayer_config_built.default?.internationalization?.defaultLocale, fallback) => ({
84
- ...dictionary,
85
- content: getFilterTranslationsOnlyContent(dictionary.content, locale, {
86
- dictionaryKey: dictionary.key,
87
- keyPath: []
88
- }, fallback)
89
- });
90
-
91
- //#endregion
92
- exports.filterTranslationsOnlyPlugin = filterTranslationsOnlyPlugin;
93
- exports.getFilterTranslationsOnlyContent = getFilterTranslationsOnlyContent;
94
- exports.getFilterTranslationsOnlyDictionary = getFilterTranslationsOnlyDictionary;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../interpreter/getContent/deepTransform.cjs`),n=require(`../interpreter/getTranslation.cjs`);let r=require(`@intlayer/types`),i=require(`@intlayer/config/built`);i=e.__toESM(i);const a=e=>typeof e!=`object`||!e?!1:e?.nodeType===r.NodeType.Translation?!0:Array.isArray(e)?e.some(a):Object.values(e).some(a),o=(e,t)=>({id:`filter-translations-only-plugin`,canHandle:e=>typeof e==`object`&&!!e,transform:(i,o,s)=>{if(typeof i==`object`&&i?.nodeType===r.NodeType.Translation){let a=structuredClone(i[r.NodeType.Translation]);for(let e in a){let t={...o,children:a[e],keyPath:[...o.keyPath,{type:r.NodeType.Translation,key:e}]};a[e]=s(a[e],{...t,plugins:[...(o.plugins??[]).filter(e=>e.id!==`filter-translations-only-plugin`)]})}return n.getTranslation(a,e,t)}else if(typeof i==`object`&&i&&!Array.isArray(i)&&!i?.nodeType){let e={};for(let t in i)if(a(i[t])){let n={...o,children:i[t],keyPath:[...o.keyPath,{type:r.NodeType.Object,key:t}]};e[t]=s(i[t],n)}return e}else if(Array.isArray(i))return i.map((e,t)=>s(e,{...o,children:e,keyPath:[...o.keyPath,{type:r.NodeType.Array,key:t}]}));return`to remove from the object`}}),s=(e,n=i.default?.internationalization?.defaultLocale,r,a)=>{let s=[o(n,a),...r.plugins??[]];return t.deepTransformNode(e,{...r,plugins:s})},c=(e,t=i.default?.internationalization?.defaultLocale,n)=>({...e,content:s(e.content,t,{dictionaryKey:e.key,keyPath:[]},n)});exports.filterTranslationsOnlyPlugin=o,exports.getFilterTranslationsOnlyContent=s,exports.getFilterTranslationsOnlyDictionary=c;
95
2
  //# sourceMappingURL=getFilterTranslationsOnlyContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilterTranslationsOnlyContent.cjs","names":["NodeType","getTranslation","configuration","deepTransformNode"],"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":";;;;;;;;;;;;AAmBA,MAAM,uBAAuB,SAAuB;AAClD,KAAI,OAAO,SAAS,YAAY,SAAS,KACvC,QAAO;AAGT,KAAI,MAAM,aAAaA,yBAAS,YAC9B,QAAO;AAGT,KAAI,MAAM,QAAQ,KAAK,CACrB,QAAO,KAAK,KAAK,oBAAoB;AAGvC,QAAO,OAAO,OAAO,KAAK,CAAC,KAAK,oBAAoB;;;AAItD,MAAa,gCACX,QACA,cACa;CACb,I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,EAC9C,GAAI,UAAU,WAAW,EAAE,CAC5B;AAED,QAAOC,+DAAkB,MAAM;EAC7B,GAAG;EACH;EACD,CAAC;;AAGJ,MAAa,uCACX,YACA,SAAwBD,gCAAe,sBACnC,eACJ,cACI;CACJ,GAAG;CACH,SAAS,iCACP,WAAW,SACX,QACA;EAAE,eAAe,WAAW;EAAK,SAAS,EAAE;EAAE,EAC9C,SACD;CACF"}
1
+ {"version":3,"file":"getFilterTranslationsOnlyContent.cjs","names":["NodeType","getTranslation","configuration","deepTransformNode"],"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":"oTAmBA,MAAM,EAAuB,GACvB,OAAO,GAAS,WAAY,EACvB,GAGL,GAAM,WAAaA,EAAAA,SAAS,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,WAAaA,EAAAA,SAAS,YAAa,CACvE,IAAM,EAAS,gBACZ,EAA4BA,EAAAA,SAAS,aACvC,CAED,IAAK,IAAM,KAAO,EAAQ,CACxB,IAAM,EAAa,CACjB,GAAG,EACH,SAAU,EAAO,GACjB,QAAS,CACP,GAAG,EAAM,QACT,CAAE,KAAMA,EAAAA,SAAS,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,OAAOC,EAAAA,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,KAAMD,EAAAA,SAAS,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,KAAMA,EAAAA,SAAS,MAAO,IAAK,EAAO,CACrC,CACF,CAC0C,CAC3C,CAGJ,MAAO,6BAEV,EAQY,GAIX,EACA,EAAYE,EAAAA,SAAe,sBAAsB,cACjD,EACA,IACG,CACH,IAAM,EAAqB,CACzB,EAA6B,EAAQ,EAAS,CAC9C,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAOC,EAAAA,kBAAkB,EAAM,CAC7B,GAAG,EACH,UACD,CAAC,EAGS,GACX,EACA,EAAwBD,EAAAA,SAAe,sBACnC,cACJ,KACI,CACJ,GAAG,EACH,QAAS,EACP,EAAW,QACX,EACA,CAAE,cAAe,EAAW,IAAK,QAAS,EAAE,CAAE,CAC9C,EACD,CACF"}
@@ -1,46 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
4
- let _intlayer_types = require("@intlayer/types");
5
-
6
- //#region src/deepTransformPlugins/getFilteredLocalesContent.ts
7
- const filterTranslationsPlugin = (locales) => ({
8
- id: "filter-translations-plugin",
9
- canHandle: (node) => typeof node === "object" && node?.nodeType === _intlayer_types.NodeType.Translation,
10
- transform: (node, props, deepTransformNode) => {
11
- const translationMap = node.translation;
12
- const filteredTranslationMap = Object.fromEntries(Object.entries(translationMap).filter(([key]) => locales.includes(key)));
13
- return {
14
- ...node,
15
- translation: deepTransformNode(filteredTranslationMap, {
16
- ...props,
17
- keyPath: [...props.keyPath, {
18
- type: _intlayer_types.NodeType.Object,
19
- key: _intlayer_types.NodeType.Translation
20
- }]
21
- })
22
- };
23
- }
24
- });
25
- const getFilteredLocalesContent = (node, locales, nodeProps) => {
26
- const plugins = [filterTranslationsPlugin(Array.isArray(locales) ? locales : [locales]), ...nodeProps.plugins ?? []];
27
- return require_interpreter_getContent_deepTransform.deepTransformNode(node, {
28
- ...nodeProps,
29
- plugins
30
- });
31
- };
32
- const getFilteredLocalesDictionary = (dictionary, locale) => {
33
- const localesArray = Array.isArray(locale) ? locale : [locale];
34
- return {
35
- ...dictionary,
36
- content: getFilteredLocalesContent(dictionary.content, localesArray, {
37
- dictionaryKey: dictionary.key,
38
- keyPath: []
39
- })
40
- };
41
- };
42
-
43
- //#endregion
44
- exports.getFilteredLocalesContent = getFilteredLocalesContent;
45
- exports.getFilteredLocalesDictionary = getFilteredLocalesDictionary;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`}),require(`../_virtual/_rolldown/runtime.cjs`);const e=require(`../interpreter/getContent/deepTransform.cjs`);let t=require(`@intlayer/types`);const n=e=>({id:`filter-translations-plugin`,canHandle:e=>typeof e==`object`&&e?.nodeType===t.NodeType.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.NodeType.Object,key:t.NodeType.Translation}]})}}}),r=(t,r,i)=>{let a=[n(Array.isArray(r)?r:[r]),...i.plugins??[]];return e.deepTransformNode(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:[]})}};exports.getFilteredLocalesContent=r,exports.getFilteredLocalesDictionary=i;
46
2
  //# sourceMappingURL=getFilteredLocalesContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getFilteredLocalesContent.cjs","names":["NodeType","deepTransformNode"],"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":";;;;;;AAYA,MAAM,4BAA4B,aAAuC;CACvE,IAAI;CACJ,YAAY,SACV,OAAO,SAAS,YAAY,MAAM,aAAaA,yBAAS;CAC1D,YAAY,MAAM,OAAO,sBAAsB;EAC7C,MAAM,iBAAiB,KAAK;EAE5B,MAAM,yBAAyB,OAAO,YACpC,OAAO,QAAQ,eAAe,CAAC,QAAQ,CAAC,SACtC,QAAQ,SAAS,IAAqB,CACvC,CACF;AAED,SAAO;GACL,GAAG;GACH,aAAa,kBAAkB,wBAAwB;IACrD,GAAG;IACH,SAAS,CACP,GAAG,MAAM,SACT;KAAE,MAAMA,yBAAS;KAAQ,KAAKA,yBAAS;KAAa,CACrD;IACF,CAAC;GACH;;CAEJ;AAED,MAAa,6BACX,MACA,SACA,cACG;CAGH,MAAM,UAAqB,CACzB,yBAHmB,MAAM,QAAQ,QAAQ,GAAG,UAAU,CAAC,QAAQ,CAGzB,EACtC,GAAI,UAAU,WAAW,EAAE,CAC5B;AAED,QAAOC,+DAAkB,MAAM;EAC7B,GAAG;EACH;EACD,CAAC;;AAYJ,MAAa,gCACX,YACA,WACG;CACH,MAAM,eAAe,MAAM,QAAQ,OAAO,GAAG,SAAS,CAAC,OAAO;AAE9D,QAAO;EACL,GAAG;EACH,SAAS,0BAA0B,WAAW,SAAS,cAAc;GACnE,eAAe,WAAW;GAC1B,SAAS,EAAE;GACZ,CAAC;EACH"}
1
+ {"version":3,"file":"getFilteredLocalesContent.cjs","names":["NodeType","deepTransformNode"],"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":"gNAYA,MAAM,EAA4B,IAAuC,CACvE,GAAI,6BACJ,UAAY,GACV,OAAO,GAAS,UAAY,GAAM,WAAaA,EAAAA,SAAS,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,KAAMA,EAAAA,SAAS,OAAQ,IAAKA,EAAAA,SAAS,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,OAAOC,EAAAA,kBAAkB,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,34 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
3
- const require_interpreter_getContent_plugins = require('../interpreter/getContent/plugins.cjs');
4
-
5
- //#region src/deepTransformPlugins/getLocalizedContent.ts
6
- /**
7
- * Transforms a node in a single pass, applying each plugin as needed.
8
- * In comparison to `getContent`, this function will only apply the translation plugin.
9
- * It will not transform enumerations, insertions, or other content types.
10
- *
11
- * @param node The node to transform.
12
- * @param locale The locale to use if your transformers need it (e.g. for translations).
13
- */
14
- const getLocalizedContent = (node, locale, nodeProps, fallback) => {
15
- const plugins = [require_interpreter_getContent_plugins.translationPlugin(locale, fallback), ...nodeProps.plugins ?? []];
16
- return require_interpreter_getContent_deepTransform.deepTransformNode(node, {
17
- ...nodeProps,
18
- plugins
19
- });
20
- };
21
- const getPerLocaleDictionary = (dictionary, locale, fallback) => ({
22
- ...dictionary,
23
- locale,
24
- content: getLocalizedContent(dictionary.content, locale, {
25
- dictionaryKey: dictionary.key,
26
- keyPath: [],
27
- plugins: []
28
- }, fallback)
29
- });
30
-
31
- //#endregion
32
- exports.getLocalizedContent = getLocalizedContent;
33
- exports.getPerLocaleDictionary = getPerLocaleDictionary;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../interpreter/getContent/deepTransform.cjs`),t=require(`../interpreter/getContent/plugins.cjs`),n=(n,r,i,a)=>{let o=[t.translationPlugin(r,a),...i.plugins??[]];return e.deepTransformNode(n,{...i,plugins:o})},r=(e,t,r)=>({...e,locale:t,content:n(e.content,t,{dictionaryKey:e.key,keyPath:[],plugins:[]},r)});exports.getLocalizedContent=n,exports.getPerLocaleDictionary=r;
34
2
  //# sourceMappingURL=getLocalizedContent.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getLocalizedContent.cjs","names":["translationPlugin","deepTransformNode"],"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":";;;;;;;;;;;;;AAsBA,MAAa,uBAIX,MACA,QACA,WACA,aACG;CACH,MAAM,UAAqB,CACzBA,yDAAkB,QAAQ,SAAS,EACnC,GAAI,UAAU,WAAW,EAAE,CAC5B;AAED,QAAOC,+DAAkB,MAAM;EAC7B,GAAG;EACH;EACD,CAAC;;AAGJ,MAAa,0BAIX,YACA,QACA,cACgB;CAChB,GAAG;CACH;CACA,SAAS,oBACP,WAAW,SACX,QACA;EACE,eAAe,WAAW;EAC1B,SAAS,EAAE;EACX,SAAS,EAAE;EACZ,EACD,SACD;CACF"}
1
+ {"version":3,"file":"getLocalizedContent.cjs","names":["translationPlugin","deepTransformNode"],"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":"qLAsBa,GAIX,EACA,EACA,EACA,IACG,CACH,IAAM,EAAqB,CACzBA,EAAAA,kBAAkB,EAAQ,EAAS,CACnC,GAAI,EAAU,SAAW,EAAE,CAC5B,CAED,OAAOC,EAAAA,kBAAkB,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,28 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_interpreter_getContent_deepTransform = require('../interpreter/getContent/deepTransform.cjs');
3
-
4
- //#region src/deepTransformPlugins/getMaskContent.ts
5
- const passTypedNodePlugin = {
6
- id: "pass-typed-node-plugin",
7
- canHandle: (node) => typeof node === "object" && typeof node?.nodeType === "string",
8
- transform: (node, props, deepTransformNode) => deepTransformNode(node[node.nodeType], props)
9
- };
10
- /** Translation plugin. Replaces node with a locale string if nodeType = Translation. */
11
- const buildMaskPlugin = {
12
- id: "build-mask-plugin",
13
- canHandle: (node) => typeof node === "string" || typeof node === "number",
14
- transform: () => true
15
- };
16
- const getMaskContent = (source) => ({
17
- ...source,
18
- content: require_interpreter_getContent_deepTransform.deepTransformNode(source.content, {
19
- dictionaryKey: source.key,
20
- keyPath: [],
21
- plugins: [passTypedNodePlugin, buildMaskPlugin]
22
- })
23
- });
24
-
25
- //#endregion
26
- exports.buildMaskPlugin = buildMaskPlugin;
27
- exports.getMaskContent = getMaskContent;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../interpreter/getContent/deepTransform.cjs`),t={id:`pass-typed-node-plugin`,canHandle:e=>typeof e==`object`&&typeof e?.nodeType==`string`,transform:(e,t,n)=>n(e[e.nodeType],t)},n={id:`build-mask-plugin`,canHandle:e=>typeof e==`string`||typeof e==`number`,transform:()=>!0},r=r=>({...r,content:e.deepTransformNode(r.content,{dictionaryKey:r.key,keyPath:[],plugins:[t,n]})});exports.buildMaskPlugin=n,exports.getMaskContent=r;
28
2
  //# sourceMappingURL=getMaskContent.cjs.map