@intlayer/core 8.1.2 → 8.1.3

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 (408) 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/transpiler/translation/translation.d.ts +1 -1
  407. package/dist/types/utils/index.d.ts +8 -0
  408. package/package.json +65 -11
@@ -1,56 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- const require_utils_checkIsURLAbsolute = require('../utils/checkIsURLAbsolute.cjs');
4
- let _intlayer_config_built = require("@intlayer/config/built");
5
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
6
-
7
- //#region src/localization/getPathWithoutLocale.ts
8
- /**
9
- * Removes the locale segment from the given URL or pathname if present.
10
- * Also removes locale from search parameters if present.
11
- *
12
- * This function get the locales from the configuration if not provided.
13
- *
14
- * Example:
15
- *
16
- * ```ts
17
- * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'
18
- * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'
19
- * getPathWithoutLocale('/dashboard') // Returns '/dashboard'
20
- * getPathWithoutLocale('dashboard') // Returns 'dashboard'
21
- * getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'
22
- * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'
23
- * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'
24
- * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'
25
- * getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'
26
- * ```
27
- *
28
- * @param inputUrl - The complete URL string or pathname to process.
29
- * @param locales - Optional array of supported locales. Defaults to `localesDefault`.
30
- * @returns The URL string or pathname without the locale segment or locale search parameter.
31
- */
32
- const getPathWithoutLocale = (inputUrl, locales = _intlayer_config_built.default?.internationalization?.locales) => {
33
- const isAbsoluteUrl = require_utils_checkIsURLAbsolute.checkIsURLAbsolute(inputUrl);
34
- let fixedInputUrl = inputUrl;
35
- if (inputUrl?.endsWith("/")) fixedInputUrl = inputUrl.slice(0, -1);
36
- const url = isAbsoluteUrl ? new URL(fixedInputUrl) : new URL(fixedInputUrl, "http://example.com");
37
- const pathname = url.pathname;
38
- if (!pathname.startsWith("/")) url.pathname = `/${pathname}`;
39
- const pathSegments = pathname.split("/");
40
- const firstSegment = pathSegments[1];
41
- if (locales?.includes(firstSegment)) {
42
- pathSegments.splice(1, 1);
43
- url.pathname = pathSegments.join("/") ?? "/";
44
- }
45
- const searchParams = new URLSearchParams(url.search);
46
- if (searchParams.has("locale")) {
47
- searchParams.delete("locale");
48
- url.search = searchParams.toString();
49
- }
50
- if (isAbsoluteUrl) return url.toString();
51
- return url.toString().replace("http://example.com", "");
52
- };
53
-
54
- //#endregion
55
- exports.getPathWithoutLocale = getPathWithoutLocale;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`),t=require(`../utils/checkIsURLAbsolute.cjs`);let n=require(`@intlayer/config/built`);n=e.__toESM(n);const r=(e,r=n.default?.internationalization?.locales)=>{let i=t.checkIsURLAbsolute(e),a=e;e?.endsWith(`/`)&&(a=e.slice(0,-1));let o=i?new URL(a):new URL(a,`http://example.com`),s=o.pathname;s.startsWith(`/`)||(o.pathname=`/${s}`);let c=s.split(`/`),l=c[1];r?.includes(l)&&(c.splice(1,1),o.pathname=c.join(`/`)??`/`);let u=new URLSearchParams(o.search);return u.has(`locale`)&&(u.delete(`locale`),o.search=u.toString()),i?o.toString():o.toString().replace(`http://example.com`,``)};exports.getPathWithoutLocale=r;
56
2
  //# sourceMappingURL=getPathWithoutLocale.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPathWithoutLocale.cjs","names":["configuration","checkIsURLAbsolute"],"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n * Also removes locale from search parameters if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment or locale search parameter.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales?.includes(firstSegment as LocalesValues)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n // Remove locale from search parameters if present\n const searchParams = new URLSearchParams(url.search);\n if (searchParams.has('locale')) {\n searchParams.delete('locale');\n url.search = searchParams.toString();\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,MAAa,wBACX,UACA,UAA2BA,gCAAe,sBAAsB,YACrD;CAEX,MAAM,gBAAgBC,oDAAmB,SAAS;CAElD,IAAI,gBAAgB;AAEpB,KAAI,UAAU,SAAS,IAAI,CACzB,iBAAgB,SAAS,MAAM,GAAG,GAAG;CAKvC,MAAM,MAAM,gBACR,IAAI,IAAI,cAAc,GACtB,IAAI,IAAI,eAAe,qBAAqB;CAEhD,MAAM,WAAW,IAAI;AAGrB,KAAI,CAAC,SAAS,WAAW,IAAI,CAE3B,KAAI,WAAW,IAAI;CAIrB,MAAM,eAAe,SAAS,MAAM,IAAI;CACxC,MAAM,eAAe,aAAa;AAGlC,KAAI,SAAS,SAAS,aAA8B,EAAE;AAEpD,eAAa,OAAO,GAAG,EAAE;AAIzB,MAAI,WADgB,aAAa,KAAK,IAAI,IAAI;;CAKhD,MAAM,eAAe,IAAI,gBAAgB,IAAI,OAAO;AACpD,KAAI,aAAa,IAAI,SAAS,EAAE;AAC9B,eAAa,OAAO,SAAS;AAC7B,MAAI,SAAS,aAAa,UAAU;;AAGtC,KAAI,cAEF,QAAO,IAAI,UAAU;AAIvB,QAAO,IAAI,UAAU,CAAC,QAAQ,sBAAsB,GAAG"}
1
+ {"version":3,"file":"getPathWithoutLocale.cjs","names":["configuration","checkIsURLAbsolute"],"sources":["../../../src/localization/getPathWithoutLocale.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport type { LocalesValues } from '@intlayer/types';\n\nimport { checkIsURLAbsolute } from '../utils/checkIsURLAbsolute';\n\n/**\n * Removes the locale segment from the given URL or pathname if present.\n * Also removes locale from search parameters if present.\n *\n * This function get the locales from the configuration if not provided.\n *\n * Example:\n *\n * ```ts\n * getPathWithoutLocale('/en/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/fr/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('/dashboard') // Returns '/dashboard'\n * getPathWithoutLocale('dashboard') // Returns 'dashboard'\n * getPathWithoutLocale('/dashboard?locale=fr') // Returns '/dashboard'\n * getPathWithoutLocale('https://example.com/en/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/fr/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard') // Returns 'https://example.com/dashboard'\n * getPathWithoutLocale('https://example.com/dashboard?locale=fr') // Returns 'https://example.com/dashboard'\n * ```\n *\n * @param inputUrl - The complete URL string or pathname to process.\n * @param locales - Optional array of supported locales. Defaults to `localesDefault`.\n * @returns The URL string or pathname without the locale segment or locale search parameter.\n */\nexport const getPathWithoutLocale = (\n inputUrl: string,\n locales: LocalesValues[] = configuration?.internationalization?.locales\n): string => {\n // Determine if the original URL is absolute (includes protocol)\n const isAbsoluteUrl = checkIsURLAbsolute(inputUrl);\n\n let fixedInputUrl = inputUrl;\n\n if (inputUrl?.endsWith('/')) {\n fixedInputUrl = inputUrl.slice(0, -1);\n }\n\n // Initialize a URL object if the URL is absolute\n // For relative URLs, use a dummy base to leverage the URL API\n const url = isAbsoluteUrl\n ? new URL(fixedInputUrl)\n : new URL(fixedInputUrl, 'http://example.com');\n\n const pathname = url.pathname;\n\n // Ensure the pathname starts with '/'\n if (!pathname.startsWith('/')) {\n // If not, return the URL as is\n url.pathname = `/${pathname}`;\n }\n\n // Split the pathname to extract the first segment\n const pathSegments = pathname.split('/');\n const firstSegment = pathSegments[1]; // The segment after the first '/'\n\n // Check if the first segment is a supported locale\n if (locales?.includes(firstSegment as LocalesValues)) {\n // Remove the locale segment from the pathname\n pathSegments.splice(1, 1); // Remove the first segment\n\n // Reconstruct the pathname\n const newPathname = pathSegments.join('/') ?? '/';\n url.pathname = newPathname;\n }\n\n // Remove locale from search parameters if present\n const searchParams = new URLSearchParams(url.search);\n if (searchParams.has('locale')) {\n searchParams.delete('locale');\n url.search = searchParams.toString();\n }\n\n if (isAbsoluteUrl) {\n // Return the modified URL as a string\n return url.toString();\n }\n\n // Return the modified URL as a string\n return url.toString().replace('http://example.com', '');\n};\n"],"mappings":"4NA6BA,MAAa,GACX,EACA,EAA2BA,EAAAA,SAAe,sBAAsB,UACrD,CAEX,IAAM,EAAgBC,EAAAA,mBAAmB,EAAS,CAE9C,EAAgB,EAEhB,GAAU,SAAS,IAAI,GACzB,EAAgB,EAAS,MAAM,EAAG,GAAG,EAKvC,IAAM,EAAM,EACR,IAAI,IAAI,EAAc,CACtB,IAAI,IAAI,EAAe,qBAAqB,CAE1C,EAAW,EAAI,SAGhB,EAAS,WAAW,IAAI,GAE3B,EAAI,SAAW,IAAI,KAIrB,IAAM,EAAe,EAAS,MAAM,IAAI,CAClC,EAAe,EAAa,GAG9B,GAAS,SAAS,EAA8B,GAElD,EAAa,OAAO,EAAG,EAAE,CAIzB,EAAI,SADgB,EAAa,KAAK,IAAI,EAAI,KAKhD,IAAM,EAAe,IAAI,gBAAgB,EAAI,OAAO,CAYpD,OAXI,EAAa,IAAI,SAAS,GAC5B,EAAa,OAAO,SAAS,CAC7B,EAAI,OAAS,EAAa,UAAU,EAGlC,EAEK,EAAI,UAAU,CAIhB,EAAI,UAAU,CAAC,QAAQ,qBAAsB,GAAG"}
@@ -1,64 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_config_client = require("@intlayer/config/client");
4
- let _intlayer_config_built = require("@intlayer/config/built");
5
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
6
-
7
- //#region src/localization/getPrefix.ts
8
- /**
9
- * Determines the URL prefix for a given locale based on the routing mode configuration.
10
- *
11
- * Example:
12
- *
13
- * ```ts
14
- * // prefix-no-default mode with default locale
15
- * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-no-default' })
16
- * // Returns { prefix: '', localePrefix: undefined }
17
- *
18
- * // prefix-no-default mode with non-default locale
19
- * getPrefix('fr', { defaultLocale: 'en', mode: 'prefix-no-default' })
20
- * // Returns { prefix: '/fr', localePrefix: 'fr' }
21
- *
22
- * // prefix-all mode
23
- * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-all' })
24
- * // Returns { prefix: '/en', localePrefix: locale }
25
- *
26
- * // search-params mode
27
- * getPrefix('en', { defaultLocale: 'en', mode: 'search-params' })
28
- * // Returns { prefix: '', localePrefix: undefined }
29
- *
30
- * // no-prefix mode
31
- * getPrefix('en', { defaultLocale: 'en', mode: 'no-prefix' })
32
- * // Returns { prefix: '', localePrefix: undefined }
33
- * ```
34
- *
35
- * @param locale - The locale to check for prefix. If not provided, uses configured default locale.
36
- * @param options - Configuration options
37
- * @param options.defaultLocale - The default locale. Defaults to configured default locale.
38
- * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.
39
- * @returns An object containing pathPrefix, prefix, and localePrefix for the given locale.
40
- */
41
- const getPrefix = (locale, options = {}) => {
42
- const { defaultLocale, mode, locales } = {
43
- defaultLocale: _intlayer_config_built.default?.internationalization?.defaultLocale ?? _intlayer_config_client.DefaultValues.Internationalization.DEFAULT_LOCALE,
44
- mode: _intlayer_config_built.default?.routing?.mode ?? _intlayer_config_client.DefaultValues.Routing.ROUTING_MODE,
45
- locales: _intlayer_config_built.default?.internationalization?.locales ?? _intlayer_config_client.DefaultValues.Internationalization.LOCALES,
46
- ...options
47
- };
48
- if (!locale || !locales.includes(locale)) return {
49
- prefix: "",
50
- localePrefix: void 0
51
- };
52
- if (mode === "prefix-all" || mode === "prefix-no-default" && defaultLocale !== locale) return {
53
- prefix: `${locale}/`,
54
- localePrefix: locale
55
- };
56
- return {
57
- prefix: "",
58
- localePrefix: void 0
59
- };
60
- };
61
-
62
- //#endregion
63
- exports.getPrefix = getPrefix;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/config/client`),n=require(`@intlayer/config/built`);n=e.__toESM(n);const r=(e,r={})=>{let{defaultLocale:i,mode:a,locales:o}={defaultLocale:n.default?.internationalization?.defaultLocale??t.DefaultValues.Internationalization.DEFAULT_LOCALE,mode:n.default?.routing?.mode??t.DefaultValues.Routing.ROUTING_MODE,locales:n.default?.internationalization?.locales??t.DefaultValues.Internationalization.LOCALES,...r};return!e||!o.includes(e)?{prefix:``,localePrefix:void 0}:a===`prefix-all`||a===`prefix-no-default`&&i!==e?{prefix:`${e}/`,localePrefix:e}:{prefix:``,localePrefix:void 0}};exports.getPrefix=r;
64
2
  //# sourceMappingURL=getPrefix.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getPrefix.cjs","names":["configuration","DefaultValues"],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale, LocalesValues, RoutingConfig } from '@intlayer/types';\n\nexport type GetPrefixOptions = {\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n};\n\nexport type GetPrefixResult = {\n /**\n * The complete base URL path with leading and trailing slashes.\n *\n * @example\n * // https://example.com/fr/about -> '/fr'\n * // https://example.com/about -> ''\n */\n prefix: string;\n /**\n * The locale identifier without slashes.\n *\n * @example\n * // https://example.com/fr/about -> 'fr'\n * // https://example.com/about -> undefined\n */\n localePrefix: Locale | undefined;\n};\n\n/**\n * Determines the URL prefix for a given locale based on the routing mode configuration.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode with default locale\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // prefix-no-default mode with non-default locale\n * getPrefix('fr', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '/fr', localePrefix: 'fr' }\n *\n * // prefix-all mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { prefix: '/en', localePrefix: locale }\n *\n * // search-params mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'search-params' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // no-prefix mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { prefix: '', localePrefix: undefined }\n * ```\n *\n * @param locale - The locale to check for prefix. If not provided, uses configured default locale.\n * @param options - Configuration options\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object containing pathPrefix, prefix, and localePrefix for the given locale.\n */\nexport const getPrefix = (\n locale: LocalesValues | undefined,\n options: {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n } = {}\n): GetPrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n if (!locale || !locales.includes(locale)) {\n return {\n prefix: '',\n localePrefix: undefined,\n };\n }\n\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n mode === 'prefix-all' ||\n (mode === 'prefix-no-default' && defaultLocale !== locale);\n\n if (shouldPrefix) {\n return {\n prefix: `${locale}/`,\n localePrefix: locale as Locale,\n };\n }\n\n return {\n prefix: '',\n localePrefix: undefined,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DA,MAAa,aACX,QACA,UAII,EAAE,KACc;CACpB,MAAM,EAAE,eAAe,MAAM,YAAY;EACvC,eACEA,gCAAe,sBAAsB,iBACrCC,sCAAc,qBAAqB;EACrC,MAAMD,gCAAe,SAAS,QAAQC,sCAAc,QAAQ;EAC5D,SACED,gCAAe,sBAAsB,WACrCC,sCAAc,qBAAqB;EACrC,GAAG;EACJ;AAED,KAAI,CAAC,UAAU,CAAC,QAAQ,SAAS,OAAO,CACtC,QAAO;EACL,QAAQ;EACR,cAAc;EACf;AAQH,KAHE,SAAS,gBACR,SAAS,uBAAuB,kBAAkB,OAGnD,QAAO;EACL,QAAQ,GAAG,OAAO;EAClB,cAAc;EACf;AAGH,QAAO;EACL,QAAQ;EACR,cAAc;EACf"}
1
+ {"version":3,"file":"getPrefix.cjs","names":["configuration","DefaultValues"],"sources":["../../../src/localization/getPrefix.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { DefaultValues } from '@intlayer/config/client';\nimport type { Locale, LocalesValues, RoutingConfig } from '@intlayer/types';\n\nexport type GetPrefixOptions = {\n defaultLocale?: LocalesValues;\n mode?: RoutingConfig['mode'];\n};\n\nexport type GetPrefixResult = {\n /**\n * The complete base URL path with leading and trailing slashes.\n *\n * @example\n * // https://example.com/fr/about -> '/fr'\n * // https://example.com/about -> ''\n */\n prefix: string;\n /**\n * The locale identifier without slashes.\n *\n * @example\n * // https://example.com/fr/about -> 'fr'\n * // https://example.com/about -> undefined\n */\n localePrefix: Locale | undefined;\n};\n\n/**\n * Determines the URL prefix for a given locale based on the routing mode configuration.\n *\n * Example:\n *\n * ```ts\n * // prefix-no-default mode with default locale\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // prefix-no-default mode with non-default locale\n * getPrefix('fr', { defaultLocale: 'en', mode: 'prefix-no-default' })\n * // Returns { prefix: '/fr', localePrefix: 'fr' }\n *\n * // prefix-all mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'prefix-all' })\n * // Returns { prefix: '/en', localePrefix: locale }\n *\n * // search-params mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'search-params' })\n * // Returns { prefix: '', localePrefix: undefined }\n *\n * // no-prefix mode\n * getPrefix('en', { defaultLocale: 'en', mode: 'no-prefix' })\n * // Returns { prefix: '', localePrefix: undefined }\n * ```\n *\n * @param locale - The locale to check for prefix. If not provided, uses configured default locale.\n * @param options - Configuration options\n * @param options.defaultLocale - The default locale. Defaults to configured default locale.\n * @param options.mode - URL routing mode for locale handling. Defaults to configured mode.\n * @returns An object containing pathPrefix, prefix, and localePrefix for the given locale.\n */\nexport const getPrefix = (\n locale: LocalesValues | undefined,\n options: {\n defaultLocale?: LocalesValues;\n locales?: LocalesValues[];\n mode?: RoutingConfig['mode'];\n } = {}\n): GetPrefixResult => {\n const { defaultLocale, mode, locales } = {\n defaultLocale:\n configuration?.internationalization?.defaultLocale ??\n DefaultValues.Internationalization.DEFAULT_LOCALE,\n mode: configuration?.routing?.mode ?? DefaultValues.Routing.ROUTING_MODE,\n locales:\n configuration?.internationalization?.locales ??\n DefaultValues.Internationalization.LOCALES,\n ...options,\n };\n\n if (!locale || !locales.includes(locale)) {\n return {\n prefix: '',\n localePrefix: undefined,\n };\n }\n\n // Handle prefix-based modes (prefix-all or prefix-no-default)\n const shouldPrefix =\n mode === 'prefix-all' ||\n (mode === 'prefix-no-default' && defaultLocale !== locale);\n\n if (shouldPrefix) {\n return {\n prefix: `${locale}/`,\n localePrefix: locale as Locale,\n };\n }\n\n return {\n prefix: '',\n localePrefix: undefined,\n };\n};\n"],"mappings":"oNA6DA,MAAa,GACX,EACA,EAII,EAAE,GACc,CACpB,GAAM,CAAE,gBAAe,OAAM,WAAY,CACvC,cACEA,EAAAA,SAAe,sBAAsB,eACrCC,EAAAA,cAAc,qBAAqB,eACrC,KAAMD,EAAAA,SAAe,SAAS,MAAQC,EAAAA,cAAc,QAAQ,aAC5D,QACED,EAAAA,SAAe,sBAAsB,SACrCC,EAAAA,cAAc,qBAAqB,QACrC,GAAG,EACJ,CAqBD,MAnBI,CAAC,GAAU,CAAC,EAAQ,SAAS,EAAO,CAC/B,CACL,OAAQ,GACR,aAAc,IAAA,GACf,CAKD,IAAS,cACR,IAAS,qBAAuB,IAAkB,EAG5C,CACL,OAAQ,GAAG,EAAO,GAClB,aAAc,EACf,CAGI,CACL,OAAQ,GACR,aAAc,IAAA,GACf"}
@@ -1,39 +1 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_localization_localeResolver = require('./localeResolver.cjs');
3
- const require_localization_localeDetector = require('./localeDetector.cjs');
4
- const require_localization_getBrowserLocale = require('./getBrowserLocale.cjs');
5
- const require_localization_getHTMLTextDir = require('./getHTMLTextDir.cjs');
6
- const require_localization_getLocale = require('./getLocale.cjs');
7
- const require_localization_getLocaleFromPath = require('./getLocaleFromPath.cjs');
8
- const require_localization_getLocaleLang = require('./getLocaleLang.cjs');
9
- const require_localization_getLocaleName = require('./getLocaleName.cjs');
10
- const require_localization_getPathWithoutLocale = require('./getPathWithoutLocale.cjs');
11
- const require_localization_getPrefix = require('./getPrefix.cjs');
12
- const require_localization_rewriteUtils = require('./rewriteUtils.cjs');
13
- const require_localization_getLocalizedUrl = require('./getLocalizedUrl.cjs');
14
- const require_localization_getMultilingualUrls = require('./getMultilingualUrls.cjs');
15
- const require_localization_localeMapper = require('./localeMapper.cjs');
16
- const require_localization_validatePrefix = require('./validatePrefix.cjs');
17
-
18
- exports.getBrowserLocale = require_localization_getBrowserLocale.getBrowserLocale;
19
- exports.getCanonicalPath = require_localization_rewriteUtils.getCanonicalPath;
20
- exports.getHTMLTextDir = require_localization_getHTMLTextDir.getHTMLTextDir;
21
- exports.getInternalPath = require_localization_rewriteUtils.getInternalPath;
22
- exports.getLocale = require_localization_getLocale.getLocale;
23
- exports.getLocaleFromPath = require_localization_getLocaleFromPath.getLocaleFromPath;
24
- exports.getLocaleLang = require_localization_getLocaleLang.getLocaleLang;
25
- exports.getLocaleName = require_localization_getLocaleName.getLocaleName;
26
- exports.getLocalizedPath = require_localization_rewriteUtils.getLocalizedPath;
27
- exports.getLocalizedUrl = require_localization_getLocalizedUrl.getLocalizedUrl;
28
- exports.getMultilingualUrls = require_localization_getMultilingualUrls.getMultilingualUrls;
29
- exports.getPathWithoutLocale = require_localization_getPathWithoutLocale.getPathWithoutLocale;
30
- exports.getPrefix = require_localization_getPrefix.getPrefix;
31
- exports.getRewritePath = require_localization_rewriteUtils.getRewritePath;
32
- exports.getRewriteRules = require_localization_rewriteUtils.getRewriteRules;
33
- exports.localeDetector = require_localization_localeDetector.localeDetector;
34
- exports.localeFlatMap = require_localization_localeMapper.localeFlatMap;
35
- exports.localeMap = require_localization_localeMapper.localeMap;
36
- exports.localeRecord = require_localization_localeMapper.localeRecord;
37
- exports.localeResolver = require_localization_localeResolver.localeResolver;
38
- exports.localeStorageOptions = require_localization_getBrowserLocale.localeStorageOptions;
39
- exports.validatePrefix = require_localization_validatePrefix.validatePrefix;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../getStorageAttributes.cjs`),t=require(`./localeResolver.cjs`),n=require(`./localeDetector.cjs`),r=require(`./getBrowserLocale.cjs`),i=require(`./getHTMLTextDir.cjs`),a=require(`./getLocale.cjs`),o=require(`./getLocaleFromPath.cjs`),s=require(`./getLocaleLang.cjs`),c=require(`./getLocaleName.cjs`),l=require(`./getPathWithoutLocale.cjs`),u=require(`./getPrefix.cjs`),d=require(`./rewriteUtils.cjs`),f=require(`./getLocalizedUrl.cjs`),p=require(`./getMultilingualUrls.cjs`),m=require(`./localeMapper.cjs`),h=require(`./validatePrefix.cjs`);exports.getBrowserLocale=r.getBrowserLocale,exports.getCanonicalPath=d.getCanonicalPath,exports.getHTMLTextDir=i.getHTMLTextDir,exports.getInternalPath=d.getInternalPath,exports.getLocale=a.getLocale,exports.getLocaleFromPath=o.getLocaleFromPath,exports.getLocaleLang=s.getLocaleLang,exports.getLocaleName=c.getLocaleName,exports.getLocalizedPath=d.getLocalizedPath,exports.getLocalizedUrl=f.getLocalizedUrl,exports.getMultilingualUrls=p.getMultilingualUrls,exports.getPathWithoutLocale=l.getPathWithoutLocale,exports.getPrefix=u.getPrefix,exports.getRewritePath=d.getRewritePath,exports.getRewriteRules=d.getRewriteRules,exports.getStorageAttributes=e.getStorageAttributes,exports.localeDetector=n.localeDetector,exports.localeFlatMap=m.localeFlatMap,exports.localeMap=m.localeMap,exports.localeRecord=m.localeRecord,exports.localeResolver=t.localeResolver,exports.localeStorageOptions=r.localeStorageOptions,exports.validatePrefix=h.validatePrefix;
@@ -1,134 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_localization_localeResolver = require('./localeResolver.cjs');
3
-
4
- //#region src/localization/localeDetector.ts
5
- /**
6
- * Constants
7
- */
8
- const LANGUAGE_FORMAT_REGULAR_EXPRESSION = /^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;
9
- const DEFAULT_QUALITY_SCORE = 1;
10
- /**
11
- * Enumeration for specificity weights.
12
- * Higher values indicate a more precise match.
13
- */
14
- var SpecificityWeight = /* @__PURE__ */ function(SpecificityWeight) {
15
- SpecificityWeight[SpecificityWeight["None"] = 0] = "None";
16
- SpecificityWeight[SpecificityWeight["Broad"] = 1] = "Broad";
17
- SpecificityWeight[SpecificityWeight["Prefix"] = 2] = "Prefix";
18
- SpecificityWeight[SpecificityWeight["Exact"] = 4] = "Exact";
19
- return SpecificityWeight;
20
- }(SpecificityWeight || {});
21
- /**
22
- * Parses a single language tag string from the Accept-Language header.
23
- * Example input: "en-US;q=0.8"
24
- */
25
- const parseLanguageTag = (tagString, index) => {
26
- const match = LANGUAGE_FORMAT_REGULAR_EXPRESSION.exec(tagString);
27
- if (!match) return null;
28
- const languageCode = match[1];
29
- const regionCode = match[2];
30
- const parameters = match[3];
31
- const fullLocale = regionCode ? `${languageCode}-${regionCode}` : languageCode;
32
- let qualityScore = DEFAULT_QUALITY_SCORE;
33
- if (parameters) {
34
- const parameterList = parameters.split(";");
35
- for (const parameter of parameterList) {
36
- const [key, value] = parameter.split("=");
37
- if (key === "q") qualityScore = parseFloat(value);
38
- }
39
- }
40
- return {
41
- languageCode,
42
- regionCode,
43
- qualityScore,
44
- originalIndex: index,
45
- fullLocale
46
- };
47
- };
48
- /**
49
- * Parses the entire Accept-Language header string into a list of preferences.
50
- */
51
- const parseAcceptLanguageHeader = (headerValue) => {
52
- const rawTags = headerValue.split(",");
53
- const preferences = [];
54
- for (let index = 0; index < rawTags.length; index++) {
55
- const parsedLanguage = parseLanguageTag(rawTags[index].trim(), index);
56
- if (parsedLanguage) preferences.push(parsedLanguage);
57
- }
58
- return preferences;
59
- };
60
- /**
61
- * Calculates the specificity of a match between a provided language and a requested preference.
62
- */
63
- const calculateMatchSpecificity = (providedLanguage, preference, providedIndex) => {
64
- const parsedProvided = parseLanguageTag(providedLanguage, providedIndex);
65
- if (!parsedProvided) return null;
66
- let specificityScore = SpecificityWeight.None;
67
- const preferenceFullLower = preference.fullLocale.toLowerCase();
68
- const preferencePrefixLower = preference.languageCode.toLowerCase();
69
- const providedFullLower = parsedProvided.fullLocale.toLowerCase();
70
- const providedPrefixLower = parsedProvided.languageCode.toLowerCase();
71
- if (preferenceFullLower === providedFullLower) specificityScore |= SpecificityWeight.Exact;
72
- else if (preferencePrefixLower === providedFullLower) specificityScore |= SpecificityWeight.Prefix;
73
- else if (preferenceFullLower === providedPrefixLower) specificityScore |= SpecificityWeight.Broad;
74
- else if (preference.fullLocale !== "*") return null;
75
- return {
76
- providedIndex,
77
- headerIndex: preference.originalIndex,
78
- qualityScore: preference.qualityScore,
79
- specificityScore
80
- };
81
- };
82
- /**
83
- * Determines the best match for a specific available language against the list of user accepted languages.
84
- */
85
- const getBestMatchForLanguage = (providedLanguage, acceptedPreferences, providedIndex) => {
86
- let bestMatch = {
87
- headerIndex: -1,
88
- qualityScore: 0,
89
- specificityScore: 0,
90
- providedIndex
91
- };
92
- for (const preference of acceptedPreferences) {
93
- const matchSpec = calculateMatchSpecificity(providedLanguage, preference, providedIndex);
94
- if (matchSpec) {
95
- if ((bestMatch.specificityScore - matchSpec.specificityScore || bestMatch.qualityScore - matchSpec.qualityScore || bestMatch.headerIndex - matchSpec.headerIndex) < 0) bestMatch = matchSpec;
96
- }
97
- }
98
- return bestMatch;
99
- };
100
- /**
101
- * Comparator function to sort language matches.
102
- * Sorting order:
103
- * 1. Quality Score (Descending)
104
- * 2. Specificity Score (Descending)
105
- * 3. Order in Header (Ascending - lower index is better)
106
- * 4. Order in Provided List (Ascending)
107
- */
108
- const compareMatchResults = (a, b) => {
109
- return b.qualityScore - a.qualityScore || b.specificityScore - a.specificityScore || a.headerIndex - b.headerIndex || a.providedIndex - b.providedIndex || 0;
110
- };
111
- /**
112
- * Derives the list of preferred languages based on the Accept-Language header
113
- * and an optional list of available languages.
114
- */
115
- const getPreferredLanguages = (acceptHeader, availableLanguages) => {
116
- const acceptedPreferences = parseAcceptLanguageHeader(acceptHeader === void 0 ? "*" : acceptHeader || "");
117
- if (!availableLanguages) return acceptedPreferences.filter((preference) => preference.qualityScore > 0).sort((a, b) => b.qualityScore - a.qualityScore).map((preference) => preference.fullLocale);
118
- return availableLanguages.map((language, index) => getBestMatchForLanguage(language, acceptedPreferences, index)).filter((result) => result.qualityScore > 0).sort(compareMatchResults).map((result) => availableLanguages[result.providedIndex]);
119
- };
120
- /**
121
- * Detects the locale from the request headers.
122
- *
123
- * Headers are provided by the browser/client and can be used to determine the user's preferred language.
124
- * This function intersects the user's `Accept-Language` header with the application's available locales.
125
- */
126
- const localeDetector = (headers, availableLocales, defaultLocale) => {
127
- const acceptLanguageHeader = headers["accept-language"];
128
- return require_localization_localeResolver.localeResolver(getPreferredLanguages(acceptLanguageHeader, availableLocales), availableLocales, defaultLocale);
129
- };
130
-
131
- //#endregion
132
- exports.getPreferredLanguages = getPreferredLanguages;
133
- exports.localeDetector = localeDetector;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`./localeResolver.cjs`),t=/^\s*([^\s\-;]+)(?:-([^\s;]+))?\s*(?:;(.*))?$/;var n=function(e){return e[e.None=0]=`None`,e[e.Broad=1]=`Broad`,e[e.Prefix=2]=`Prefix`,e[e.Exact=4]=`Exact`,e}(n||{});const r=(e,n)=>{let r=t.exec(e);if(!r)return null;let i=r[1],a=r[2],o=r[3],s=a?`${i}-${a}`:i,c=1;if(o){let e=o.split(`;`);for(let t of e){let[e,n]=t.split(`=`);e===`q`&&(c=parseFloat(n))}}return{languageCode:i,regionCode:a,qualityScore:c,originalIndex:n,fullLocale:s}},i=e=>{let t=e.split(`,`),n=[];for(let e=0;e<t.length;e++){let i=r(t[e].trim(),e);i&&n.push(i)}return n},a=(e,t,i)=>{let a=r(e,i);if(!a)return null;let o=n.None,s=t.fullLocale.toLowerCase(),c=t.languageCode.toLowerCase(),l=a.fullLocale.toLowerCase(),u=a.languageCode.toLowerCase();if(s===l)o|=n.Exact;else if(c===l)o|=n.Prefix;else if(s===u)o|=n.Broad;else if(t.fullLocale!==`*`)return null;return{providedIndex:i,headerIndex:t.originalIndex,qualityScore:t.qualityScore,specificityScore:o}},o=(e,t,n)=>{let r={headerIndex:-1,qualityScore:0,specificityScore:0,providedIndex:n};for(let i of t){let t=a(e,i,n);t&&(r.specificityScore-t.specificityScore||r.qualityScore-t.qualityScore||r.headerIndex-t.headerIndex)<0&&(r=t)}return r},s=(e,t)=>t.qualityScore-e.qualityScore||t.specificityScore-e.specificityScore||e.headerIndex-t.headerIndex||e.providedIndex-t.providedIndex||0,c=(e,t)=>{let n=i(e===void 0?`*`:e||``);return t?t.map((e,t)=>o(e,n,t)).filter(e=>e.qualityScore>0).sort(s).map(e=>t[e.providedIndex]):n.filter(e=>e.qualityScore>0).sort((e,t)=>t.qualityScore-e.qualityScore).map(e=>e.fullLocale)},l=(t,n,r)=>{let i=t[`accept-language`];return e.localeResolver(c(i,n),n,r)};exports.getPreferredLanguages=c,exports.localeDetector=l;
134
2
  //# sourceMappingURL=localeDetector.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"localeDetector.cjs","names":["localeResolver"],"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Constants\n */\nconst LANGUAGE_FORMAT_REGULAR_EXPRESSION =\n /^\\s*([^\\s\\-;]+)(?:-([^\\s;]+))?\\s*(?:;(.*))?$/;\nconst DEFAULT_QUALITY_SCORE = 1;\n\n/**\n * Enumeration for specificity weights.\n * Higher values indicate a more precise match.\n */\nenum SpecificityWeight {\n None = 0,\n Broad = 1, // Matches prefix (e.g., 'en' matches 'en-US')\n Prefix = 2, // Matches prefix in reverse (e.g., 'en-US' matches 'en')\n Exact = 4, // Matches exact string (e.g., 'en-US' matches 'en-US')\n}\n\n/**\n * Represents a parsed language tag from the header.\n */\ntype LanguagePreference = {\n languageCode: string;\n regionCode?: string;\n fullLocale: string;\n qualityScore: number;\n originalIndex: number;\n};\n\n/**\n * Represents the result of matching a requested language against an available language.\n */\ntype MatchResult = {\n providedIndex: number;\n headerIndex: number;\n qualityScore: number;\n specificityScore: number;\n};\n\n/**\n * Parses a single language tag string from the Accept-Language header.\n * Example input: \"en-US;q=0.8\"\n */\nconst parseLanguageTag = (\n tagString: string,\n index: number\n): LanguagePreference | null => {\n const match = LANGUAGE_FORMAT_REGULAR_EXPRESSION.exec(tagString);\n if (!match) {\n return null;\n }\n\n const languageCode = match[1];\n const regionCode = match[2];\n const parameters = match[3];\n\n // Construct the full locale string (e.g., \"en-US\" or \"en\")\n const fullLocale = regionCode\n ? `${languageCode}-${regionCode}`\n : languageCode;\n\n let qualityScore = DEFAULT_QUALITY_SCORE;\n\n // Parse parameters to find the quality score (\"q\")\n if (parameters) {\n const parameterList = parameters.split(';');\n for (const parameter of parameterList) {\n const [key, value] = parameter.split('=');\n if (key === 'q') {\n qualityScore = parseFloat(value);\n }\n }\n }\n\n return {\n languageCode,\n regionCode,\n qualityScore,\n originalIndex: index,\n fullLocale,\n };\n};\n\n/**\n * Parses the entire Accept-Language header string into a list of preferences.\n */\nconst parseAcceptLanguageHeader = (\n headerValue: string\n): LanguagePreference[] => {\n const rawTags = headerValue.split(',');\n const preferences: LanguagePreference[] = [];\n\n for (let index = 0; index < rawTags.length; index++) {\n const tag = rawTags[index].trim();\n const parsedLanguage = parseLanguageTag(tag, index);\n\n if (parsedLanguage) {\n preferences.push(parsedLanguage);\n }\n }\n\n return preferences;\n};\n\n/**\n * Calculates the specificity of a match between a provided language and a requested preference.\n */\nconst calculateMatchSpecificity = (\n providedLanguage: string,\n preference: LanguagePreference,\n providedIndex: number\n): MatchResult | null => {\n const parsedProvided = parseLanguageTag(providedLanguage, providedIndex);\n if (!parsedProvided) {\n return null;\n }\n\n let specificityScore = SpecificityWeight.None;\n\n const preferenceFullLower = preference.fullLocale.toLowerCase();\n const preferencePrefixLower = preference.languageCode.toLowerCase();\n const providedFullLower = parsedProvided.fullLocale.toLowerCase();\n const providedPrefixLower = parsedProvided.languageCode.toLowerCase();\n\n if (preferenceFullLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Exact;\n } else if (preferencePrefixLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Prefix;\n } else if (preferenceFullLower === providedPrefixLower) {\n specificityScore |= SpecificityWeight.Broad;\n } else if (preference.fullLocale !== '*') {\n return null;\n }\n\n return {\n providedIndex,\n headerIndex: preference.originalIndex,\n qualityScore: preference.qualityScore,\n specificityScore,\n };\n};\n\n/**\n * Determines the best match for a specific available language against the list of user accepted languages.\n */\nconst getBestMatchForLanguage = (\n providedLanguage: string,\n acceptedPreferences: LanguagePreference[],\n providedIndex: number\n): MatchResult => {\n // Initialize with a non-match priority\n let bestMatch: MatchResult = {\n headerIndex: -1,\n qualityScore: 0,\n specificityScore: 0,\n providedIndex,\n };\n\n for (const preference of acceptedPreferences) {\n const matchSpec = calculateMatchSpecificity(\n providedLanguage,\n preference,\n providedIndex\n );\n\n if (matchSpec) {\n // Compare current best match with new match\n const scoreDifference =\n bestMatch.specificityScore - matchSpec.specificityScore ||\n bestMatch.qualityScore - matchSpec.qualityScore ||\n bestMatch.headerIndex - matchSpec.headerIndex;\n\n // If the new match is better (difference < 0), update priority\n if (scoreDifference < 0) {\n bestMatch = matchSpec;\n }\n }\n }\n\n return bestMatch;\n};\n\n/**\n * Comparator function to sort language matches.\n * Sorting order:\n * 1. Quality Score (Descending)\n * 2. Specificity Score (Descending)\n * 3. Order in Header (Ascending - lower index is better)\n * 4. Order in Provided List (Ascending)\n */\nconst compareMatchResults = (a: MatchResult, b: MatchResult): number => {\n return (\n b.qualityScore - a.qualityScore ||\n b.specificityScore - a.specificityScore ||\n a.headerIndex - b.headerIndex ||\n a.providedIndex - b.providedIndex ||\n 0\n );\n};\n\n/**\n * Derives the list of preferred languages based on the Accept-Language header\n * and an optional list of available languages.\n */\nexport const getPreferredLanguages = (\n acceptHeader: string | undefined,\n availableLanguages?: string[]\n): string[] => {\n // RFC 2616 sec 14.4: no header implies '*'\n const headerValue = acceptHeader === undefined ? '*' : acceptHeader || '';\n const acceptedPreferences = parseAcceptLanguageHeader(headerValue);\n\n // If no specific languages are provided to filter against, return the header languages sorted by quality\n if (!availableLanguages) {\n return acceptedPreferences\n .filter((preference) => preference.qualityScore > 0)\n .sort((a, b) => b.qualityScore - a.qualityScore) // Simple sort by quality\n .map((preference) => preference.fullLocale);\n }\n\n // Map available languages to their match priority against the header\n const matchResults = availableLanguages.map((language, index) =>\n getBestMatchForLanguage(language, acceptedPreferences, index)\n );\n\n return matchResults\n .filter((result) => result.qualityScore > 0)\n .sort(compareMatchResults)\n .map((result) => availableLanguages[result.providedIndex]);\n};\n\n/**\n * Detects the locale from the request headers.\n *\n * Headers are provided by the browser/client and can be used to determine the user's preferred language.\n * This function intersects the user's `Accept-Language` header with the application's available locales.\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n availableLocales?: Locale[],\n defaultLocale?: Locale\n): Locale => {\n const acceptLanguageHeader = headers['accept-language'];\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales as string[]\n );\n\n return localeResolver(\n preferredLocaleStrings as Locale[],\n availableLocales,\n defaultLocale\n );\n};\n"],"mappings":";;;;;;;AAMA,MAAM,qCACJ;AACF,MAAM,wBAAwB;;;;;AAM9B,IAAK,gEAAL;AACE;AACA;AACA;AACA;;EAJG;;;;;AAgCL,MAAM,oBACJ,WACA,UAC8B;CAC9B,MAAM,QAAQ,mCAAmC,KAAK,UAAU;AAChE,KAAI,CAAC,MACH,QAAO;CAGT,MAAM,eAAe,MAAM;CAC3B,MAAM,aAAa,MAAM;CACzB,MAAM,aAAa,MAAM;CAGzB,MAAM,aAAa,aACf,GAAG,aAAa,GAAG,eACnB;CAEJ,IAAI,eAAe;AAGnB,KAAI,YAAY;EACd,MAAM,gBAAgB,WAAW,MAAM,IAAI;AAC3C,OAAK,MAAM,aAAa,eAAe;GACrC,MAAM,CAAC,KAAK,SAAS,UAAU,MAAM,IAAI;AACzC,OAAI,QAAQ,IACV,gBAAe,WAAW,MAAM;;;AAKtC,QAAO;EACL;EACA;EACA;EACA,eAAe;EACf;EACD;;;;;AAMH,MAAM,6BACJ,gBACyB;CACzB,MAAM,UAAU,YAAY,MAAM,IAAI;CACtC,MAAM,cAAoC,EAAE;AAE5C,MAAK,IAAI,QAAQ,GAAG,QAAQ,QAAQ,QAAQ,SAAS;EAEnD,MAAM,iBAAiB,iBADX,QAAQ,OAAO,MAAM,EACY,MAAM;AAEnD,MAAI,eACF,aAAY,KAAK,eAAe;;AAIpC,QAAO;;;;;AAMT,MAAM,6BACJ,kBACA,YACA,kBACuB;CACvB,MAAM,iBAAiB,iBAAiB,kBAAkB,cAAc;AACxE,KAAI,CAAC,eACH,QAAO;CAGT,IAAI,mBAAmB,kBAAkB;CAEzC,MAAM,sBAAsB,WAAW,WAAW,aAAa;CAC/D,MAAM,wBAAwB,WAAW,aAAa,aAAa;CACnE,MAAM,oBAAoB,eAAe,WAAW,aAAa;CACjE,MAAM,sBAAsB,eAAe,aAAa,aAAa;AAErE,KAAI,wBAAwB,kBAC1B,qBAAoB,kBAAkB;UAC7B,0BAA0B,kBACnC,qBAAoB,kBAAkB;UAC7B,wBAAwB,oBACjC,qBAAoB,kBAAkB;UAC7B,WAAW,eAAe,IACnC,QAAO;AAGT,QAAO;EACL;EACA,aAAa,WAAW;EACxB,cAAc,WAAW;EACzB;EACD;;;;;AAMH,MAAM,2BACJ,kBACA,qBACA,kBACgB;CAEhB,IAAI,YAAyB;EAC3B,aAAa;EACb,cAAc;EACd,kBAAkB;EAClB;EACD;AAED,MAAK,MAAM,cAAc,qBAAqB;EAC5C,MAAM,YAAY,0BAChB,kBACA,YACA,cACD;AAED,MAAI,WAQF;QALE,UAAU,mBAAmB,UAAU,oBACvC,UAAU,eAAe,UAAU,gBACnC,UAAU,cAAc,UAAU,eAGd,EACpB,aAAY;;;AAKlB,QAAO;;;;;;;;;;AAWT,MAAM,uBAAuB,GAAgB,MAA2B;AACtE,QACE,EAAE,eAAe,EAAE,gBACnB,EAAE,mBAAmB,EAAE,oBACvB,EAAE,cAAc,EAAE,eAClB,EAAE,gBAAgB,EAAE,iBACpB;;;;;;AAQJ,MAAa,yBACX,cACA,uBACa;CAGb,MAAM,sBAAsB,0BADR,iBAAiB,SAAY,MAAM,gBAAgB,GACL;AAGlE,KAAI,CAAC,mBACH,QAAO,oBACJ,QAAQ,eAAe,WAAW,eAAe,EAAE,CACnD,MAAM,GAAG,MAAM,EAAE,eAAe,EAAE,aAAa,CAC/C,KAAK,eAAe,WAAW,WAAW;AAQ/C,QAJqB,mBAAmB,KAAK,UAAU,UACrD,wBAAwB,UAAU,qBAAqB,MAAM,CAC9D,CAGE,QAAQ,WAAW,OAAO,eAAe,EAAE,CAC3C,KAAK,oBAAoB,CACzB,KAAK,WAAW,mBAAmB,OAAO,eAAe;;;;;;;;AAS9D,MAAa,kBACX,SACA,kBACA,kBACW;CACX,MAAM,uBAAuB,QAAQ;AAOrC,QAAOA,mDALwB,sBAC7B,sBACA,iBACD,EAIC,kBACA,cACD"}
1
+ {"version":3,"file":"localeDetector.cjs","names":["localeResolver"],"sources":["../../../src/localization/localeDetector.ts"],"sourcesContent":["import type { Locale } from '@intlayer/types';\nimport { localeResolver } from './localeResolver';\n\n/**\n * Constants\n */\nconst LANGUAGE_FORMAT_REGULAR_EXPRESSION =\n /^\\s*([^\\s\\-;]+)(?:-([^\\s;]+))?\\s*(?:;(.*))?$/;\nconst DEFAULT_QUALITY_SCORE = 1;\n\n/**\n * Enumeration for specificity weights.\n * Higher values indicate a more precise match.\n */\nenum SpecificityWeight {\n None = 0,\n Broad = 1, // Matches prefix (e.g., 'en' matches 'en-US')\n Prefix = 2, // Matches prefix in reverse (e.g., 'en-US' matches 'en')\n Exact = 4, // Matches exact string (e.g., 'en-US' matches 'en-US')\n}\n\n/**\n * Represents a parsed language tag from the header.\n */\ntype LanguagePreference = {\n languageCode: string;\n regionCode?: string;\n fullLocale: string;\n qualityScore: number;\n originalIndex: number;\n};\n\n/**\n * Represents the result of matching a requested language against an available language.\n */\ntype MatchResult = {\n providedIndex: number;\n headerIndex: number;\n qualityScore: number;\n specificityScore: number;\n};\n\n/**\n * Parses a single language tag string from the Accept-Language header.\n * Example input: \"en-US;q=0.8\"\n */\nconst parseLanguageTag = (\n tagString: string,\n index: number\n): LanguagePreference | null => {\n const match = LANGUAGE_FORMAT_REGULAR_EXPRESSION.exec(tagString);\n if (!match) {\n return null;\n }\n\n const languageCode = match[1];\n const regionCode = match[2];\n const parameters = match[3];\n\n // Construct the full locale string (e.g., \"en-US\" or \"en\")\n const fullLocale = regionCode\n ? `${languageCode}-${regionCode}`\n : languageCode;\n\n let qualityScore = DEFAULT_QUALITY_SCORE;\n\n // Parse parameters to find the quality score (\"q\")\n if (parameters) {\n const parameterList = parameters.split(';');\n for (const parameter of parameterList) {\n const [key, value] = parameter.split('=');\n if (key === 'q') {\n qualityScore = parseFloat(value);\n }\n }\n }\n\n return {\n languageCode,\n regionCode,\n qualityScore,\n originalIndex: index,\n fullLocale,\n };\n};\n\n/**\n * Parses the entire Accept-Language header string into a list of preferences.\n */\nconst parseAcceptLanguageHeader = (\n headerValue: string\n): LanguagePreference[] => {\n const rawTags = headerValue.split(',');\n const preferences: LanguagePreference[] = [];\n\n for (let index = 0; index < rawTags.length; index++) {\n const tag = rawTags[index].trim();\n const parsedLanguage = parseLanguageTag(tag, index);\n\n if (parsedLanguage) {\n preferences.push(parsedLanguage);\n }\n }\n\n return preferences;\n};\n\n/**\n * Calculates the specificity of a match between a provided language and a requested preference.\n */\nconst calculateMatchSpecificity = (\n providedLanguage: string,\n preference: LanguagePreference,\n providedIndex: number\n): MatchResult | null => {\n const parsedProvided = parseLanguageTag(providedLanguage, providedIndex);\n if (!parsedProvided) {\n return null;\n }\n\n let specificityScore = SpecificityWeight.None;\n\n const preferenceFullLower = preference.fullLocale.toLowerCase();\n const preferencePrefixLower = preference.languageCode.toLowerCase();\n const providedFullLower = parsedProvided.fullLocale.toLowerCase();\n const providedPrefixLower = parsedProvided.languageCode.toLowerCase();\n\n if (preferenceFullLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Exact;\n } else if (preferencePrefixLower === providedFullLower) {\n specificityScore |= SpecificityWeight.Prefix;\n } else if (preferenceFullLower === providedPrefixLower) {\n specificityScore |= SpecificityWeight.Broad;\n } else if (preference.fullLocale !== '*') {\n return null;\n }\n\n return {\n providedIndex,\n headerIndex: preference.originalIndex,\n qualityScore: preference.qualityScore,\n specificityScore,\n };\n};\n\n/**\n * Determines the best match for a specific available language against the list of user accepted languages.\n */\nconst getBestMatchForLanguage = (\n providedLanguage: string,\n acceptedPreferences: LanguagePreference[],\n providedIndex: number\n): MatchResult => {\n // Initialize with a non-match priority\n let bestMatch: MatchResult = {\n headerIndex: -1,\n qualityScore: 0,\n specificityScore: 0,\n providedIndex,\n };\n\n for (const preference of acceptedPreferences) {\n const matchSpec = calculateMatchSpecificity(\n providedLanguage,\n preference,\n providedIndex\n );\n\n if (matchSpec) {\n // Compare current best match with new match\n const scoreDifference =\n bestMatch.specificityScore - matchSpec.specificityScore ||\n bestMatch.qualityScore - matchSpec.qualityScore ||\n bestMatch.headerIndex - matchSpec.headerIndex;\n\n // If the new match is better (difference < 0), update priority\n if (scoreDifference < 0) {\n bestMatch = matchSpec;\n }\n }\n }\n\n return bestMatch;\n};\n\n/**\n * Comparator function to sort language matches.\n * Sorting order:\n * 1. Quality Score (Descending)\n * 2. Specificity Score (Descending)\n * 3. Order in Header (Ascending - lower index is better)\n * 4. Order in Provided List (Ascending)\n */\nconst compareMatchResults = (a: MatchResult, b: MatchResult): number => {\n return (\n b.qualityScore - a.qualityScore ||\n b.specificityScore - a.specificityScore ||\n a.headerIndex - b.headerIndex ||\n a.providedIndex - b.providedIndex ||\n 0\n );\n};\n\n/**\n * Derives the list of preferred languages based on the Accept-Language header\n * and an optional list of available languages.\n */\nexport const getPreferredLanguages = (\n acceptHeader: string | undefined,\n availableLanguages?: string[]\n): string[] => {\n // RFC 2616 sec 14.4: no header implies '*'\n const headerValue = acceptHeader === undefined ? '*' : acceptHeader || '';\n const acceptedPreferences = parseAcceptLanguageHeader(headerValue);\n\n // If no specific languages are provided to filter against, return the header languages sorted by quality\n if (!availableLanguages) {\n return acceptedPreferences\n .filter((preference) => preference.qualityScore > 0)\n .sort((a, b) => b.qualityScore - a.qualityScore) // Simple sort by quality\n .map((preference) => preference.fullLocale);\n }\n\n // Map available languages to their match priority against the header\n const matchResults = availableLanguages.map((language, index) =>\n getBestMatchForLanguage(language, acceptedPreferences, index)\n );\n\n return matchResults\n .filter((result) => result.qualityScore > 0)\n .sort(compareMatchResults)\n .map((result) => availableLanguages[result.providedIndex]);\n};\n\n/**\n * Detects the locale from the request headers.\n *\n * Headers are provided by the browser/client and can be used to determine the user's preferred language.\n * This function intersects the user's `Accept-Language` header with the application's available locales.\n */\nexport const localeDetector = (\n headers: Record<string, string | undefined>,\n availableLocales?: Locale[],\n defaultLocale?: Locale\n): Locale => {\n const acceptLanguageHeader = headers['accept-language'];\n\n const preferredLocaleStrings = getPreferredLanguages(\n acceptLanguageHeader,\n availableLocales as string[]\n );\n\n return localeResolver(\n preferredLocaleStrings as Locale[],\n availableLocales,\n defaultLocale\n );\n};\n"],"mappings":"2GAMM,EACJ,+CAOF,IAAK,EAAA,SAAA,EAAL,OACE,GAAA,EAAA,KAAA,GAAA,OACA,EAAA,EAAA,MAAA,GAAA,QACA,EAAA,EAAA,OAAA,GAAA,SACA,EAAA,EAAA,MAAA,GAAA,WAJG,GAAA,EAAA,CAAA,CAgCL,MAAM,GACJ,EACA,IAC8B,CAC9B,IAAM,EAAQ,EAAmC,KAAK,EAAU,CAChE,GAAI,CAAC,EACH,OAAO,KAGT,IAAM,EAAe,EAAM,GACrB,EAAa,EAAM,GACnB,EAAa,EAAM,GAGnB,EAAa,EACf,GAAG,EAAa,GAAG,IACnB,EAEA,EAAe,EAGnB,GAAI,EAAY,CACd,IAAM,EAAgB,EAAW,MAAM,IAAI,CAC3C,IAAK,IAAM,KAAa,EAAe,CACrC,GAAM,CAAC,EAAK,GAAS,EAAU,MAAM,IAAI,CACrC,IAAQ,MACV,EAAe,WAAW,EAAM,GAKtC,MAAO,CACL,eACA,aACA,eACA,cAAe,EACf,aACD,EAMG,EACJ,GACyB,CACzB,IAAM,EAAU,EAAY,MAAM,IAAI,CAChC,EAAoC,EAAE,CAE5C,IAAK,IAAI,EAAQ,EAAG,EAAQ,EAAQ,OAAQ,IAAS,CAEnD,IAAM,EAAiB,EADX,EAAQ,GAAO,MAAM,CACY,EAAM,CAE/C,GACF,EAAY,KAAK,EAAe,CAIpC,OAAO,GAMH,GACJ,EACA,EACA,IACuB,CACvB,IAAM,EAAiB,EAAiB,EAAkB,EAAc,CACxE,GAAI,CAAC,EACH,OAAO,KAGT,IAAI,EAAmB,EAAkB,KAEnC,EAAsB,EAAW,WAAW,aAAa,CACzD,EAAwB,EAAW,aAAa,aAAa,CAC7D,EAAoB,EAAe,WAAW,aAAa,CAC3D,EAAsB,EAAe,aAAa,aAAa,CAErE,GAAI,IAAwB,EAC1B,GAAoB,EAAkB,cAC7B,IAA0B,EACnC,GAAoB,EAAkB,eAC7B,IAAwB,EACjC,GAAoB,EAAkB,cAC7B,EAAW,aAAe,IACnC,OAAO,KAGT,MAAO,CACL,gBACA,YAAa,EAAW,cACxB,aAAc,EAAW,aACzB,mBACD,EAMG,GACJ,EACA,EACA,IACgB,CAEhB,IAAI,EAAyB,CAC3B,YAAa,GACb,aAAc,EACd,iBAAkB,EAClB,gBACD,CAED,IAAK,IAAM,KAAc,EAAqB,CAC5C,IAAM,EAAY,EAChB,EACA,EACA,EACD,CAEG,IAGA,EAAU,iBAAmB,EAAU,kBACvC,EAAU,aAAe,EAAU,cACnC,EAAU,YAAc,EAAU,aAGd,IACpB,EAAY,GAKlB,OAAO,GAWH,GAAuB,EAAgB,IAEzC,EAAE,aAAe,EAAE,cACnB,EAAE,iBAAmB,EAAE,kBACvB,EAAE,YAAc,EAAE,aAClB,EAAE,cAAgB,EAAE,eACpB,EAQS,GACX,EACA,IACa,CAGb,IAAM,EAAsB,EADR,IAAiB,IAAA,GAAY,IAAM,GAAgB,GACL,CAelE,OAZK,EAQgB,EAAmB,KAAK,EAAU,IACrD,EAAwB,EAAU,EAAqB,EAAM,CAC9D,CAGE,OAAQ,GAAW,EAAO,aAAe,EAAE,CAC3C,KAAK,EAAoB,CACzB,IAAK,GAAW,EAAmB,EAAO,eAAe,CAdnD,EACJ,OAAQ,GAAe,EAAW,aAAe,EAAE,CACnD,MAAM,EAAG,IAAM,EAAE,aAAe,EAAE,aAAa,CAC/C,IAAK,GAAe,EAAW,WAAW,EAoBpC,GACX,EACA,EACA,IACW,CACX,IAAM,EAAuB,EAAQ,mBAOrC,OAAOA,EAAAA,eALwB,EAC7B,EACA,EACD,CAIC,EACA,EACD"}
@@ -1,120 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_types = require("@intlayer/types");
4
- let _intlayer_config_built = require("@intlayer/config/built");
5
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
6
-
7
- //#region src/localization/localeMapper.ts
8
- /**
9
- * Determine if the locale should be prefixed in the URL based on routing mode
10
- */
11
- const shouldPrefixLocale = (locale, defaultLocale, mode) => {
12
- if (mode === "no-prefix" || mode === "search-params") return false;
13
- if (mode === "prefix-all") return true;
14
- return locale !== defaultLocale;
15
- };
16
- /**
17
- * Map the locale data to an array of objects
18
- *
19
- * @example
20
- * ```ts
21
- * const routes = localeMap((localizedData) =>
22
- * ({
23
- * path: localizedData.urlPrefix,
24
- * name: localizedData.locale,
25
- * isDefault: localizedData.isDefault,
26
- * locales: localizedData.locales,
27
- * defaultLocale: localizedData.defaultLocale,
28
- * }),
29
- * );
30
- *
31
- * // Result
32
- * [
33
- * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },
34
- * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },
35
- * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },
36
- * ]
37
- * ```
38
- *
39
- * @param mapper - The mapper function that returns an object
40
- * @returns An array of objects
41
- */
42
- const localeMap = (mapper, locales = _intlayer_config_built.default?.internationalization.locales ?? [], defaultLocale = _intlayer_config_built.default?.internationalization.defaultLocale ?? _intlayer_types.Locales.ENGLISH, mode = _intlayer_config_built.default?.routing?.mode ?? "prefix-no-default") => (locales ?? []).map((locale) => mapper({
43
- locale,
44
- defaultLocale,
45
- locales,
46
- isDefault: locale === defaultLocale,
47
- urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode) ? `/${locale}` : ""
48
- }));
49
- /**
50
- * Flatten the locale map into a single array of objects
51
- *
52
- * @example
53
- * ```ts
54
- * const routes = localeMap((localizedData) =>
55
- * [{
56
- * path: localizedData.urlPrefix,
57
- * name: localizedData.locale,
58
- * isDefault: localizedData.isDefault,
59
- * locales: localizedData.locales,
60
- * defaultLocale: localizedData.defaultLocale,
61
- * }],
62
- * );
63
- *
64
- * // Result
65
- * [
66
- * path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' ,
67
- * path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' ,
68
- * path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' ,
69
- * ]
70
- * ```
71
- *
72
- * @param mapper - The mapper function that returns an array of objects
73
- * @returns An array of objects
74
- */
75
- const localeFlatMap = (mapper, locales = _intlayer_config_built.default?.internationalization.locales ?? [], defaultLocale = _intlayer_config_built.default?.internationalization.defaultLocale ?? _intlayer_types.Locales.ENGLISH, mode = _intlayer_config_built.default?.routing?.mode ?? "prefix-no-default") => locales.flatMap((locale) => mapper({
76
- locale,
77
- defaultLocale,
78
- locales,
79
- isDefault: locale === defaultLocale,
80
- urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode) ? `/${locale}` : ""
81
- }));
82
- /**
83
- * Creates a record object mapping locales to values transformed by the mapper function
84
- *
85
- * @example
86
- * ```ts
87
- * const translations = localeRecord(({ locale }) =>
88
- * require(`./translations/${locale}.json`)
89
- * );
90
- *
91
- * // Result
92
- *
93
- * en: ... , // Content of translations/en.json
94
- * fr: ... , // Content of translations/fr.json
95
- * es: ...
96
- *
97
- * ```
98
- *
99
- * @param mapper - Function that takes locale data and returns a value for that locale
100
- * @param locales - Array of locale codes to map over (defaults to configured locales)
101
- * @param defaultLocale - The default locale (defaults to configured default)
102
- * @param mode - URL routing mode for locale handling (defaults to configured value)
103
- * @returns Record mapping locale codes to mapped values
104
- */
105
- const localeRecord = (mapper, locales = _intlayer_config_built.default?.internationalization.locales ?? [], defaultLocale = _intlayer_config_built.default?.internationalization.defaultLocale ?? _intlayer_types.Locales.ENGLISH, mode = _intlayer_config_built.default?.routing?.mode ?? "prefix-no-default") => (locales ?? []).reduce((acc, locale) => {
106
- acc[locale] = mapper({
107
- locale,
108
- defaultLocale,
109
- locales,
110
- isDefault: locale === defaultLocale,
111
- urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode) ? `/${locale}` : ""
112
- });
113
- return acc;
114
- }, {});
115
-
116
- //#endregion
117
- exports.localeFlatMap = localeFlatMap;
118
- exports.localeMap = localeMap;
119
- exports.localeRecord = localeRecord;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/types`),n=require(`@intlayer/config/built`);n=e.__toESM(n);const r=(e,t,n)=>n===`no-prefix`||n===`search-params`?!1:n===`prefix-all`?!0:e!==t,i=(e,i=n.default?.internationalization.locales??[],a=n.default?.internationalization.defaultLocale??t.Locales.ENGLISH,o=n.default?.routing?.mode??`prefix-no-default`)=>(i??[]).map(t=>e({locale:t,defaultLocale:a,locales:i,isDefault:t===a,urlPrefix:r(t,a,o)?`/${t}`:``})),a=(e,i=n.default?.internationalization.locales??[],a=n.default?.internationalization.defaultLocale??t.Locales.ENGLISH,o=n.default?.routing?.mode??`prefix-no-default`)=>i.flatMap(t=>e({locale:t,defaultLocale:a,locales:i,isDefault:t===a,urlPrefix:r(t,a,o)?`/${t}`:``})),o=(e,i=n.default?.internationalization.locales??[],a=n.default?.internationalization.defaultLocale??t.Locales.ENGLISH,o=n.default?.routing?.mode??`prefix-no-default`)=>(i??[]).reduce((t,n)=>(t[n]=e({locale:n,defaultLocale:a,locales:i,isDefault:n===a,urlPrefix:r(n,a,o)?`/${n}`:``}),t),{});exports.localeFlatMap=a,exports.localeMap=i,exports.localeRecord=o;
120
2
  //# sourceMappingURL=localeMapper.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"localeMapper.cjs","names":["configuration","Locales"],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locale, Locales, type LocalesValues } from '@intlayer/types';\n\nexport type LocaleData = {\n locale: Locale;\n defaultLocale: Locale;\n isDefault: boolean;\n locales: Locale[];\n urlPrefix: string;\n};\n\n/**\n * Determine if the locale should be prefixed in the URL based on routing mode\n */\nconst shouldPrefixLocale = (\n locale: LocalesValues,\n defaultLocale: LocalesValues,\n mode: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params'\n): boolean => {\n if (mode === 'no-prefix' || mode === 'search-params') {\n return false;\n }\n if (mode === 'prefix-all') {\n return true;\n }\n // 'prefix-no-default'\n return locale !== defaultLocale;\n};\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? Locales.ENGLISH,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n (locales ?? []).map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' ,\n * path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' ,\n * path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' ,\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? Locales.ENGLISH,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Creates a record object mapping locales to values transformed by the mapper function\n *\n * @example\n * ```ts\n * const translations = localeRecord(({ locale }) =>\n * require(`./translations/${locale}.json`)\n * );\n *\n * // Result\n *\n * en: ... , // Content of translations/en.json\n * fr: ... , // Content of translations/fr.json\n * es: ...\n *\n * ```\n *\n * @param mapper - Function that takes locale data and returns a value for that locale\n * @param locales - Array of locale codes to map over (defaults to configured locales)\n * @param defaultLocale - The default locale (defaults to configured default)\n * @param mode - URL routing mode for locale handling (defaults to configured value)\n * @returns Record mapping locale codes to mapped values\n */\nexport const localeRecord = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? Locales.ENGLISH,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): Record<LocalesValues, T> =>\n (locales ?? []).reduce(\n (acc, locale) => {\n acc[locale] = mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData);\n return acc;\n },\n {} as Record<LocalesValues, T>\n );\n"],"mappings":";;;;;;;;;;AAcA,MAAM,sBACJ,QACA,eACA,SACY;AACZ,KAAI,SAAS,eAAe,SAAS,gBACnC,QAAO;AAET,KAAI,SAAS,aACX,QAAO;AAGT,QAAO,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BpB,MAAa,aACX,QACA,UAA2BA,gCAAe,qBAAqB,WAAW,EAAE,EAC5E,gBAA+BA,gCAAe,qBAC3C,iBAAiBC,wBAAQ,SAC5B,OAIsBD,gCAAe,SAAS,QAAQ,yBAErD,WAAW,EAAE,EAAE,KAAK,WACnB,OAAO;CACL;CACA;CACA;CACA,WAAW,WAAW;CACtB,WAAW,mBAAmB,QAAQ,eAAe,KAAK,GACtD,IAAI,WACJ;CACL,CAAe,CACjB;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BH,MAAa,iBACX,QACA,UAA2BA,gCAAe,qBAAqB,WAAW,EAAE,EAC5E,gBAA+BA,gCAAe,qBAC3C,iBAAiBC,wBAAQ,SAC5B,OAIsBD,gCAAe,SAAS,QAAQ,wBAEtD,QAAQ,SAAS,WACf,OAAO;CACL;CACA;CACA;CACA,WAAW,WAAW;CACtB,WAAW,mBAAmB,QAAQ,eAAe,KAAK,GACtD,IAAI,WACJ;CACL,CAAe,CACjB;;;;;;;;;;;;;;;;;;;;;;;;AAyBH,MAAa,gBACX,QACA,UAA2BA,gCAAe,qBAAqB,WAAW,EAAE,EAC5E,gBAA+BA,gCAAe,qBAC3C,iBAAiBC,wBAAQ,SAC5B,OAIsBD,gCAAe,SAAS,QAAQ,yBAErD,WAAW,EAAE,EAAE,QACb,KAAK,WAAW;AACf,KAAI,UAAU,OAAO;EACnB;EACA;EACA;EACA,WAAW,WAAW;EACtB,WAAW,mBAAmB,QAAQ,eAAe,KAAK,GACtD,IAAI,WACJ;EACL,CAAe;AAChB,QAAO;GAET,EAAE,CACH"}
1
+ {"version":3,"file":"localeMapper.cjs","names":["configuration","Locales"],"sources":["../../../src/localization/localeMapper.ts"],"sourcesContent":["import configuration from '@intlayer/config/built';\nimport { type Locale, Locales, type LocalesValues } from '@intlayer/types';\n\nexport type LocaleData = {\n locale: Locale;\n defaultLocale: Locale;\n isDefault: boolean;\n locales: Locale[];\n urlPrefix: string;\n};\n\n/**\n * Determine if the locale should be prefixed in the URL based on routing mode\n */\nconst shouldPrefixLocale = (\n locale: LocalesValues,\n defaultLocale: LocalesValues,\n mode: 'prefix-no-default' | 'prefix-all' | 'no-prefix' | 'search-params'\n): boolean => {\n if (mode === 'no-prefix' || mode === 'search-params') {\n return false;\n }\n if (mode === 'prefix-all') {\n return true;\n }\n // 'prefix-no-default'\n return locale !== defaultLocale;\n};\n\n/**\n * Map the locale data to an array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * ({\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }),\n * );\n *\n * // Result\n * [\n * { path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' },\n * { path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' },\n * { path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' },\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an object\n * @returns An array of objects\n */\nexport const localeMap = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? Locales.ENGLISH,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n (locales ?? []).map((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Flatten the locale map into a single array of objects\n *\n * @example\n * ```ts\n * const routes = localeMap((localizedData) =>\n * [{\n * path: localizedData.urlPrefix,\n * name: localizedData.locale,\n * isDefault: localizedData.isDefault,\n * locales: localizedData.locales,\n * defaultLocale: localizedData.defaultLocale,\n * }],\n * );\n *\n * // Result\n * [\n * path: '/', name: 'en', isDefault: true, locales: ['en'], defaultLocale: 'en', urlPrefix: '' ,\n * path: '/fr', name: 'fr', isDefault: false, locales: ['fr'], defaultLocale: 'en', urlPrefix: '/fr' ,\n * path: '/es', name: 'es', isDefault: false, locales: ['es'], defaultLocale: 'en', urlPrefix: '/es' ,\n * ]\n * ```\n *\n * @param mapper - The mapper function that returns an array of objects\n * @returns An array of objects\n */\nexport const localeFlatMap = <T>(\n mapper: (locale: LocaleData) => T[],\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? Locales.ENGLISH,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): T[] =>\n locales.flatMap((locale) =>\n mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData)\n );\n\n/**\n * Creates a record object mapping locales to values transformed by the mapper function\n *\n * @example\n * ```ts\n * const translations = localeRecord(({ locale }) =>\n * require(`./translations/${locale}.json`)\n * );\n *\n * // Result\n *\n * en: ... , // Content of translations/en.json\n * fr: ... , // Content of translations/fr.json\n * es: ...\n *\n * ```\n *\n * @param mapper - Function that takes locale data and returns a value for that locale\n * @param locales - Array of locale codes to map over (defaults to configured locales)\n * @param defaultLocale - The default locale (defaults to configured default)\n * @param mode - URL routing mode for locale handling (defaults to configured value)\n * @returns Record mapping locale codes to mapped values\n */\nexport const localeRecord = <T>(\n mapper: (locale: LocaleData) => T,\n locales: LocalesValues[] = configuration?.internationalization.locales ?? [],\n defaultLocale: LocalesValues = configuration?.internationalization\n .defaultLocale ?? Locales.ENGLISH,\n mode:\n | 'prefix-no-default'\n | 'prefix-all'\n | 'no-prefix'\n | 'search-params' = configuration?.routing?.mode ?? 'prefix-no-default'\n): Record<LocalesValues, T> =>\n (locales ?? []).reduce(\n (acc, locale) => {\n acc[locale] = mapper({\n locale,\n defaultLocale,\n locales,\n isDefault: locale === defaultLocale,\n urlPrefix: shouldPrefixLocale(locale, defaultLocale, mode)\n ? `/${locale}`\n : '',\n } as LocaleData);\n return acc;\n },\n {} as Record<LocalesValues, T>\n );\n"],"mappings":"4MAcA,MAAM,GACJ,EACA,EACA,IAEI,IAAS,aAAe,IAAS,gBAC5B,GAEL,IAAS,aACJ,GAGF,IAAW,EA6BP,GACX,EACA,EAA2BA,EAAAA,SAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+BA,EAAAA,SAAe,qBAC3C,eAAiBC,EAAAA,QAAQ,QAC5B,EAIsBD,EAAAA,SAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,IAAK,GACnB,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CA4BU,GACX,EACA,EAA2BA,EAAAA,SAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+BA,EAAAA,SAAe,qBAC3C,eAAiBC,EAAAA,QAAQ,QAC5B,EAIsBD,EAAAA,SAAe,SAAS,MAAQ,sBAEtD,EAAQ,QAAS,GACf,EAAO,CACL,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACjB,CAyBU,GACX,EACA,EAA2BA,EAAAA,SAAe,qBAAqB,SAAW,EAAE,CAC5E,EAA+BA,EAAAA,SAAe,qBAC3C,eAAiBC,EAAAA,QAAQ,QAC5B,EAIsBD,EAAAA,SAAe,SAAS,MAAQ,uBAErD,GAAW,EAAE,EAAE,QACb,EAAK,KACJ,EAAI,GAAU,EAAO,CACnB,SACA,gBACA,UACA,UAAW,IAAW,EACtB,UAAW,EAAmB,EAAQ,EAAe,EAAK,CACtD,IAAI,IACJ,GACL,CAAe,CACT,GAET,EAAE,CACH"}
@@ -1,29 +1,2 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_runtime = require('../_virtual/_rolldown/runtime.cjs');
3
- let _intlayer_config_built = require("@intlayer/config/built");
4
- _intlayer_config_built = require_runtime.__toESM(_intlayer_config_built);
5
-
6
- //#region src/localization/localeResolver.ts
7
- /**
8
- * Resolves the most specific locale from a user-provided list,
9
- * or falls back to the default locale if no match is found.
10
- */
11
- const localeResolver = (selectedLocale, locales = _intlayer_config_built.default?.internationalization?.locales, defaultLocale = _intlayer_config_built.default?.internationalization?.defaultLocale) => {
12
- const requestedLocales = [selectedLocale].flat();
13
- const normalize = (locale) => locale.trim().toLowerCase();
14
- try {
15
- for (const requested of requestedLocales) {
16
- const normalizedRequested = normalize(requested);
17
- const exactMatch = locales.find((loc) => normalize(loc) === normalizedRequested);
18
- if (exactMatch) return exactMatch;
19
- const [requestedLang] = normalizedRequested.split("-");
20
- const partialMatch = locales.find((loc) => normalize(loc).split("-")[0] === requestedLang);
21
- if (partialMatch) return partialMatch;
22
- }
23
- } catch (_error) {}
24
- return defaultLocale;
25
- };
26
-
27
- //#endregion
28
- exports.localeResolver = localeResolver;
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require(`../_virtual/_rolldown/runtime.cjs`);let t=require(`@intlayer/config/built`);t=e.__toESM(t);const n=(e,n=t.default?.internationalization?.locales,r=t.default?.internationalization?.defaultLocale)=>{let i=[e].flat(),a=e=>e.trim().toLowerCase();try{for(let e of i){let t=a(e),r=n.find(e=>a(e)===t);if(r)return r;let[i]=t.split(`-`),o=n.find(e=>a(e).split(`-`)[0]===i);if(o)return o}}catch{}return r};exports.localeResolver=n;
29
2
  //# sourceMappingURL=localeResolver.cjs.map