intor 2.5.0 → 2.5.1

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 (294) hide show
  1. package/dist/core/src/client/shared/helpers/get-client-locale.js +5 -20
  2. package/dist/core/src/client/shared/utils/locale/detect-browser-locale.js +2 -8
  3. package/dist/core/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  4. package/dist/core/src/config/constants/cookie.js +9 -9
  5. package/dist/core/src/config/constants/routing.js +13 -14
  6. package/dist/core/src/config/define-intor-config.js +28 -44
  7. package/dist/core/src/config/resolvers/resolve-cookie-options.js +4 -4
  8. package/dist/core/src/config/resolvers/resolve-fallback-locales.js +33 -50
  9. package/dist/core/src/config/resolvers/resolve-routing-options.js +32 -61
  10. package/dist/core/src/config/validators/validate-default-locale.js +8 -13
  11. package/dist/core/src/config/validators/validate-id.js +8 -13
  12. package/dist/core/src/config/validators/validate-supported-locales.js +8 -13
  13. package/dist/core/src/core/constants/locale-placeholder.js +0 -1
  14. package/dist/core/src/core/error/intor-error.js +14 -29
  15. package/dist/core/src/core/locale/canonicalize-locale.js +7 -18
  16. package/dist/core/src/core/locale/match-locale.js +24 -50
  17. package/dist/core/src/core/locale/parse-locale.js +12 -22
  18. package/dist/core/src/core/logger/get-logger.js +26 -31
  19. package/dist/core/src/core/logger/global-logger-pool.js +4 -4
  20. package/dist/core/src/core/messages/internal-metadata.js +1 -1
  21. package/dist/core/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  22. package/dist/core/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  23. package/dist/core/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  24. package/dist/core/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  25. package/dist/core/src/core/messages/merge-messages.js +17 -28
  26. package/dist/core/src/core/messages/utils/is-valid-messages.js +22 -37
  27. package/dist/core/src/core/messages/utils/nest-object-from-path.js +5 -17
  28. package/dist/core/src/core/render/create-html-renderer.js +29 -37
  29. package/dist/core/src/core/render/utils/escape-html.js +1 -6
  30. package/dist/core/src/core/render/utils/render-attributes.js +6 -11
  31. package/dist/core/src/core/translator/create-t-rich.js +6 -15
  32. package/dist/core/src/core/translator/create-translator.js +16 -24
  33. package/dist/core/src/core/utils/deep-merge.js +24 -42
  34. package/dist/core/src/core/utils/normalizers/normalize-cache-key.js +14 -40
  35. package/dist/core/src/core/utils/normalizers/normalize-pathname.js +19 -37
  36. package/dist/core/src/core/utils/normalizers/normalize-query.js +6 -20
  37. package/dist/core/src/core/utils/parse-cookie-header.js +11 -18
  38. package/dist/core/src/core/utils/resolve-loader-options.js +6 -32
  39. package/dist/core/src/edge/helpers/get-translator.js +14 -20
  40. package/dist/core/src/edge/translator/init-translator.js +23 -31
  41. package/dist/core/src/routing/inbound/helpers/resolve-inbound-from-request.js +21 -28
  42. package/dist/core/src/routing/inbound/resolve-inbound.js +22 -37
  43. package/dist/core/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  44. package/dist/core/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  45. package/dist/core/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  46. package/dist/core/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  47. package/dist/core/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  48. package/dist/core/src/routing/locale/get-locale-from-accept-language.js +21 -36
  49. package/dist/core/src/routing/locale/get-locale-from-host.js +5 -28
  50. package/dist/core/src/routing/locale/get-locale-from-pathname.js +11 -37
  51. package/dist/core/src/routing/locale/get-locale-from-query.js +2 -17
  52. package/dist/core/src/routing/pathname/canonicalize-pathname.js +25 -67
  53. package/dist/core/src/routing/pathname/localize-pathname.js +12 -30
  54. package/dist/core/src/routing/pathname/materialize-pathname.js +9 -44
  55. package/dist/core/src/routing/pathname/standardize-pathname.js +6 -30
  56. package/dist/core/src/server/helpers/get-translator.js +26 -23
  57. package/dist/core/src/server/intor/intor.js +20 -25
  58. package/dist/core/src/server/messages/load-local-messages/cache/messages-pool.js +4 -7
  59. package/dist/core/src/server/messages/load-local-messages/load-local-messages.js +76 -92
  60. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +59 -80
  61. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +53 -87
  62. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/utils/json-reader.js +3 -6
  63. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/read-locale-messages.js +23 -35
  64. package/dist/core/src/server/messages/load-messages.js +56 -69
  65. package/dist/core/src/server/translator/init-translator.js +28 -30
  66. package/dist/express/src/adapters/express/create-intor-handler.js +35 -46
  67. package/dist/express/src/adapters/express/get-translator.js +2 -9
  68. package/dist/express/src/core/constants/locale-placeholder.js +0 -1
  69. package/dist/express/src/core/locale/canonicalize-locale.js +7 -18
  70. package/dist/express/src/core/locale/match-locale.js +24 -50
  71. package/dist/express/src/core/locale/parse-locale.js +12 -22
  72. package/dist/express/src/core/utils/normalizers/normalize-pathname.js +19 -37
  73. package/dist/express/src/core/utils/normalizers/normalize-query.js +6 -20
  74. package/dist/express/src/core/utils/parse-cookie-header.js +11 -18
  75. package/dist/express/src/routing/inbound/resolve-inbound.js +22 -37
  76. package/dist/express/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  77. package/dist/express/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  78. package/dist/express/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  79. package/dist/express/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  80. package/dist/express/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  81. package/dist/express/src/routing/locale/get-locale-from-accept-language.js +21 -36
  82. package/dist/express/src/routing/locale/get-locale-from-host.js +5 -28
  83. package/dist/express/src/routing/locale/get-locale-from-pathname.js +11 -37
  84. package/dist/express/src/routing/locale/get-locale-from-query.js +2 -17
  85. package/dist/express/src/routing/pathname/canonicalize-pathname.js +25 -67
  86. package/dist/express/src/routing/pathname/localize-pathname.js +12 -30
  87. package/dist/express/src/routing/pathname/materialize-pathname.js +9 -44
  88. package/dist/express/src/routing/pathname/standardize-pathname.js +6 -30
  89. package/dist/fastify/src/adapters/fastify/create-intor-handler.js +35 -47
  90. package/dist/fastify/src/adapters/fastify/get-translator.js +2 -9
  91. package/dist/fastify/src/adapters/fastify/intor-fastify-plugin.js +29 -38
  92. package/dist/fastify/src/core/constants/locale-placeholder.js +0 -1
  93. package/dist/fastify/src/core/locale/canonicalize-locale.js +7 -18
  94. package/dist/fastify/src/core/locale/match-locale.js +24 -50
  95. package/dist/fastify/src/core/locale/parse-locale.js +12 -22
  96. package/dist/fastify/src/core/utils/normalizers/normalize-pathname.js +19 -37
  97. package/dist/fastify/src/core/utils/normalizers/normalize-query.js +6 -20
  98. package/dist/fastify/src/core/utils/parse-cookie-header.js +11 -18
  99. package/dist/fastify/src/routing/inbound/resolve-inbound.js +22 -37
  100. package/dist/fastify/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  101. package/dist/fastify/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  102. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  103. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  104. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  105. package/dist/fastify/src/routing/locale/get-locale-from-accept-language.js +21 -36
  106. package/dist/fastify/src/routing/locale/get-locale-from-host.js +5 -28
  107. package/dist/fastify/src/routing/locale/get-locale-from-pathname.js +11 -37
  108. package/dist/fastify/src/routing/locale/get-locale-from-query.js +2 -17
  109. package/dist/fastify/src/routing/pathname/canonicalize-pathname.js +25 -67
  110. package/dist/fastify/src/routing/pathname/localize-pathname.js +12 -30
  111. package/dist/fastify/src/routing/pathname/materialize-pathname.js +9 -44
  112. package/dist/fastify/src/routing/pathname/standardize-pathname.js +6 -30
  113. package/dist/hono/src/adapters/hono/create-intor-handler.js +33 -44
  114. package/dist/hono/src/adapters/hono/get-translator.js +2 -9
  115. package/dist/hono/src/core/constants/locale-placeholder.js +0 -1
  116. package/dist/hono/src/core/locale/canonicalize-locale.js +7 -18
  117. package/dist/hono/src/core/locale/match-locale.js +24 -50
  118. package/dist/hono/src/core/locale/parse-locale.js +12 -22
  119. package/dist/hono/src/core/utils/normalizers/normalize-pathname.js +19 -37
  120. package/dist/hono/src/core/utils/normalizers/normalize-query.js +6 -20
  121. package/dist/hono/src/core/utils/parse-cookie-header.js +11 -18
  122. package/dist/hono/src/routing/inbound/resolve-inbound.js +22 -37
  123. package/dist/hono/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  124. package/dist/hono/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  125. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  126. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  127. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  128. package/dist/hono/src/routing/locale/get-locale-from-accept-language.js +21 -36
  129. package/dist/hono/src/routing/locale/get-locale-from-host.js +5 -28
  130. package/dist/hono/src/routing/locale/get-locale-from-pathname.js +11 -37
  131. package/dist/hono/src/routing/locale/get-locale-from-query.js +2 -17
  132. package/dist/hono/src/routing/pathname/canonicalize-pathname.js +25 -67
  133. package/dist/hono/src/routing/pathname/localize-pathname.js +12 -30
  134. package/dist/hono/src/routing/pathname/materialize-pathname.js +9 -44
  135. package/dist/hono/src/routing/pathname/standardize-pathname.js +6 -30
  136. package/dist/next/src/adapters/next/create-intor-handler.js +29 -47
  137. package/dist/next/src/adapters/next/link.js +33 -28
  138. package/dist/next/src/adapters/next/redirect.js +12 -15
  139. package/dist/next/src/adapters/next/server/get-locale.js +12 -23
  140. package/dist/next/src/adapters/next/server/get-translator.js +2 -9
  141. package/dist/next/src/adapters/next/server/intor.js +5 -13
  142. package/dist/next/src/adapters/next/use-router.js +47 -66
  143. package/dist/next/src/client/shared/navigation/execute-navigation.js +20 -38
  144. package/dist/next/src/client/shared/utils/build-cookie-string.js +18 -27
  145. package/dist/next/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  146. package/dist/next/src/core/constants/headers.js +4 -4
  147. package/dist/next/src/core/constants/locale-placeholder.js +0 -1
  148. package/dist/next/src/core/locale/canonicalize-locale.js +7 -18
  149. package/dist/next/src/core/locale/match-locale.js +24 -50
  150. package/dist/next/src/core/locale/parse-locale.js +12 -22
  151. package/dist/next/src/core/utils/normalizers/normalize-pathname.js +19 -37
  152. package/dist/next/src/core/utils/normalizers/normalize-query.js +6 -20
  153. package/dist/next/src/core/utils/resolve-loader-options.js +6 -29
  154. package/dist/next/src/policies/shoud-full-reload.js +2 -5
  155. package/dist/next/src/policies/should-sync-locale.js +1 -4
  156. package/dist/next/src/routing/inbound/resolve-inbound.js +24 -39
  157. package/dist/next/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  158. package/dist/next/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  159. package/dist/next/src/routing/inbound/resolve-pathname/strategies/all.js +13 -29
  160. package/dist/next/src/routing/inbound/resolve-pathname/strategies/except-default.js +14 -30
  161. package/dist/next/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  162. package/dist/next/src/routing/locale/get-locale-from-accept-language.js +21 -36
  163. package/dist/next/src/routing/locale/get-locale-from-host.js +5 -28
  164. package/dist/next/src/routing/locale/get-locale-from-pathname.js +11 -37
  165. package/dist/next/src/routing/locale/get-locale-from-query.js +2 -17
  166. package/dist/next/src/routing/outbound/decide-strategy.js +9 -9
  167. package/dist/next/src/routing/outbound/determine-target.js +28 -44
  168. package/dist/next/src/routing/outbound/resolve-outbound.js +12 -16
  169. package/dist/next/src/routing/outbound/utils/derive-host-destination.js +5 -9
  170. package/dist/next/src/routing/outbound/utils/derive-query-destination.js +4 -7
  171. package/dist/next/src/routing/outbound/utils/is-external-destination.js +1 -7
  172. package/dist/next/src/routing/pathname/canonicalize-pathname.js +25 -67
  173. package/dist/next/src/routing/pathname/localize-pathname.js +12 -30
  174. package/dist/next/src/routing/pathname/materialize-pathname.js +9 -44
  175. package/dist/next/src/routing/pathname/standardize-pathname.js +6 -30
  176. package/dist/react/src/client/react/helpers/use-intor.js +25 -44
  177. package/dist/react/src/client/react/provider/effects/use-locale-effects.js +20 -25
  178. package/dist/react/src/client/react/provider/effects/use-messages-effects.js +17 -16
  179. package/dist/react/src/client/react/provider/intor-provider.js +63 -66
  180. package/dist/react/src/client/react/provider/use-intor-context.js +4 -4
  181. package/dist/react/src/client/react/render/create-react-renderer.js +18 -24
  182. package/dist/react/src/client/react/translator/create-t-rich.js +9 -22
  183. package/dist/react/src/client/react/translator/use-translator.js +11 -16
  184. package/dist/react/src/client/shared/messages/create-refetch-messages.js +41 -51
  185. package/dist/react/src/client/shared/provider/effective-state.js +2 -6
  186. package/dist/react/src/client/shared/utils/build-cookie-string.js +18 -27
  187. package/dist/react/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  188. package/dist/react/src/client/shared/utils/locale/set-document-locale.js +2 -8
  189. package/dist/react/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  190. package/dist/react/src/core/logger/get-logger.js +26 -31
  191. package/dist/react/src/core/logger/global-logger-pool.js +4 -4
  192. package/dist/react/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  193. package/dist/react/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  194. package/dist/react/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  195. package/dist/react/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  196. package/dist/react/src/core/messages/merge-messages.js +17 -28
  197. package/dist/react/src/core/messages/utils/is-valid-messages.js +22 -37
  198. package/dist/react/src/core/messages/utils/nest-object-from-path.js +5 -17
  199. package/dist/react/src/core/utils/deep-merge.js +24 -42
  200. package/dist/react/src/core/utils/resolve-loader-options.js +6 -29
  201. package/dist/react/src/policies/should-persist-on-first-visit.js +1 -4
  202. package/dist/svelte/export/svelte/index.js +0 -6
  203. package/dist/svelte/src/client/shared/messages/create-refetch-messages.js +41 -51
  204. package/dist/svelte/src/client/shared/provider/effective-state.js +2 -6
  205. package/dist/svelte/src/client/shared/utils/build-cookie-string.js +18 -27
  206. package/dist/svelte/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  207. package/dist/svelte/src/client/shared/utils/locale/set-document-locale.js +2 -8
  208. package/dist/svelte/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  209. package/dist/svelte/src/client/svelte/provider/create-intor-store.js +59 -63
  210. package/dist/svelte/src/client/svelte/provider/effects/attach-locale-effects.js +20 -25
  211. package/dist/svelte/src/client/svelte/provider/effects/attach-messages-effects.js +21 -18
  212. package/dist/svelte/src/client/svelte/provider/get-intor-context.js +4 -4
  213. package/dist/svelte/src/client/svelte/translator/use-translator.js +11 -16
  214. package/dist/svelte/src/core/logger/get-logger.js +26 -31
  215. package/dist/svelte/src/core/logger/global-logger-pool.js +4 -4
  216. package/dist/svelte/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  217. package/dist/svelte/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  218. package/dist/svelte/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  219. package/dist/svelte/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  220. package/dist/svelte/src/core/messages/merge-messages.js +17 -28
  221. package/dist/svelte/src/core/messages/utils/is-valid-messages.js +22 -37
  222. package/dist/svelte/src/core/messages/utils/nest-object-from-path.js +5 -17
  223. package/dist/svelte/src/core/render/create-html-renderer.js +29 -37
  224. package/dist/svelte/src/core/render/utils/escape-html.js +1 -6
  225. package/dist/svelte/src/core/render/utils/render-attributes.js +6 -11
  226. package/dist/svelte/src/core/translator/create-t-rich.js +6 -15
  227. package/dist/svelte/src/core/utils/deep-merge.js +24 -42
  228. package/dist/svelte/src/core/utils/resolve-loader-options.js +6 -29
  229. package/dist/svelte/src/policies/should-persist-on-first-visit.js +1 -4
  230. package/dist/svelte-kit/src/adapters/svelte-kit/create-intor-handler.js +37 -57
  231. package/dist/svelte-kit/src/adapters/svelte-kit/use-navigation.js +29 -27
  232. package/dist/svelte-kit/src/adapters/svelte-kit/utils/is-svelte-kit-ssg.js +4 -11
  233. package/dist/svelte-kit/src/client/shared/navigation/execute-navigation.js +19 -37
  234. package/dist/svelte-kit/src/client/shared/utils/build-cookie-string.js +18 -27
  235. package/dist/svelte-kit/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  236. package/dist/svelte-kit/src/core/constants/locale-placeholder.js +0 -1
  237. package/dist/svelte-kit/src/core/locale/canonicalize-locale.js +7 -18
  238. package/dist/svelte-kit/src/core/locale/match-locale.js +24 -50
  239. package/dist/svelte-kit/src/core/locale/parse-locale.js +12 -22
  240. package/dist/svelte-kit/src/core/utils/normalizers/normalize-pathname.js +19 -37
  241. package/dist/svelte-kit/src/core/utils/normalizers/normalize-query.js +6 -20
  242. package/dist/svelte-kit/src/core/utils/resolve-loader-options.js +6 -29
  243. package/dist/svelte-kit/src/policies/shoud-full-reload.js +2 -5
  244. package/dist/svelte-kit/src/policies/should-sync-locale.js +1 -4
  245. package/dist/svelte-kit/src/routing/inbound/resolve-inbound.js +22 -37
  246. package/dist/svelte-kit/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  247. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  248. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  249. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  250. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  251. package/dist/svelte-kit/src/routing/locale/get-locale-from-accept-language.js +21 -36
  252. package/dist/svelte-kit/src/routing/locale/get-locale-from-host.js +5 -28
  253. package/dist/svelte-kit/src/routing/locale/get-locale-from-pathname.js +11 -37
  254. package/dist/svelte-kit/src/routing/locale/get-locale-from-query.js +2 -17
  255. package/dist/svelte-kit/src/routing/outbound/decide-strategy.js +9 -9
  256. package/dist/svelte-kit/src/routing/outbound/determine-target.js +28 -44
  257. package/dist/svelte-kit/src/routing/outbound/resolve-outbound.js +12 -16
  258. package/dist/svelte-kit/src/routing/outbound/utils/derive-host-destination.js +5 -9
  259. package/dist/svelte-kit/src/routing/outbound/utils/derive-query-destination.js +4 -7
  260. package/dist/svelte-kit/src/routing/outbound/utils/is-external-destination.js +1 -7
  261. package/dist/svelte-kit/src/routing/pathname/canonicalize-pathname.js +25 -67
  262. package/dist/svelte-kit/src/routing/pathname/localize-pathname.js +12 -30
  263. package/dist/svelte-kit/src/routing/pathname/materialize-pathname.js +9 -44
  264. package/dist/svelte-kit/src/routing/pathname/standardize-pathname.js +6 -30
  265. package/dist/types/src/routing/outbound/decide-strategy.d.ts +1 -1
  266. package/dist/types/src/routing/outbound/decide-strategy.d.ts.map +1 -1
  267. package/dist/vue/src/client/shared/messages/create-refetch-messages.js +41 -51
  268. package/dist/vue/src/client/shared/provider/effective-state.js +2 -6
  269. package/dist/vue/src/client/shared/utils/build-cookie-string.js +18 -27
  270. package/dist/vue/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  271. package/dist/vue/src/client/shared/utils/locale/set-document-locale.js +2 -8
  272. package/dist/vue/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  273. package/dist/vue/src/client/vue/helpers/use-intor.js +20 -42
  274. package/dist/vue/src/client/vue/provider/effects/use-locale-effects.js +23 -24
  275. package/dist/vue/src/client/vue/provider/effects/use-messages-effects.js +15 -24
  276. package/dist/vue/src/client/vue/provider/inject-intor-context.js +4 -4
  277. package/dist/vue/src/client/vue/provider/intor-provider.js +61 -66
  278. package/dist/vue/src/client/vue/render/create-vue-renderer.js +18 -24
  279. package/dist/vue/src/client/vue/translator/create-t-rich.js +5 -17
  280. package/dist/vue/src/client/vue/translator/trans.js +24 -31
  281. package/dist/vue/src/client/vue/translator/use-translator.js +12 -17
  282. package/dist/vue/src/core/logger/get-logger.js +26 -31
  283. package/dist/vue/src/core/logger/global-logger-pool.js +4 -4
  284. package/dist/vue/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  285. package/dist/vue/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  286. package/dist/vue/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  287. package/dist/vue/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  288. package/dist/vue/src/core/messages/merge-messages.js +17 -28
  289. package/dist/vue/src/core/messages/utils/is-valid-messages.js +22 -37
  290. package/dist/vue/src/core/messages/utils/nest-object-from-path.js +5 -17
  291. package/dist/vue/src/core/utils/deep-merge.js +24 -42
  292. package/dist/vue/src/core/utils/resolve-loader-options.js +6 -29
  293. package/dist/vue/src/policies/should-persist-on-first-visit.js +1 -4
  294. package/package.json +2 -2
@@ -2,37 +2,19 @@ import { canonicalizePathname } from './canonicalize-pathname.js';
2
2
  import { materializePathname } from './materialize-pathname.js';
3
3
  import { standardizePathname } from './standardize-pathname.js';
4
4
 
5
- /**
6
- * Localizes a pathname by composing canonicalization,
7
- * standardization, and locale prefix strategies.
8
- *
9
- * @example
10
- * ```ts
11
- * // config.supportedLocales: ["en-US"]
12
- * // config.routing.basePath: "/app"
13
- * // config.routing.prefix: "all"
14
- * localizePathname("/app/en-US/about", config, "en-US");
15
- * // => {
16
- * // pathname: '/app/en-US/about'
17
- * // canonicalPathname: '/about',
18
- * // templatedPathname: '/app/{locale}/about',
19
- * // }
20
- * ```
21
- *
22
- * @public
23
- */
24
5
  const localizePathname = (rawPathname, config, locale) => {
25
- // 1. Canonicalize: normalize and remove routing-specific prefixes
26
- const canonicalPathname = canonicalizePathname(rawPathname, config);
27
- // 2. Standardize: convert to internal pathname shape with locale placeholder
28
- const standardizedPathname = standardizePathname(canonicalPathname, config);
29
- // 3. Materialize: apply routing rules to produce the final pathname
30
- const materializedPathname = materializePathname(standardizedPathname, config, locale);
31
- return {
32
- canonicalPathname,
33
- templatedPathname: standardizedPathname,
34
- pathname: materializedPathname,
35
- };
6
+ const canonicalPathname = canonicalizePathname(rawPathname, config);
7
+ const standardizedPathname = standardizePathname(canonicalPathname, config);
8
+ const materializedPathname = materializePathname(
9
+ standardizedPathname,
10
+ config,
11
+ locale
12
+ );
13
+ return {
14
+ canonicalPathname,
15
+ templatedPathname: standardizedPathname,
16
+ pathname: materializedPathname
17
+ };
36
18
  };
37
19
 
38
20
  export { localizePathname };
@@ -3,51 +3,16 @@ import 'logry';
3
3
  import 'p-limit';
4
4
  import 'intor-translator';
5
5
 
6
- /**
7
- * Materializes a standardized pathname into a concrete, locale-aware URL.
8
- *
9
- * This function resolves the `{locale}` placeholder according to the
10
- * configured `localePrefix` strategy and produces the final pathname.
11
- *
12
- * Behavior:
13
- * - "all": always injects the locale segment
14
- * - "except-default": injects the locale unless it equals `defaultLocale`
15
- * - "none": removes the locale placeholder entirely
16
- *
17
- * Invariants:
18
- * - `standardizedPathname` must be produced by `standardizePathname`
19
- * - The pathname must contain exactly one `{locale}` placeholder
20
- * - The placeholder must appear as the first path segment
21
- *
22
- * This function performs structural transformation only.
23
- * It does not normalize or sanitize the resulting pathname.
24
- *
25
- * @example
26
- * ```ts
27
- * // config.routing.localePrefix: "all"
28
- * materializePathname("/app/{locale}/about", config, "en");
29
- * // => /app/en/about
30
- *
31
- * // config.routing.localePrefix: "none"
32
- * materializePathname("/app/{locale}/about", config, "en");
33
- * // => /app/about
34
- * ```
35
- */
36
6
  const materializePathname = (standardizedPathname, config, locale) => {
37
- const { localePrefix } = config.routing;
38
- const removeLocale = () => {
39
- const result = standardizedPathname.replace(`/${LOCALE_PLACEHOLDER}`, "");
40
- return result === "" ? "/" : result;
41
- };
42
- const injectLocale = () => standardizedPathname.replace(LOCALE_PLACEHOLDER, locale);
43
- // localePrefix: "none"
44
- if (localePrefix === "none")
45
- return removeLocale();
46
- // localePrefix: "all"
47
- if (localePrefix === "all")
48
- return injectLocale();
49
- // localePrefix: "except-default"
50
- return locale === config.defaultLocale ? removeLocale() : injectLocale();
7
+ const { localePrefix } = config.routing;
8
+ const removeLocale = () => {
9
+ const result = standardizedPathname.replace(`/${LOCALE_PLACEHOLDER}`, "");
10
+ return result === "" ? "/" : result;
11
+ };
12
+ const injectLocale = () => standardizedPathname.replace(LOCALE_PLACEHOLDER, locale);
13
+ if (localePrefix === "none") return removeLocale();
14
+ if (localePrefix === "all") return injectLocale();
15
+ return locale === config.defaultLocale ? removeLocale() : injectLocale();
51
16
  };
52
17
 
53
18
  export { materializePathname };
@@ -3,37 +3,13 @@ import 'logry';
3
3
  import 'p-limit';
4
4
  import 'intor-translator';
5
5
 
6
- /**
7
- * Standardizes a canonical pathname into an internal routing template.
8
- *
9
- * Standardized representation:
10
- * - Prepends the deployment prefix (`basePath`) if defined
11
- * - Injects the `{locale}` placeholder as the first path segment
12
- * - Preserves the canonical pathname structure
13
- *
14
- * Input must be a canonical pathname.
15
- *
16
- * Output is an internal routing template and
17
- * is not a locale-resolved URL.
18
- *
19
- * @example
20
- * ```ts
21
- * // config.routing.basePath: "/app",
22
- * standardizePathname("/about", config);
23
- * // => "/app/{locale}/about"
24
- * ```
25
- */
26
6
  const standardizePathname = (canonicalPathname, config) => {
27
- const { routing } = config;
28
- const basePath = routing.basePath && routing.basePath !== "/" ? routing.basePath : "";
29
- if (canonicalPathname === "/") {
30
- return basePath
31
- ? `${basePath}/${LOCALE_PLACEHOLDER}`
32
- : `/${LOCALE_PLACEHOLDER}`;
33
- }
34
- return basePath
35
- ? `${basePath}/${LOCALE_PLACEHOLDER}${canonicalPathname}`
36
- : `/${LOCALE_PLACEHOLDER}${canonicalPathname}`;
7
+ const { routing } = config;
8
+ const basePath = routing.basePath && routing.basePath !== "/" ? routing.basePath : "";
9
+ if (canonicalPathname === "/") {
10
+ return basePath ? `${basePath}/${LOCALE_PLACEHOLDER}` : `/${LOCALE_PLACEHOLDER}`;
11
+ }
12
+ return basePath ? `${basePath}/${LOCALE_PLACEHOLDER}${canonicalPathname}` : `/${LOCALE_PLACEHOLDER}${canonicalPathname}`;
37
13
  };
38
14
 
39
15
  export { standardizePathname };
@@ -4,30 +4,33 @@ import 'intor-translator';
4
4
  import { createTRich } from '../../core/translator/create-t-rich.js';
5
5
  import { initTranslator } from '../translator/init-translator.js';
6
6
 
7
- /**
8
- * Get a server-side translator for the current execution context.
9
- *
10
- * @public
11
- */
12
7
  async function getTranslator(config, params) {
13
- const { locale, loader, readers, allowCacheWrite = false, fetch = globalThis.fetch, handlers, hooks, preKey, } = params;
14
- // Initialize a locale-bound translator snapshot with messages loaded
15
- const translator = await initTranslator(config, locale, {
16
- ...(loader !== undefined ? { loader } : {}),
17
- ...(readers !== undefined ? { readers } : {}),
18
- allowCacheWrite,
19
- fetch,
20
- ...(handlers !== undefined ? { handlers } : {}),
21
- ...(hooks !== undefined ? { hooks } : {}),
22
- });
23
- const scoped = translator.scoped(preKey);
24
- return {
25
- messages: translator.messages,
26
- locale: translator.locale,
27
- hasKey: scoped.hasKey,
28
- t: scoped.t,
29
- tRich: createTRich(scoped.t),
30
- };
8
+ const {
9
+ locale,
10
+ loader,
11
+ readers,
12
+ allowCacheWrite = false,
13
+ fetch = globalThis.fetch,
14
+ handlers,
15
+ hooks,
16
+ preKey
17
+ } = params;
18
+ const translator = await initTranslator(config, locale, {
19
+ ...loader !== void 0 ? { loader } : {},
20
+ ...readers !== void 0 ? { readers } : {},
21
+ allowCacheWrite,
22
+ fetch,
23
+ ...handlers !== void 0 ? { handlers } : {},
24
+ ...hooks !== void 0 ? { hooks } : {}
25
+ });
26
+ const scoped = translator.scoped(preKey);
27
+ return {
28
+ messages: translator.messages,
29
+ locale: translator.locale,
30
+ hasKey: scoped.hasKey,
31
+ t: scoped.t,
32
+ tRich: createTRich(scoped.t)
33
+ };
31
34
  }
32
35
 
33
36
  export { getTranslator };
@@ -3,32 +3,27 @@ import 'p-limit';
3
3
  import 'intor-translator';
4
4
  import { initTranslator } from '../translator/init-translator.js';
5
5
 
6
- /**
7
- * Initializes Intor for the current execution context.
8
- *
9
- * Produces a server-side snapshot for SSR and
10
- * full-stack rendering environments.
11
- *
12
- * @public
13
- */
14
6
  async function intor(config, locale, options) {
15
- const baseLogger = getLogger(config.logger);
16
- const logger = baseLogger.child({ scope: "intor" });
17
- logger.info("Start Intor initialization.");
18
- logger.debug(`Initializing Intor with locale "${locale}".`);
19
- const { readers, allowCacheWrite = true, fetch = globalThis.fetch, } = options ?? {};
20
- // Initialize a locale-bound translator snapshot with messages loaded
21
- const translator = await initTranslator(config, locale, {
22
- ...(readers !== undefined ? { readers: readers } : {}),
23
- allowCacheWrite,
24
- fetch,
25
- });
26
- logger.info("Intor initialized.");
27
- return {
28
- config,
29
- locale: translator.locale,
30
- messages: translator.messages,
31
- };
7
+ const baseLogger = getLogger(config.logger);
8
+ const logger = baseLogger.child({ scope: "intor" });
9
+ logger.info("Start Intor initialization.");
10
+ logger.debug(`Initializing Intor with locale "${locale}".`);
11
+ const {
12
+ readers,
13
+ allowCacheWrite = true,
14
+ fetch = globalThis.fetch
15
+ } = options ?? {};
16
+ const translator = await initTranslator(config, locale, {
17
+ ...readers !== void 0 ? { readers } : {},
18
+ allowCacheWrite,
19
+ fetch
20
+ });
21
+ logger.info("Intor initialized.");
22
+ return {
23
+ config,
24
+ locale: translator.locale,
25
+ messages: translator.messages
26
+ };
32
27
  }
33
28
 
34
29
  export { intor };
@@ -1,11 +1,8 @@
1
- /**
2
- * Get the messages pool.
3
- */
4
1
  function getMessagesPool() {
5
- if (!globalThis.__INTOR_MESSAGES_POOL__) {
6
- globalThis.__INTOR_MESSAGES_POOL__ = new Map();
7
- }
8
- return globalThis.__INTOR_MESSAGES_POOL__;
2
+ if (!globalThis.__INTOR_MESSAGES_POOL__) {
3
+ globalThis.__INTOR_MESSAGES_POOL__ = /* @__PURE__ */ new Map();
4
+ }
5
+ return globalThis.__INTOR_MESSAGES_POOL__;
9
6
  }
10
7
 
11
8
  export { getMessagesPool };
@@ -6,101 +6,85 @@ import 'intor-translator';
6
6
  import { getMessagesPool } from './cache/messages-pool.js';
7
7
  import { readLocaleMessages } from './read-locale-messages/read-locale-messages.js';
8
8
 
9
- /**
10
- * Load locale messages from the local file system.
11
- *
12
- * This function serves as the orchestration layer for local message loading.
13
- * It coordinates:
14
- *
15
- * - Locale resolution with fallbacks
16
- * - Concurrency control for file system access
17
- * - Process-level memoization (read by default, write by ownership)
18
- *
19
- * Local messages are cached for the lifetime of the process.
20
- * Cache writes are restricted to the primary initialization flow.
21
- *
22
- * File traversal, parsing, and validation are delegated to lower-level utilities.
23
- */
24
- const loadLocalMessages = async ({ id, locale, fallbackLocales, namespaces, rootDir = "messages", concurrency = 10, readers, pool = getMessagesPool(), allowCacheWrite = false, loggerOptions, }) => {
25
- const baseLogger = getLogger(loggerOptions);
26
- const logger = baseLogger.child({ scope: "load-local-messages" });
27
- const start = performance.now();
28
- logger.debug("Loading local messages.", {
29
- rootDir,
30
- resolvedRootDir: path.resolve(rootDir),
31
- });
32
- // ---------------------------------------------------------------------------
33
- // Cache key resolution
34
- // ---------------------------------------------------------------------------
35
- const cacheKey = normalizeCacheKey([
36
- id,
37
- "loaderType:local",
38
- rootDir,
39
- locale,
40
- fallbackLocales?.sort().join(","),
41
- namespaces?.sort().join(","),
42
- ].filter(Boolean));
43
- // ---------------------------------------------------------------------------
44
- // Cache read
45
- // ---------------------------------------------------------------------------
46
- if (cacheKey) {
47
- const cached = pool.get(cacheKey);
48
- if (cached) {
49
- logger.debug("Messages cache hit.", { key: cacheKey });
50
- return cached;
51
- }
52
- }
53
- // ---------------------------------------------------------------------------
54
- // Resolve locale messages with ordered fallback strategy
55
- // ---------------------------------------------------------------------------
56
- const limit = pLimit(concurrency);
57
- const candidateLocales = [locale, ...(fallbackLocales || [])];
58
- let messages;
59
- for (const candidateLocale of candidateLocales) {
60
- const isLast = candidateLocale === candidateLocales[candidateLocales.length - 1];
61
- try {
62
- const result = await readLocaleMessages({
63
- locale: candidateLocale,
64
- ...(namespaces !== undefined ? { namespaces } : {}),
65
- rootDir,
66
- limit,
67
- readers: readers ?? {},
68
- loggerOptions,
69
- });
70
- // Stop at the first locale that yields non-empty messages
71
- if (Object.values(result[candidateLocale] || {}).length > 0) {
72
- messages = result;
73
- break;
74
- }
75
- }
76
- catch {
77
- if (isLast) {
78
- logger.warn("Failed to load messages for all candidate locales.", {
79
- locale,
80
- fallbackLocales,
81
- });
82
- }
83
- else {
84
- logger.warn(`Failed to load locale messages for "${candidateLocale}", trying next fallback.`);
85
- }
86
- }
9
+ const loadLocalMessages = async ({
10
+ id,
11
+ locale,
12
+ fallbackLocales,
13
+ namespaces,
14
+ rootDir = "messages",
15
+ concurrency = 10,
16
+ readers,
17
+ pool = getMessagesPool(),
18
+ allowCacheWrite = false,
19
+ loggerOptions
20
+ }) => {
21
+ const baseLogger = getLogger(loggerOptions);
22
+ const logger = baseLogger.child({ scope: "load-local-messages" });
23
+ const start = performance.now();
24
+ logger.debug("Loading local messages.", {
25
+ rootDir,
26
+ resolvedRootDir: path.resolve(rootDir)
27
+ });
28
+ const cacheKey = normalizeCacheKey(
29
+ [
30
+ id,
31
+ "loaderType:local",
32
+ rootDir,
33
+ locale,
34
+ fallbackLocales?.sort().join(","),
35
+ namespaces?.sort().join(",")
36
+ ].filter(Boolean)
37
+ );
38
+ if (cacheKey) {
39
+ const cached = pool.get(cacheKey);
40
+ if (cached) {
41
+ logger.debug("Messages cache hit.", { key: cacheKey });
42
+ return cached;
87
43
  }
88
- // ---------------------------------------------------------------------------
89
- // Cache write (explicitly permitted)
90
- // ---------------------------------------------------------------------------
91
- const isProd = process.env["NODE_ENV"] === "production";
92
- const canWriteCache = isProd && allowCacheWrite;
93
- if (canWriteCache && cacheKey && messages) {
94
- pool.set(cacheKey, messages);
95
- }
96
- // Final success log with resolved locale and timing
97
- if (messages) {
98
- logger.trace("Finished loading local messages.", {
99
- loadedLocale: Object.keys(messages)[0],
100
- duration: `${Math.round(performance.now() - start)} ms`,
44
+ }
45
+ const limit = pLimit(concurrency);
46
+ const candidateLocales = [locale, ...fallbackLocales || []];
47
+ let messages;
48
+ for (const candidateLocale of candidateLocales) {
49
+ const isLast = candidateLocale === candidateLocales[candidateLocales.length - 1];
50
+ try {
51
+ const result = await readLocaleMessages({
52
+ locale: candidateLocale,
53
+ ...namespaces !== void 0 ? { namespaces } : {},
54
+ rootDir,
55
+ limit,
56
+ readers: readers ?? {},
57
+ loggerOptions
58
+ });
59
+ if (Object.values(result[candidateLocale] || {}).length > 0) {
60
+ messages = result;
61
+ break;
62
+ }
63
+ } catch {
64
+ if (isLast) {
65
+ logger.warn("Failed to load messages for all candidate locales.", {
66
+ locale,
67
+ fallbackLocales
101
68
  });
69
+ } else {
70
+ logger.warn(
71
+ `Failed to load locale messages for "${candidateLocale}", trying next fallback.`
72
+ );
73
+ }
102
74
  }
103
- return messages;
75
+ }
76
+ const isProd = process.env["NODE_ENV"] === "production";
77
+ const canWriteCache = isProd && allowCacheWrite;
78
+ if (canWriteCache && cacheKey && messages) {
79
+ pool.set(cacheKey, messages);
80
+ }
81
+ if (messages) {
82
+ logger.trace("Finished loading local messages.", {
83
+ loadedLocale: Object.keys(messages)[0],
84
+ duration: `${Math.round(performance.now() - start)} ms`
85
+ });
86
+ }
87
+ return messages;
104
88
  };
105
89
 
106
90
  export { loadLocalMessages };
@@ -4,87 +4,66 @@ import { getLogger } from '../../../../../core/logger/get-logger.js';
4
4
  import 'p-limit';
5
5
  import 'intor-translator';
6
6
 
7
- /**
8
- * Recursively collects message file metadata under a given locale root.
9
- *
10
- * - Traverses directories and collects matching message files
11
- * - Supports filtering by file extensions and optional namespaces
12
- *
13
- * @example
14
- * ```ts
15
- * [{
16
- * namespace: "auth", // If messages under locale root (no namespace) -> "index"
17
- * fullPath: "/Users/john/my-app/messages/en-US/auth/login.json",
18
- * relativePath: "auth/login.json",
19
- * segments: ["auth", "login"],
20
- * basename: "login",
21
- * }, ... ];
22
- * ```
23
- */
24
- async function collectFileEntries({ readdir = fs.readdir, namespaces, rootDir, limit, exts = [], loggerOptions, }) {
25
- const baseLogger = getLogger(loggerOptions);
26
- const logger = baseLogger.child({ scope: "collect-file-entries" });
27
- const supportedExts = new Set(["json", ...exts]);
28
- const fileEntries = [];
29
- // Recursive directory walk
30
- const walk = async (currentDir) => {
31
- // -------------------------------------------------------------------------
32
- // Read directory entries
33
- // -------------------------------------------------------------------------
34
- let entries = [];
35
- try {
36
- entries = await readdir(currentDir, { withFileTypes: true });
37
- }
38
- catch {
39
- logger.debug("Locale directory not found, skipping locale.", {
40
- localeDir: currentDir,
41
- });
42
- return;
43
- }
44
- // -------------------------------------------------------------------------
45
- // 1. Recurse into sub-directories (control flow, no limit)
46
- // -------------------------------------------------------------------------
47
- for (const entry of entries) {
48
- if (!entry.isDirectory())
49
- continue;
50
- await walk(path.join(currentDir, entry.name));
51
- }
52
- // -------------------------------------------------------------------------
53
- // 2. Process files (IO-bound, concurrency-limited)
54
- // -------------------------------------------------------------------------
55
- const tasks = entries
56
- .filter((entry) => entry.isFile())
57
- .map((entry) => limit(() => {
58
- const fullPath = path.join(currentDir, entry.name);
59
- const ext = path.extname(entry.name).slice(1);
60
- if (!ext || !supportedExts.has(ext))
61
- return;
62
- const relativePath = path.relative(rootDir, fullPath);
63
- const withoutExt = relativePath.slice(0, relativePath.length - (ext.length + 1));
64
- const segments = withoutExt.split(path.sep).filter(Boolean);
65
- const namespace = segments.at(0);
66
- if (!namespace)
67
- return;
68
- // Apply namespace filter (always allow "index")
69
- if (namespaces && namespace !== "index") {
70
- if (!namespaces.includes(namespace))
71
- return;
72
- }
73
- fileEntries.push({
74
- namespace,
75
- fullPath,
76
- relativePath,
77
- segments,
78
- basename: path.basename(entry.name, `.${ext}`),
79
- });
80
- }));
81
- await Promise.all(tasks);
82
- };
83
- await walk(rootDir);
84
- if (fileEntries.length > 0) {
85
- logger.trace(`Collected ${fileEntries.length} local message files for locale "${path.basename(rootDir)}".`);
7
+ async function collectFileEntries({
8
+ readdir = fs.readdir,
9
+ namespaces,
10
+ rootDir,
11
+ limit,
12
+ exts = [],
13
+ loggerOptions
14
+ }) {
15
+ const baseLogger = getLogger(loggerOptions);
16
+ const logger = baseLogger.child({ scope: "collect-file-entries" });
17
+ const supportedExts = /* @__PURE__ */ new Set(["json", ...exts]);
18
+ const fileEntries = [];
19
+ const walk = async (currentDir) => {
20
+ let entries = [];
21
+ try {
22
+ entries = await readdir(currentDir, { withFileTypes: true });
23
+ } catch {
24
+ logger.debug("Locale directory not found, skipping locale.", {
25
+ localeDir: currentDir
26
+ });
27
+ return;
86
28
  }
87
- return fileEntries;
29
+ for (const entry of entries) {
30
+ if (!entry.isDirectory()) continue;
31
+ await walk(path.join(currentDir, entry.name));
32
+ }
33
+ const tasks = entries.filter((entry) => entry.isFile()).map(
34
+ (entry) => limit(() => {
35
+ const fullPath = path.join(currentDir, entry.name);
36
+ const ext = path.extname(entry.name).slice(1);
37
+ if (!ext || !supportedExts.has(ext)) return;
38
+ const relativePath = path.relative(rootDir, fullPath);
39
+ const withoutExt = relativePath.slice(
40
+ 0,
41
+ relativePath.length - (ext.length + 1)
42
+ );
43
+ const segments = withoutExt.split(path.sep).filter(Boolean);
44
+ const namespace = segments.at(0);
45
+ if (!namespace) return;
46
+ if (namespaces && namespace !== "index") {
47
+ if (!namespaces.includes(namespace)) return;
48
+ }
49
+ fileEntries.push({
50
+ namespace,
51
+ fullPath,
52
+ relativePath,
53
+ segments,
54
+ basename: path.basename(entry.name, `.${ext}`)
55
+ });
56
+ })
57
+ );
58
+ await Promise.all(tasks);
59
+ };
60
+ await walk(rootDir);
61
+ if (fileEntries.length > 0) {
62
+ logger.trace(
63
+ `Collected ${fileEntries.length} local message files for locale "${path.basename(rootDir)}".`
64
+ );
65
+ }
66
+ return fileEntries;
88
67
  }
89
68
 
90
69
  export { collectFileEntries };