intor 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (322) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +1 -1
  3. package/dist/core/export/index.js +1 -0
  4. package/dist/core/src/client/shared/helpers/get-client-locale.js +5 -20
  5. package/dist/core/src/client/shared/utils/locale/detect-browser-locale.js +2 -8
  6. package/dist/core/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  7. package/dist/core/src/config/constants/cookie.js +9 -9
  8. package/dist/core/src/config/constants/routing.js +13 -14
  9. package/dist/core/src/config/define-intor-config.js +28 -44
  10. package/dist/core/src/config/resolvers/resolve-cookie-options.js +4 -4
  11. package/dist/core/src/config/resolvers/resolve-fallback-locales.js +33 -50
  12. package/dist/core/src/config/resolvers/resolve-routing-options.js +32 -61
  13. package/dist/core/src/config/validators/validate-default-locale.js +8 -13
  14. package/dist/core/src/config/validators/validate-id.js +8 -13
  15. package/dist/core/src/config/validators/validate-supported-locales.js +8 -13
  16. package/dist/core/src/core/constants/locale-placeholder.js +0 -1
  17. package/dist/core/src/core/error/intor-error.js +14 -29
  18. package/dist/core/src/core/locale/canonicalize-locale.js +7 -18
  19. package/dist/core/src/core/locale/match-locale.js +24 -50
  20. package/dist/core/src/core/locale/parse-locale.js +12 -22
  21. package/dist/core/src/core/logger/get-logger.js +26 -31
  22. package/dist/core/src/core/logger/global-logger-pool.js +4 -4
  23. package/dist/core/src/core/messages/internal-metadata.js +1 -1
  24. package/dist/core/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  25. package/dist/core/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  26. package/dist/core/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  27. package/dist/core/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  28. package/dist/core/src/core/messages/merge-messages.js +17 -28
  29. package/dist/core/src/core/messages/utils/is-valid-messages.js +22 -37
  30. package/dist/core/src/core/messages/utils/nest-object-from-path.js +5 -17
  31. package/dist/core/src/core/render/create-html-renderer.js +29 -37
  32. package/dist/core/src/core/render/utils/escape-html.js +1 -6
  33. package/dist/core/src/core/render/utils/render-attributes.js +6 -11
  34. package/dist/core/src/core/translator/create-t-rich.js +6 -15
  35. package/dist/core/src/core/translator/create-translator.js +16 -24
  36. package/dist/core/src/core/utils/deep-merge.js +24 -42
  37. package/dist/core/src/core/utils/normalizers/normalize-cache-key.js +14 -40
  38. package/dist/core/src/core/utils/normalizers/normalize-pathname.js +19 -37
  39. package/dist/core/src/core/utils/normalizers/normalize-query.js +6 -20
  40. package/dist/core/src/core/utils/parse-cookie-header.js +11 -18
  41. package/dist/core/src/core/utils/resolve-loader-options.js +6 -32
  42. package/dist/core/src/edge/helpers/get-translator.js +14 -20
  43. package/dist/core/src/edge/translator/init-translator.js +23 -31
  44. package/dist/core/src/routing/inbound/helpers/resolve-inbound-from-request.js +21 -28
  45. package/dist/core/src/routing/inbound/resolve-inbound.js +22 -37
  46. package/dist/core/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  47. package/dist/core/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  48. package/dist/core/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  49. package/dist/core/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  50. package/dist/core/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  51. package/dist/core/src/routing/locale/get-locale-from-accept-language.js +21 -36
  52. package/dist/core/src/routing/locale/get-locale-from-host.js +5 -28
  53. package/dist/core/src/routing/locale/get-locale-from-pathname.js +11 -37
  54. package/dist/core/src/routing/locale/get-locale-from-query.js +2 -17
  55. package/dist/core/src/routing/pathname/canonicalize-pathname.js +25 -67
  56. package/dist/core/src/routing/pathname/localize-pathname.js +12 -30
  57. package/dist/core/src/routing/pathname/materialize-pathname.js +9 -44
  58. package/dist/core/src/routing/pathname/standardize-pathname.js +6 -30
  59. package/dist/core/src/server/helpers/get-translator.js +26 -23
  60. package/dist/core/src/server/intor/intor.js +20 -25
  61. package/dist/core/src/server/messages/load-local-messages/cache/messages-pool.js +4 -7
  62. package/dist/core/src/server/messages/load-local-messages/load-local-messages.js +76 -92
  63. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +59 -80
  64. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +53 -87
  65. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/utils/json-reader.js +3 -6
  66. package/dist/core/src/server/messages/load-local-messages/read-locale-messages/read-locale-messages.js +23 -35
  67. package/dist/core/src/server/messages/load-messages.js +56 -69
  68. package/dist/core/src/server/translator/init-translator.js +28 -30
  69. package/dist/express/src/adapters/express/create-intor-handler.js +35 -46
  70. package/dist/express/src/adapters/express/get-translator.js +2 -9
  71. package/dist/express/src/core/constants/locale-placeholder.js +0 -1
  72. package/dist/express/src/core/locale/canonicalize-locale.js +7 -18
  73. package/dist/express/src/core/locale/match-locale.js +24 -50
  74. package/dist/express/src/core/locale/parse-locale.js +12 -22
  75. package/dist/express/src/core/utils/normalizers/normalize-pathname.js +19 -37
  76. package/dist/express/src/core/utils/normalizers/normalize-query.js +6 -20
  77. package/dist/express/src/core/utils/parse-cookie-header.js +11 -18
  78. package/dist/express/src/routing/inbound/resolve-inbound.js +22 -37
  79. package/dist/express/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  80. package/dist/express/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  81. package/dist/express/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  82. package/dist/express/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  83. package/dist/express/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  84. package/dist/express/src/routing/locale/get-locale-from-accept-language.js +21 -36
  85. package/dist/express/src/routing/locale/get-locale-from-host.js +5 -28
  86. package/dist/express/src/routing/locale/get-locale-from-pathname.js +11 -37
  87. package/dist/express/src/routing/locale/get-locale-from-query.js +2 -17
  88. package/dist/express/src/routing/pathname/canonicalize-pathname.js +25 -67
  89. package/dist/express/src/routing/pathname/localize-pathname.js +12 -30
  90. package/dist/express/src/routing/pathname/materialize-pathname.js +9 -44
  91. package/dist/express/src/routing/pathname/standardize-pathname.js +6 -30
  92. package/dist/fastify/src/adapters/fastify/create-intor-handler.js +35 -47
  93. package/dist/fastify/src/adapters/fastify/get-translator.js +2 -9
  94. package/dist/fastify/src/adapters/fastify/intor-fastify-plugin.js +29 -38
  95. package/dist/fastify/src/core/constants/locale-placeholder.js +0 -1
  96. package/dist/fastify/src/core/locale/canonicalize-locale.js +7 -18
  97. package/dist/fastify/src/core/locale/match-locale.js +24 -50
  98. package/dist/fastify/src/core/locale/parse-locale.js +12 -22
  99. package/dist/fastify/src/core/utils/normalizers/normalize-pathname.js +19 -37
  100. package/dist/fastify/src/core/utils/normalizers/normalize-query.js +6 -20
  101. package/dist/fastify/src/core/utils/parse-cookie-header.js +11 -18
  102. package/dist/fastify/src/routing/inbound/resolve-inbound.js +22 -37
  103. package/dist/fastify/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  104. package/dist/fastify/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  105. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  106. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  107. package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  108. package/dist/fastify/src/routing/locale/get-locale-from-accept-language.js +21 -36
  109. package/dist/fastify/src/routing/locale/get-locale-from-host.js +5 -28
  110. package/dist/fastify/src/routing/locale/get-locale-from-pathname.js +11 -37
  111. package/dist/fastify/src/routing/locale/get-locale-from-query.js +2 -17
  112. package/dist/fastify/src/routing/pathname/canonicalize-pathname.js +25 -67
  113. package/dist/fastify/src/routing/pathname/localize-pathname.js +12 -30
  114. package/dist/fastify/src/routing/pathname/materialize-pathname.js +9 -44
  115. package/dist/fastify/src/routing/pathname/standardize-pathname.js +6 -30
  116. package/dist/hono/src/adapters/hono/create-intor-handler.js +33 -44
  117. package/dist/hono/src/adapters/hono/get-translator.js +2 -9
  118. package/dist/hono/src/core/constants/locale-placeholder.js +0 -1
  119. package/dist/hono/src/core/locale/canonicalize-locale.js +7 -18
  120. package/dist/hono/src/core/locale/match-locale.js +24 -50
  121. package/dist/hono/src/core/locale/parse-locale.js +12 -22
  122. package/dist/hono/src/core/utils/normalizers/normalize-pathname.js +19 -37
  123. package/dist/hono/src/core/utils/normalizers/normalize-query.js +6 -20
  124. package/dist/hono/src/core/utils/parse-cookie-header.js +11 -18
  125. package/dist/hono/src/routing/inbound/resolve-inbound.js +22 -37
  126. package/dist/hono/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  127. package/dist/hono/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  128. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  129. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  130. package/dist/hono/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  131. package/dist/hono/src/routing/locale/get-locale-from-accept-language.js +21 -36
  132. package/dist/hono/src/routing/locale/get-locale-from-host.js +5 -28
  133. package/dist/hono/src/routing/locale/get-locale-from-pathname.js +11 -37
  134. package/dist/hono/src/routing/locale/get-locale-from-query.js +2 -17
  135. package/dist/hono/src/routing/pathname/canonicalize-pathname.js +25 -67
  136. package/dist/hono/src/routing/pathname/localize-pathname.js +12 -30
  137. package/dist/hono/src/routing/pathname/materialize-pathname.js +9 -44
  138. package/dist/hono/src/routing/pathname/standardize-pathname.js +6 -30
  139. package/dist/next/export/next/server/index.js +1 -0
  140. package/dist/next/src/adapters/next/create-intor-handler.js +39 -48
  141. package/dist/next/src/adapters/next/header-keys.js +9 -0
  142. package/dist/next/src/adapters/next/link.js +33 -28
  143. package/dist/next/src/adapters/next/redirect.js +12 -15
  144. package/dist/next/src/adapters/next/server/get-locale.js +13 -24
  145. package/dist/next/src/adapters/next/server/get-translator.js +2 -9
  146. package/dist/next/src/adapters/next/server/intor.js +5 -13
  147. package/dist/next/src/adapters/next/server/read-intor-url-state.js +13 -0
  148. package/dist/next/src/adapters/next/use-router.js +47 -66
  149. package/dist/next/src/client/shared/navigation/execute-navigation.js +20 -38
  150. package/dist/next/src/client/shared/utils/build-cookie-string.js +18 -27
  151. package/dist/next/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  152. package/dist/next/src/core/constants/locale-placeholder.js +0 -1
  153. package/dist/next/src/core/locale/canonicalize-locale.js +7 -18
  154. package/dist/next/src/core/locale/match-locale.js +24 -50
  155. package/dist/next/src/core/locale/parse-locale.js +12 -22
  156. package/dist/next/src/core/utils/normalizers/normalize-pathname.js +19 -37
  157. package/dist/next/src/core/utils/normalizers/normalize-query.js +6 -20
  158. package/dist/next/src/core/utils/resolve-loader-options.js +6 -29
  159. package/dist/next/src/policies/shoud-full-reload.js +2 -5
  160. package/dist/next/src/policies/should-sync-locale.js +1 -4
  161. package/dist/next/src/routing/inbound/resolve-inbound.js +24 -39
  162. package/dist/next/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  163. package/dist/next/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  164. package/dist/next/src/routing/inbound/resolve-pathname/strategies/all.js +13 -29
  165. package/dist/next/src/routing/inbound/resolve-pathname/strategies/except-default.js +14 -30
  166. package/dist/next/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  167. package/dist/next/src/routing/locale/get-locale-from-accept-language.js +21 -36
  168. package/dist/next/src/routing/locale/get-locale-from-host.js +5 -28
  169. package/dist/next/src/routing/locale/get-locale-from-pathname.js +11 -37
  170. package/dist/next/src/routing/locale/get-locale-from-query.js +2 -17
  171. package/dist/next/src/routing/outbound/decide-strategy.js +9 -9
  172. package/dist/next/src/routing/outbound/determine-target.js +28 -44
  173. package/dist/next/src/routing/outbound/resolve-outbound.js +12 -16
  174. package/dist/next/src/routing/outbound/utils/derive-host-destination.js +5 -9
  175. package/dist/next/src/routing/outbound/utils/derive-query-destination.js +4 -7
  176. package/dist/next/src/routing/outbound/utils/is-external-destination.js +1 -7
  177. package/dist/next/src/routing/pathname/canonicalize-pathname.js +25 -67
  178. package/dist/next/src/routing/pathname/localize-pathname.js +12 -30
  179. package/dist/next/src/routing/pathname/materialize-pathname.js +9 -44
  180. package/dist/next/src/routing/pathname/standardize-pathname.js +6 -30
  181. package/dist/react/src/client/react/helpers/use-intor.js +25 -44
  182. package/dist/react/src/client/react/provider/effects/use-locale-effects.js +20 -25
  183. package/dist/react/src/client/react/provider/effects/use-messages-effects.js +17 -16
  184. package/dist/react/src/client/react/provider/intor-provider.js +63 -66
  185. package/dist/react/src/client/react/provider/use-intor-context.js +4 -4
  186. package/dist/react/src/client/react/render/create-react-renderer.js +18 -24
  187. package/dist/react/src/client/react/translator/create-t-rich.js +9 -22
  188. package/dist/react/src/client/react/translator/use-translator.js +11 -16
  189. package/dist/react/src/client/shared/messages/create-refetch-messages.js +41 -51
  190. package/dist/react/src/client/shared/provider/effective-state.js +2 -6
  191. package/dist/react/src/client/shared/utils/build-cookie-string.js +18 -27
  192. package/dist/react/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  193. package/dist/react/src/client/shared/utils/locale/set-document-locale.js +2 -8
  194. package/dist/react/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  195. package/dist/react/src/core/logger/get-logger.js +26 -31
  196. package/dist/react/src/core/logger/global-logger-pool.js +4 -4
  197. package/dist/react/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  198. package/dist/react/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  199. package/dist/react/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  200. package/dist/react/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  201. package/dist/react/src/core/messages/merge-messages.js +17 -28
  202. package/dist/react/src/core/messages/utils/is-valid-messages.js +22 -37
  203. package/dist/react/src/core/messages/utils/nest-object-from-path.js +5 -17
  204. package/dist/react/src/core/utils/deep-merge.js +24 -42
  205. package/dist/react/src/core/utils/resolve-loader-options.js +6 -29
  206. package/dist/react/src/policies/should-persist-on-first-visit.js +1 -4
  207. package/dist/svelte/export/svelte/index.js +0 -6
  208. package/dist/svelte/src/client/shared/messages/create-refetch-messages.js +41 -51
  209. package/dist/svelte/src/client/shared/provider/effective-state.js +2 -6
  210. package/dist/svelte/src/client/shared/utils/build-cookie-string.js +18 -27
  211. package/dist/svelte/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  212. package/dist/svelte/src/client/shared/utils/locale/set-document-locale.js +2 -8
  213. package/dist/svelte/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  214. package/dist/svelte/src/client/svelte/provider/create-intor-store.js +59 -63
  215. package/dist/svelte/src/client/svelte/provider/effects/attach-locale-effects.js +20 -25
  216. package/dist/svelte/src/client/svelte/provider/effects/attach-messages-effects.js +21 -18
  217. package/dist/svelte/src/client/svelte/provider/get-intor-context.js +4 -4
  218. package/dist/svelte/src/client/svelte/translator/use-translator.js +11 -16
  219. package/dist/svelte/src/core/logger/get-logger.js +26 -31
  220. package/dist/svelte/src/core/logger/global-logger-pool.js +4 -4
  221. package/dist/svelte/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  222. package/dist/svelte/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  223. package/dist/svelte/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  224. package/dist/svelte/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  225. package/dist/svelte/src/core/messages/merge-messages.js +17 -28
  226. package/dist/svelte/src/core/messages/utils/is-valid-messages.js +22 -37
  227. package/dist/svelte/src/core/messages/utils/nest-object-from-path.js +5 -17
  228. package/dist/svelte/src/core/render/create-html-renderer.js +29 -37
  229. package/dist/svelte/src/core/render/utils/escape-html.js +1 -6
  230. package/dist/svelte/src/core/render/utils/render-attributes.js +6 -11
  231. package/dist/svelte/src/core/translator/create-t-rich.js +6 -15
  232. package/dist/svelte/src/core/utils/deep-merge.js +24 -42
  233. package/dist/svelte/src/core/utils/resolve-loader-options.js +6 -29
  234. package/dist/svelte/src/policies/should-persist-on-first-visit.js +1 -4
  235. package/dist/svelte-kit/src/adapters/svelte-kit/create-intor-handler.js +37 -57
  236. package/dist/svelte-kit/src/adapters/svelte-kit/use-navigation.js +29 -27
  237. package/dist/svelte-kit/src/adapters/svelte-kit/utils/is-svelte-kit-ssg.js +4 -11
  238. package/dist/svelte-kit/src/client/shared/navigation/execute-navigation.js +19 -37
  239. package/dist/svelte-kit/src/client/shared/utils/build-cookie-string.js +18 -27
  240. package/dist/svelte-kit/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  241. package/dist/svelte-kit/src/core/constants/locale-placeholder.js +0 -1
  242. package/dist/svelte-kit/src/core/locale/canonicalize-locale.js +7 -18
  243. package/dist/svelte-kit/src/core/locale/match-locale.js +24 -50
  244. package/dist/svelte-kit/src/core/locale/parse-locale.js +12 -22
  245. package/dist/svelte-kit/src/core/utils/normalizers/normalize-pathname.js +19 -37
  246. package/dist/svelte-kit/src/core/utils/normalizers/normalize-query.js +6 -20
  247. package/dist/svelte-kit/src/core/utils/resolve-loader-options.js +6 -29
  248. package/dist/svelte-kit/src/policies/shoud-full-reload.js +2 -5
  249. package/dist/svelte-kit/src/policies/should-sync-locale.js +1 -4
  250. package/dist/svelte-kit/src/routing/inbound/resolve-inbound.js +22 -37
  251. package/dist/svelte-kit/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
  252. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
  253. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
  254. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
  255. package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
  256. package/dist/svelte-kit/src/routing/locale/get-locale-from-accept-language.js +21 -36
  257. package/dist/svelte-kit/src/routing/locale/get-locale-from-host.js +5 -28
  258. package/dist/svelte-kit/src/routing/locale/get-locale-from-pathname.js +11 -37
  259. package/dist/svelte-kit/src/routing/locale/get-locale-from-query.js +2 -17
  260. package/dist/svelte-kit/src/routing/outbound/decide-strategy.js +9 -9
  261. package/dist/svelte-kit/src/routing/outbound/determine-target.js +28 -44
  262. package/dist/svelte-kit/src/routing/outbound/resolve-outbound.js +12 -16
  263. package/dist/svelte-kit/src/routing/outbound/utils/derive-host-destination.js +5 -9
  264. package/dist/svelte-kit/src/routing/outbound/utils/derive-query-destination.js +4 -7
  265. package/dist/svelte-kit/src/routing/outbound/utils/is-external-destination.js +1 -7
  266. package/dist/svelte-kit/src/routing/pathname/canonicalize-pathname.js +25 -67
  267. package/dist/svelte-kit/src/routing/pathname/localize-pathname.js +12 -30
  268. package/dist/svelte-kit/src/routing/pathname/materialize-pathname.js +9 -44
  269. package/dist/svelte-kit/src/routing/pathname/standardize-pathname.js +6 -30
  270. package/dist/types/export/index.d.ts +1 -1
  271. package/dist/types/export/index.d.ts.map +1 -1
  272. package/dist/types/export/next/server/index.d.ts +1 -1
  273. package/dist/types/export/next/server/index.d.ts.map +1 -1
  274. package/dist/types/src/adapters/fastify/intor-fastify-plugin.d.ts.map +1 -1
  275. package/dist/types/src/adapters/next/create-intor-handler.d.ts.map +1 -1
  276. package/dist/types/src/{core/constants/headers.d.ts → adapters/next/header-keys.d.ts} +3 -2
  277. package/dist/types/src/adapters/next/header-keys.d.ts.map +1 -0
  278. package/dist/types/src/adapters/next/server/get-locale.d.ts.map +1 -1
  279. package/dist/types/src/adapters/next/server/index.d.ts +1 -0
  280. package/dist/types/src/adapters/next/server/index.d.ts.map +1 -1
  281. package/dist/types/src/adapters/next/server/read-intor-url-state.d.ts +13 -0
  282. package/dist/types/src/adapters/next/server/read-intor-url-state.d.ts.map +1 -0
  283. package/dist/types/src/core/constants/index.d.ts +0 -1
  284. package/dist/types/src/core/constants/index.d.ts.map +1 -1
  285. package/dist/types/src/core/constants/locale-placeholder.d.ts +5 -0
  286. package/dist/types/src/core/constants/locale-placeholder.d.ts.map +1 -1
  287. package/dist/types/src/core/index.d.ts +1 -1
  288. package/dist/types/src/core/index.d.ts.map +1 -1
  289. package/dist/types/src/edge/translator/init-translator.d.ts.map +1 -1
  290. package/dist/types/src/routing/outbound/decide-strategy.d.ts +1 -1
  291. package/dist/types/src/routing/outbound/decide-strategy.d.ts.map +1 -1
  292. package/dist/types/src/server/translator/init-translator.d.ts.map +1 -1
  293. package/dist/vue/src/client/shared/messages/create-refetch-messages.js +41 -51
  294. package/dist/vue/src/client/shared/provider/effective-state.js +2 -6
  295. package/dist/vue/src/client/shared/utils/build-cookie-string.js +18 -27
  296. package/dist/vue/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
  297. package/dist/vue/src/client/shared/utils/locale/set-document-locale.js +2 -8
  298. package/dist/vue/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
  299. package/dist/vue/src/client/vue/helpers/use-intor.js +20 -42
  300. package/dist/vue/src/client/vue/provider/effects/use-locale-effects.js +23 -24
  301. package/dist/vue/src/client/vue/provider/effects/use-messages-effects.js +15 -24
  302. package/dist/vue/src/client/vue/provider/inject-intor-context.js +4 -4
  303. package/dist/vue/src/client/vue/provider/intor-provider.js +61 -66
  304. package/dist/vue/src/client/vue/render/create-vue-renderer.js +18 -24
  305. package/dist/vue/src/client/vue/translator/create-t-rich.js +5 -17
  306. package/dist/vue/src/client/vue/translator/trans.js +24 -31
  307. package/dist/vue/src/client/vue/translator/use-translator.js +12 -17
  308. package/dist/vue/src/core/logger/get-logger.js +26 -31
  309. package/dist/vue/src/core/logger/global-logger-pool.js +4 -4
  310. package/dist/vue/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
  311. package/dist/vue/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
  312. package/dist/vue/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
  313. package/dist/vue/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
  314. package/dist/vue/src/core/messages/merge-messages.js +17 -28
  315. package/dist/vue/src/core/messages/utils/is-valid-messages.js +22 -37
  316. package/dist/vue/src/core/messages/utils/nest-object-from-path.js +5 -17
  317. package/dist/vue/src/core/utils/deep-merge.js +24 -42
  318. package/dist/vue/src/core/utils/resolve-loader-options.js +6 -29
  319. package/dist/vue/src/policies/should-persist-on-first-visit.js +1 -4
  320. package/package.json +53 -65
  321. package/dist/next/src/core/constants/headers.js +0 -8
  322. package/dist/types/src/core/constants/headers.d.ts.map +0 -1
@@ -7,96 +7,62 @@ import { nestObjectFromPath } from '../../../../../core/messages/utils/nest-obje
7
7
  import 'intor-translator';
8
8
  import { jsonReader } from './utils/json-reader.js';
9
9
 
10
- /**
11
- * Parse locale message files into a unified Messages object (single-locale).
12
- *
13
- * - Reads JSON or custom formats (via `messagesReader`)
14
- * - Validates message structure
15
- * - Builds nested objects based on file path segments
16
- * - Deep-merges entries by namespace
17
- *
18
- * @example
19
- * ```plain
20
- * File paths:
21
- * - en/index.json = { a: "A" }
22
- * - en/ui.json = { b: "B" }
23
- * - en/auth/index.json = { c: "C" }
24
- * - en/auth/verify.json = { d: "D" }
25
- *```
26
-
27
- * The final return value is a `Messages` object:
28
- * ```ts
29
- * {
30
- * a: "A",
31
- * ui: { b: "B" },
32
- * auth: {
33
- * c: "C",
34
- * verify: { d: "D" },
35
- * },
36
- * }
37
- * ```
38
- */
39
- async function parseFileEntries({ fileEntries, limit, readers, loggerOptions, }) {
40
- const baseLogger = getLogger(loggerOptions);
41
- const logger = baseLogger.child({ scope: "parse-file-entries" });
42
- // Read and parse all file entries
43
- const parsedFileEntries = [];
44
- const tasks = fileEntries.map(({ namespace, segments, basename, fullPath }) => limit(async () => {
45
- try {
46
- // -------------------------------------------------------------------
47
- // Read and validate file content
48
- // -------------------------------------------------------------------
49
- const ext = path.extname(fullPath).slice(1); // remove dot
50
- let raw;
51
- if (ext === "json") {
52
- raw = await jsonReader(fullPath);
53
- }
54
- else {
55
- const reader = readers?.[ext];
56
- if (!reader) {
57
- throw new Error(`No message reader registered for .${ext} files. ` +
58
- `Please register a reader for the "${ext}" extension.`);
59
- }
60
- raw = await reader(fullPath);
61
- }
62
- // Validate messages structure
63
- if (!isValidMessages(raw)) {
64
- throw new Error("Parsed content does not match expected Messages structure");
65
- }
66
- // -------------------------------------------------------------------
67
- // Build nested message object from path segments
68
- // -------------------------------------------------------------------
69
- const segmentsWithoutNamespace = segments.slice(1);
70
- const isIndexFile = basename === "index";
71
- const keyPath = isIndexFile
72
- ? segmentsWithoutNamespace.slice(0, -1)
73
- : segmentsWithoutNamespace;
74
- // Nest the parsed content based on the path segments
75
- const nestedMessages = nestObjectFromPath(keyPath, raw);
76
- parsedFileEntries.push({ namespace, messages: nestedMessages });
77
- }
78
- catch (error) {
79
- logger.warn("Failed to read or parse file.", {
80
- path: fullPath,
81
- error,
82
- });
83
- }
84
- }));
85
- await Promise.all(tasks);
86
- // ---------------------------------------------------------------------------
87
- // Merge parsed entries by namespace
88
- // ---------------------------------------------------------------------------
89
- const result = {};
90
- for (const { namespace, messages } of parsedFileEntries) {
91
- // Root-level namespace (e.g. [locale]/index.json)
92
- if (namespace === "index") {
93
- Object.assign(result, deepMerge(result, messages));
10
+ async function parseFileEntries({
11
+ fileEntries,
12
+ limit,
13
+ readers,
14
+ loggerOptions
15
+ }) {
16
+ const baseLogger = getLogger(loggerOptions);
17
+ const logger = baseLogger.child({ scope: "parse-file-entries" });
18
+ const parsedFileEntries = [];
19
+ const tasks = fileEntries.map(
20
+ ({ namespace, segments, basename, fullPath }) => limit(async () => {
21
+ try {
22
+ const ext = path.extname(fullPath).slice(1);
23
+ let raw;
24
+ if (ext === "json") {
25
+ raw = await jsonReader(fullPath);
26
+ } else {
27
+ const reader = readers?.[ext];
28
+ if (!reader) {
29
+ throw new Error(
30
+ `No message reader registered for .${ext} files. Please register a reader for the "${ext}" extension.`
31
+ );
32
+ }
33
+ raw = await reader(fullPath);
94
34
  }
95
- else {
96
- result[namespace] = deepMerge(result[namespace], messages);
35
+ if (!isValidMessages(raw)) {
36
+ throw new Error(
37
+ "Parsed content does not match expected Messages structure"
38
+ );
97
39
  }
40
+ const segmentsWithoutNamespace = segments.slice(1);
41
+ const isIndexFile = basename === "index";
42
+ const keyPath = isIndexFile ? segmentsWithoutNamespace.slice(0, -1) : segmentsWithoutNamespace;
43
+ const nestedMessages = nestObjectFromPath(keyPath, raw);
44
+ parsedFileEntries.push({ namespace, messages: nestedMessages });
45
+ } catch (error) {
46
+ logger.warn("Failed to read or parse file.", {
47
+ path: fullPath,
48
+ error
49
+ });
50
+ }
51
+ })
52
+ );
53
+ await Promise.all(tasks);
54
+ const result = {};
55
+ for (const { namespace, messages } of parsedFileEntries) {
56
+ if (namespace === "index") {
57
+ Object.assign(result, deepMerge(result, messages));
58
+ } else {
59
+ result[namespace] = deepMerge(
60
+ result[namespace],
61
+ messages
62
+ );
98
63
  }
99
- return result;
64
+ }
65
+ return result;
100
66
  }
101
67
 
102
68
  export { parseFileEntries };
@@ -1,12 +1,9 @@
1
1
  import fs from 'node:fs/promises';
2
2
 
3
- /**
4
- * Read & parse a JSON file
5
- */
6
3
  async function jsonReader(filePath, readFile = fs.readFile) {
7
- const raw = await readFile(filePath, "utf8");
8
- const parsed = JSON.parse(raw);
9
- return parsed;
4
+ const raw = await readFile(filePath, "utf8");
5
+ const parsed = JSON.parse(raw);
6
+ return parsed;
10
7
  }
11
8
 
12
9
  export { jsonReader };
@@ -2,41 +2,29 @@ import path from 'node:path';
2
2
  import { collectFileEntries } from './collect-file-entries/collect-file-entries.js';
3
3
  import { parseFileEntries } from './parse-file-entries/parse-file-entries.js';
4
4
 
5
- /**
6
- * Read and assemble messages for a single locale from the file system.
7
- *
8
- * This function acts as a thin orchestration layer:
9
- * - Collects message file metadata for the locale
10
- * - Parses files into a single Messages object
11
- * - Wraps the result under the locale key
12
- *
13
- * It does not perform validation or transformation itself.
14
- */
15
- const readLocaleMessages = async ({ locale, namespaces, rootDir = "messages", limit, readers, loggerOptions, }) => {
16
- // ---------------------------------------------------------------------------
17
- // Collect message file entries for the locale
18
- // ---------------------------------------------------------------------------
19
- const fileEntries = await collectFileEntries({
20
- ...(namespaces !== undefined ? { namespaces } : {}),
21
- rootDir: path.resolve(rootDir, locale),
22
- limit,
23
- exts: Object.keys(readers || {}),
24
- loggerOptions,
25
- });
26
- // ---------------------------------------------------------------------------
27
- // Parse collected files into a Messages object (single-locale)
28
- // ---------------------------------------------------------------------------
29
- const messages = await parseFileEntries({
30
- fileEntries,
31
- limit,
32
- readers: readers ?? {},
33
- loggerOptions,
34
- });
35
- // ---------------------------------------------------------------------------
36
- // Wrap parsed messages under the locale key
37
- // ---------------------------------------------------------------------------
38
- const localeMessages = { [locale]: messages };
39
- return localeMessages;
5
+ const readLocaleMessages = async ({
6
+ locale,
7
+ namespaces,
8
+ rootDir = "messages",
9
+ limit,
10
+ readers,
11
+ loggerOptions
12
+ }) => {
13
+ const fileEntries = await collectFileEntries({
14
+ ...namespaces !== void 0 ? { namespaces } : {},
15
+ rootDir: path.resolve(rootDir, locale),
16
+ limit,
17
+ exts: Object.keys(readers || {}),
18
+ loggerOptions
19
+ });
20
+ const messages = await parseFileEntries({
21
+ fileEntries,
22
+ limit,
23
+ readers: readers ?? {},
24
+ loggerOptions
25
+ });
26
+ const localeMessages = { [locale]: messages };
27
+ return localeMessages;
40
28
  };
41
29
 
42
30
  export { readLocaleMessages };
@@ -4,76 +4,63 @@ import { loadRemoteMessages } from '../../core/messages/load-remote-messages/loa
4
4
  import 'intor-translator';
5
5
  import { loadLocalMessages } from './load-local-messages/load-local-messages.js';
6
6
 
7
- /**
8
- * Load locale messages according to the resolved Intor loader configuration.
9
- *
10
- * This function is the top-level orchestration entry for message loading.
11
- * It is responsible for:
12
- *
13
- * - Resolving the active loader strategy (local or remote)
14
- * - Dispatching to the appropriate loader implementation
15
- * - Passing through cache and read-related options
16
- *
17
- * Message traversal, parsing, fallback resolution, and caching logic
18
- * are delegated to the selected loader.
19
- */
20
- const loadMessages = async ({ config, locale, readers, allowCacheWrite = false, fetch, }) => {
21
- const baseLogger = getLogger(config.logger);
22
- const logger = baseLogger.child({ scope: "load-messages" });
23
- // ---------------------------------------------------------------------------
24
- // Resolve loader configuration
25
- // ---------------------------------------------------------------------------
26
- const loader = resolveLoaderOptions(config, "server");
27
- if (!loader) {
28
- logger.warn("No loader options have been configured in the current config.");
29
- return;
30
- }
31
- const { mode, namespaces, concurrency } = loader;
32
- const fallbackLocales = config.fallbackLocales[locale] || [];
33
- logger.info(`Loading messages for locale "${locale}".`);
34
- logger.trace("Starting to load messages with runtime context.", {
35
- loaderMode: mode,
36
- ...(mode === "local" ? { rootDir: loader.rootDir } : {}),
37
- locale,
38
- fallbackLocales: fallbackLocales.join(", "),
39
- namespaces: namespaces && namespaces.length > 0 ? [...namespaces] : "*",
7
+ const loadMessages = async ({
8
+ config,
9
+ locale,
10
+ readers,
11
+ allowCacheWrite = false,
12
+ fetch
13
+ }) => {
14
+ const baseLogger = getLogger(config.logger);
15
+ const logger = baseLogger.child({ scope: "load-messages" });
16
+ const loader = resolveLoaderOptions(config, "server");
17
+ if (!loader) {
18
+ logger.warn(
19
+ "No loader options have been configured in the current config."
20
+ );
21
+ return;
22
+ }
23
+ const { mode, namespaces, concurrency } = loader;
24
+ const fallbackLocales = config.fallbackLocales[locale] || [];
25
+ logger.info(`Loading messages for locale "${locale}".`);
26
+ logger.trace("Starting to load messages with runtime context.", {
27
+ loaderMode: mode,
28
+ ...mode === "local" ? { rootDir: loader.rootDir } : {},
29
+ locale,
30
+ fallbackLocales: fallbackLocales.join(", "),
31
+ namespaces: namespaces && namespaces.length > 0 ? [...namespaces] : "*"
32
+ });
33
+ let loadedMessages;
34
+ if (mode === "local") {
35
+ const { rootDir } = loader;
36
+ loadedMessages = await loadLocalMessages({
37
+ id: config.id,
38
+ locale,
39
+ fallbackLocales,
40
+ ...namespaces !== void 0 ? { namespaces } : {},
41
+ ...rootDir !== void 0 ? { rootDir } : {},
42
+ ...concurrency !== void 0 ? { concurrency } : {},
43
+ readers: readers ?? {},
44
+ allowCacheWrite,
45
+ loggerOptions: config.logger
40
46
  });
41
- // ---------------------------------------------------------------------------
42
- // Dispatch to loader implementation
43
- // ---------------------------------------------------------------------------
44
- let loadedMessages;
45
- if (mode === "local") {
46
- const { rootDir } = loader;
47
- loadedMessages = await loadLocalMessages({
48
- id: config.id,
49
- locale,
50
- fallbackLocales,
51
- ...(namespaces !== undefined ? { namespaces } : {}),
52
- ...(rootDir !== undefined ? { rootDir } : {}),
53
- ...(concurrency !== undefined ? { concurrency } : {}),
54
- readers: readers ?? {},
55
- allowCacheWrite,
56
- loggerOptions: config.logger,
57
- });
58
- }
59
- else if (mode === "remote") {
60
- const { url, headers } = loader;
61
- loadedMessages = await loadRemoteMessages({
62
- locale,
63
- fallbackLocales,
64
- ...(namespaces !== undefined ? { namespaces } : {}),
65
- ...(concurrency !== undefined ? { concurrency } : {}),
66
- fetch,
67
- url,
68
- ...(headers !== undefined ? { headers } : {}),
69
- loggerOptions: config.logger,
70
- });
71
- }
72
- // Final sanity check
73
- if (!loadedMessages || Object.keys(loadedMessages).length === 0) {
74
- logger.warn("No messages found.", { locale, fallbackLocales, namespaces });
75
- }
76
- return loadedMessages;
47
+ } else if (mode === "remote") {
48
+ const { url, headers } = loader;
49
+ loadedMessages = await loadRemoteMessages({
50
+ locale,
51
+ fallbackLocales,
52
+ ...namespaces !== void 0 ? { namespaces } : {},
53
+ ...concurrency !== void 0 ? { concurrency } : {},
54
+ fetch,
55
+ url,
56
+ ...headers !== void 0 ? { headers } : {},
57
+ loggerOptions: config.logger
58
+ });
59
+ }
60
+ if (!loadedMessages || Object.keys(loadedMessages).length === 0) {
61
+ logger.warn("No messages found.", { locale, fallbackLocales, namespaces });
62
+ }
63
+ return loadedMessages;
77
64
  };
78
65
 
79
66
  export { loadMessages };
@@ -7,38 +7,36 @@ import { loadMessages } from '../messages/load-messages.js';
7
7
  import 'node:path';
8
8
  import 'node:fs/promises';
9
9
 
10
- /**
11
- * Initialize a locale-bound Translator snapshot.
12
- *
13
- * - Resolves loader options and loads messages if configured
14
- * - Creates an immutable Translator instance for server usage
15
- */
16
10
  async function initTranslator(config, locale, options) {
17
- const { loader, readers, allowCacheWrite = false, fetch, handlers, hooks, } = options;
18
- const loaderOptions = resolveLoaderOptions(config, "server");
19
- // Load messages
20
- let messages = {};
21
- if (loader) {
22
- messages = await loader(config, locale);
23
- }
24
- else if (loaderOptions) {
25
- const loaded = await loadMessages({
26
- config,
27
- locale,
28
- ...(readers !== undefined ? { readers } : {}),
29
- allowCacheWrite,
30
- fetch,
31
- });
32
- messages = loaded || {};
33
- }
34
- // Create immutable translator snapshot
35
- return createTranslator({
36
- config,
37
- locale,
38
- messages,
39
- ...(handlers !== undefined ? { handlers } : {}),
40
- ...(hooks !== undefined ? { hooks } : {}),
11
+ const {
12
+ loader,
13
+ readers,
14
+ allowCacheWrite = false,
15
+ fetch,
16
+ handlers,
17
+ hooks
18
+ } = options;
19
+ const loaderOptions = resolveLoaderOptions(config, "server");
20
+ let messages = {};
21
+ if (loader) {
22
+ messages = await loader(config, locale);
23
+ } else if (loaderOptions) {
24
+ const loaded = await loadMessages({
25
+ config,
26
+ locale,
27
+ ...readers !== void 0 ? { readers } : {},
28
+ allowCacheWrite,
29
+ fetch
41
30
  });
31
+ messages = loaded || {};
32
+ }
33
+ return createTranslator({
34
+ config,
35
+ locale,
36
+ messages,
37
+ ...handlers !== void 0 ? { handlers } : {},
38
+ ...hooks !== void 0 ? { hooks } : {}
39
+ });
42
40
  }
43
41
 
44
42
  export { initTranslator };
@@ -7,53 +7,42 @@ import 'intor-translator';
7
7
  import { resolveInbound } from '../../routing/inbound/resolve-inbound.js';
8
8
  import { getLocaleFromAcceptLanguage } from '../../routing/locale/get-locale-from-accept-language.js';
9
9
 
10
- /**
11
- * Resolves locale-aware routing for the current execution context.
12
- *
13
- * - Binds resolved routing state to the request.
14
- * - Optionally binds convenience routing shortcuts for downstream consumption.
15
- *
16
- * @public
17
- */
18
10
  function createIntorHandler(config, options) {
19
- return async function intorHandler(req, _res, next) {
20
- // Locale from Accept-Language header
21
- const acceptLanguage = req.headers["accept-language"];
22
- const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(acceptLanguage, config.supportedLocales);
23
- // ----------------------------------------------------------
24
- // Resolve inbound routing decision (pure computation)
25
- // ----------------------------------------------------------
26
- const cookie = parseCookieHeader(req.headers.cookie)[config.cookie.name];
27
- const { locale, localeSource, pathname } = resolveInbound(config, req.path, {
28
- host: req.hostname,
29
- query: normalizeQuery(req.query),
30
- ...(cookie !== undefined ? { cookie } : {}),
31
- ...(localeFromAcceptLanguage !== undefined
32
- ? { detected: localeFromAcceptLanguage }
33
- : {}),
34
- });
35
- // --------------------------------------------------
36
- // Bind inbound routing context
37
- // --------------------------------------------------
38
- req.intor = { locale, localeSource, pathname };
39
- const { loader, readers, handlers, hooks } = options ?? {};
40
- const { hasKey, t, tRich } = await getTranslator(config, {
41
- locale,
42
- ...(loader !== undefined ? { loader } : {}),
43
- ...(readers !== undefined ? { readers } : {}),
44
- allowCacheWrite: true,
45
- ...(handlers !== undefined ? { handlers } : {}),
46
- ...(hooks !== undefined ? { hooks } : {}),
47
- });
48
- // DX shortcuts (enabled by default)
49
- if (options?.shortcuts !== false) {
50
- req.locale = locale;
51
- req.hasKey = hasKey;
52
- req.t = t;
53
- req.tRich = tRich;
54
- }
55
- return next();
56
- };
11
+ return async function intorHandler(req, _res, next) {
12
+ const acceptLanguage = req.headers["accept-language"];
13
+ const localeFromAcceptLanguage = getLocaleFromAcceptLanguage(
14
+ acceptLanguage,
15
+ config.supportedLocales
16
+ );
17
+ const cookie = parseCookieHeader(req.headers.cookie)[config.cookie.name];
18
+ const { locale, localeSource, pathname } = resolveInbound(
19
+ config,
20
+ req.path,
21
+ {
22
+ host: req.hostname,
23
+ query: normalizeQuery(req.query),
24
+ ...cookie !== void 0 ? { cookie } : {},
25
+ ...localeFromAcceptLanguage !== void 0 ? { detected: localeFromAcceptLanguage } : {}
26
+ }
27
+ );
28
+ req.intor = { locale, localeSource, pathname };
29
+ const { loader, readers, handlers, hooks } = options ?? {};
30
+ const { hasKey, t, tRich } = await getTranslator(config, {
31
+ locale,
32
+ ...loader !== void 0 ? { loader } : {},
33
+ ...readers !== void 0 ? { readers } : {},
34
+ allowCacheWrite: true,
35
+ ...handlers !== void 0 ? { handlers } : {},
36
+ ...hooks !== void 0 ? { hooks } : {}
37
+ });
38
+ if (options?.shortcuts !== false) {
39
+ req.locale = locale;
40
+ req.hasKey = hasKey;
41
+ req.t = t;
42
+ req.tRich = tRich;
43
+ }
44
+ return next();
45
+ };
57
46
  }
58
47
 
59
48
  export { createIntorHandler };
@@ -1,15 +1,8 @@
1
1
  import { getTranslator as getTranslator$1 } from 'intor/server';
2
2
 
3
- /**
4
- * Get a server-side translator for the current execution context.
5
- *
6
- * - Automatically resolves the locale from the framework context.
7
- *
8
- * @public
9
- */
10
3
  async function getTranslator(config, req, params) {
11
- const locale = req.intor?.locale ?? config.defaultLocale;
12
- return getTranslator$1(config, { locale, ...(params ?? {}) });
4
+ const locale = req.intor?.locale ?? config.defaultLocale;
5
+ return getTranslator$1(config, { locale, ...params ?? {} });
13
6
  }
14
7
 
15
8
  export { getTranslator };
@@ -1,4 +1,3 @@
1
- // Default locale placeholder
2
1
  const LOCALE_PLACEHOLDER = "{locale}";
3
2
 
4
3
  export { LOCALE_PLACEHOLDER };
@@ -1,23 +1,12 @@
1
- /**
2
- * Canonicalizes a BCP 47 locale string.
3
- *
4
- * - Uses `Intl.getCanonicalLocales` when available.
5
- * - Returns the original input if `Intl` is unavailable.
6
- * - Returns `undefined` for invalid locale input.
7
- *
8
- * This function performs normalization only.
9
- * It does not perform matching or fallback.
10
- */
11
1
  function canonicalizeLocale(input) {
12
- try {
13
- if (typeof Intl === "undefined" || !Intl.getCanonicalLocales) {
14
- return input;
15
- }
16
- return Intl.getCanonicalLocales(input)[0];
17
- }
18
- catch {
19
- return;
2
+ try {
3
+ if (typeof Intl === "undefined" || !Intl.getCanonicalLocales) {
4
+ return input;
20
5
  }
6
+ return Intl.getCanonicalLocales(input)[0];
7
+ } catch {
8
+ return;
9
+ }
21
10
  }
22
11
 
23
12
  export { canonicalizeLocale };