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.
- package/dist/core/src/client/shared/helpers/get-client-locale.js +5 -20
- package/dist/core/src/client/shared/utils/locale/detect-browser-locale.js +2 -8
- package/dist/core/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
- package/dist/core/src/config/constants/cookie.js +9 -9
- package/dist/core/src/config/constants/routing.js +13 -14
- package/dist/core/src/config/define-intor-config.js +28 -44
- package/dist/core/src/config/resolvers/resolve-cookie-options.js +4 -4
- package/dist/core/src/config/resolvers/resolve-fallback-locales.js +33 -50
- package/dist/core/src/config/resolvers/resolve-routing-options.js +32 -61
- package/dist/core/src/config/validators/validate-default-locale.js +8 -13
- package/dist/core/src/config/validators/validate-id.js +8 -13
- package/dist/core/src/config/validators/validate-supported-locales.js +8 -13
- package/dist/core/src/core/constants/locale-placeholder.js +0 -1
- package/dist/core/src/core/error/intor-error.js +14 -29
- package/dist/core/src/core/locale/canonicalize-locale.js +7 -18
- package/dist/core/src/core/locale/match-locale.js +24 -50
- package/dist/core/src/core/locale/parse-locale.js +12 -22
- package/dist/core/src/core/logger/get-logger.js +26 -31
- package/dist/core/src/core/logger/global-logger-pool.js +4 -4
- package/dist/core/src/core/messages/internal-metadata.js +1 -1
- package/dist/core/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
- package/dist/core/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
- package/dist/core/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
- package/dist/core/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
- package/dist/core/src/core/messages/merge-messages.js +17 -28
- package/dist/core/src/core/messages/utils/is-valid-messages.js +22 -37
- package/dist/core/src/core/messages/utils/nest-object-from-path.js +5 -17
- package/dist/core/src/core/render/create-html-renderer.js +29 -37
- package/dist/core/src/core/render/utils/escape-html.js +1 -6
- package/dist/core/src/core/render/utils/render-attributes.js +6 -11
- package/dist/core/src/core/translator/create-t-rich.js +6 -15
- package/dist/core/src/core/translator/create-translator.js +16 -24
- package/dist/core/src/core/utils/deep-merge.js +24 -42
- package/dist/core/src/core/utils/normalizers/normalize-cache-key.js +14 -40
- package/dist/core/src/core/utils/normalizers/normalize-pathname.js +19 -37
- package/dist/core/src/core/utils/normalizers/normalize-query.js +6 -20
- package/dist/core/src/core/utils/parse-cookie-header.js +11 -18
- package/dist/core/src/core/utils/resolve-loader-options.js +6 -32
- package/dist/core/src/edge/helpers/get-translator.js +14 -20
- package/dist/core/src/edge/translator/init-translator.js +23 -31
- package/dist/core/src/routing/inbound/helpers/resolve-inbound-from-request.js +21 -28
- package/dist/core/src/routing/inbound/resolve-inbound.js +22 -37
- package/dist/core/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
- package/dist/core/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
- package/dist/core/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
- package/dist/core/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
- package/dist/core/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
- package/dist/core/src/routing/locale/get-locale-from-accept-language.js +21 -36
- package/dist/core/src/routing/locale/get-locale-from-host.js +5 -28
- package/dist/core/src/routing/locale/get-locale-from-pathname.js +11 -37
- package/dist/core/src/routing/locale/get-locale-from-query.js +2 -17
- package/dist/core/src/routing/pathname/canonicalize-pathname.js +25 -67
- package/dist/core/src/routing/pathname/localize-pathname.js +12 -30
- package/dist/core/src/routing/pathname/materialize-pathname.js +9 -44
- package/dist/core/src/routing/pathname/standardize-pathname.js +6 -30
- package/dist/core/src/server/helpers/get-translator.js +26 -23
- package/dist/core/src/server/intor/intor.js +20 -25
- package/dist/core/src/server/messages/load-local-messages/cache/messages-pool.js +4 -7
- package/dist/core/src/server/messages/load-local-messages/load-local-messages.js +76 -92
- package/dist/core/src/server/messages/load-local-messages/read-locale-messages/collect-file-entries/collect-file-entries.js +59 -80
- package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/parse-file-entries.js +53 -87
- package/dist/core/src/server/messages/load-local-messages/read-locale-messages/parse-file-entries/utils/json-reader.js +3 -6
- package/dist/core/src/server/messages/load-local-messages/read-locale-messages/read-locale-messages.js +23 -35
- package/dist/core/src/server/messages/load-messages.js +56 -69
- package/dist/core/src/server/translator/init-translator.js +28 -30
- package/dist/express/src/adapters/express/create-intor-handler.js +35 -46
- package/dist/express/src/adapters/express/get-translator.js +2 -9
- package/dist/express/src/core/constants/locale-placeholder.js +0 -1
- package/dist/express/src/core/locale/canonicalize-locale.js +7 -18
- package/dist/express/src/core/locale/match-locale.js +24 -50
- package/dist/express/src/core/locale/parse-locale.js +12 -22
- package/dist/express/src/core/utils/normalizers/normalize-pathname.js +19 -37
- package/dist/express/src/core/utils/normalizers/normalize-query.js +6 -20
- package/dist/express/src/core/utils/parse-cookie-header.js +11 -18
- package/dist/express/src/routing/inbound/resolve-inbound.js +22 -37
- package/dist/express/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
- package/dist/express/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
- package/dist/express/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
- package/dist/express/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
- package/dist/express/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
- package/dist/express/src/routing/locale/get-locale-from-accept-language.js +21 -36
- package/dist/express/src/routing/locale/get-locale-from-host.js +5 -28
- package/dist/express/src/routing/locale/get-locale-from-pathname.js +11 -37
- package/dist/express/src/routing/locale/get-locale-from-query.js +2 -17
- package/dist/express/src/routing/pathname/canonicalize-pathname.js +25 -67
- package/dist/express/src/routing/pathname/localize-pathname.js +12 -30
- package/dist/express/src/routing/pathname/materialize-pathname.js +9 -44
- package/dist/express/src/routing/pathname/standardize-pathname.js +6 -30
- package/dist/fastify/src/adapters/fastify/create-intor-handler.js +35 -47
- package/dist/fastify/src/adapters/fastify/get-translator.js +2 -9
- package/dist/fastify/src/adapters/fastify/intor-fastify-plugin.js +29 -38
- package/dist/fastify/src/core/constants/locale-placeholder.js +0 -1
- package/dist/fastify/src/core/locale/canonicalize-locale.js +7 -18
- package/dist/fastify/src/core/locale/match-locale.js +24 -50
- package/dist/fastify/src/core/locale/parse-locale.js +12 -22
- package/dist/fastify/src/core/utils/normalizers/normalize-pathname.js +19 -37
- package/dist/fastify/src/core/utils/normalizers/normalize-query.js +6 -20
- package/dist/fastify/src/core/utils/parse-cookie-header.js +11 -18
- package/dist/fastify/src/routing/inbound/resolve-inbound.js +22 -37
- package/dist/fastify/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
- package/dist/fastify/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
- package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
- package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
- package/dist/fastify/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
- package/dist/fastify/src/routing/locale/get-locale-from-accept-language.js +21 -36
- package/dist/fastify/src/routing/locale/get-locale-from-host.js +5 -28
- package/dist/fastify/src/routing/locale/get-locale-from-pathname.js +11 -37
- package/dist/fastify/src/routing/locale/get-locale-from-query.js +2 -17
- package/dist/fastify/src/routing/pathname/canonicalize-pathname.js +25 -67
- package/dist/fastify/src/routing/pathname/localize-pathname.js +12 -30
- package/dist/fastify/src/routing/pathname/materialize-pathname.js +9 -44
- package/dist/fastify/src/routing/pathname/standardize-pathname.js +6 -30
- package/dist/hono/src/adapters/hono/create-intor-handler.js +33 -44
- package/dist/hono/src/adapters/hono/get-translator.js +2 -9
- package/dist/hono/src/core/constants/locale-placeholder.js +0 -1
- package/dist/hono/src/core/locale/canonicalize-locale.js +7 -18
- package/dist/hono/src/core/locale/match-locale.js +24 -50
- package/dist/hono/src/core/locale/parse-locale.js +12 -22
- package/dist/hono/src/core/utils/normalizers/normalize-pathname.js +19 -37
- package/dist/hono/src/core/utils/normalizers/normalize-query.js +6 -20
- package/dist/hono/src/core/utils/parse-cookie-header.js +11 -18
- package/dist/hono/src/routing/inbound/resolve-inbound.js +22 -37
- package/dist/hono/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
- package/dist/hono/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
- package/dist/hono/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
- package/dist/hono/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
- package/dist/hono/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
- package/dist/hono/src/routing/locale/get-locale-from-accept-language.js +21 -36
- package/dist/hono/src/routing/locale/get-locale-from-host.js +5 -28
- package/dist/hono/src/routing/locale/get-locale-from-pathname.js +11 -37
- package/dist/hono/src/routing/locale/get-locale-from-query.js +2 -17
- package/dist/hono/src/routing/pathname/canonicalize-pathname.js +25 -67
- package/dist/hono/src/routing/pathname/localize-pathname.js +12 -30
- package/dist/hono/src/routing/pathname/materialize-pathname.js +9 -44
- package/dist/hono/src/routing/pathname/standardize-pathname.js +6 -30
- package/dist/next/src/adapters/next/create-intor-handler.js +29 -47
- package/dist/next/src/adapters/next/link.js +33 -28
- package/dist/next/src/adapters/next/redirect.js +12 -15
- package/dist/next/src/adapters/next/server/get-locale.js +12 -23
- package/dist/next/src/adapters/next/server/get-translator.js +2 -9
- package/dist/next/src/adapters/next/server/intor.js +5 -13
- package/dist/next/src/adapters/next/use-router.js +47 -66
- package/dist/next/src/client/shared/navigation/execute-navigation.js +20 -38
- package/dist/next/src/client/shared/utils/build-cookie-string.js +18 -27
- package/dist/next/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
- package/dist/next/src/core/constants/headers.js +4 -4
- package/dist/next/src/core/constants/locale-placeholder.js +0 -1
- package/dist/next/src/core/locale/canonicalize-locale.js +7 -18
- package/dist/next/src/core/locale/match-locale.js +24 -50
- package/dist/next/src/core/locale/parse-locale.js +12 -22
- package/dist/next/src/core/utils/normalizers/normalize-pathname.js +19 -37
- package/dist/next/src/core/utils/normalizers/normalize-query.js +6 -20
- package/dist/next/src/core/utils/resolve-loader-options.js +6 -29
- package/dist/next/src/policies/shoud-full-reload.js +2 -5
- package/dist/next/src/policies/should-sync-locale.js +1 -4
- package/dist/next/src/routing/inbound/resolve-inbound.js +24 -39
- package/dist/next/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
- package/dist/next/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
- package/dist/next/src/routing/inbound/resolve-pathname/strategies/all.js +13 -29
- package/dist/next/src/routing/inbound/resolve-pathname/strategies/except-default.js +14 -30
- package/dist/next/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
- package/dist/next/src/routing/locale/get-locale-from-accept-language.js +21 -36
- package/dist/next/src/routing/locale/get-locale-from-host.js +5 -28
- package/dist/next/src/routing/locale/get-locale-from-pathname.js +11 -37
- package/dist/next/src/routing/locale/get-locale-from-query.js +2 -17
- package/dist/next/src/routing/outbound/decide-strategy.js +9 -9
- package/dist/next/src/routing/outbound/determine-target.js +28 -44
- package/dist/next/src/routing/outbound/resolve-outbound.js +12 -16
- package/dist/next/src/routing/outbound/utils/derive-host-destination.js +5 -9
- package/dist/next/src/routing/outbound/utils/derive-query-destination.js +4 -7
- package/dist/next/src/routing/outbound/utils/is-external-destination.js +1 -7
- package/dist/next/src/routing/pathname/canonicalize-pathname.js +25 -67
- package/dist/next/src/routing/pathname/localize-pathname.js +12 -30
- package/dist/next/src/routing/pathname/materialize-pathname.js +9 -44
- package/dist/next/src/routing/pathname/standardize-pathname.js +6 -30
- package/dist/react/src/client/react/helpers/use-intor.js +25 -44
- package/dist/react/src/client/react/provider/effects/use-locale-effects.js +20 -25
- package/dist/react/src/client/react/provider/effects/use-messages-effects.js +17 -16
- package/dist/react/src/client/react/provider/intor-provider.js +63 -66
- package/dist/react/src/client/react/provider/use-intor-context.js +4 -4
- package/dist/react/src/client/react/render/create-react-renderer.js +18 -24
- package/dist/react/src/client/react/translator/create-t-rich.js +9 -22
- package/dist/react/src/client/react/translator/use-translator.js +11 -16
- package/dist/react/src/client/shared/messages/create-refetch-messages.js +41 -51
- package/dist/react/src/client/shared/provider/effective-state.js +2 -6
- package/dist/react/src/client/shared/utils/build-cookie-string.js +18 -27
- package/dist/react/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
- package/dist/react/src/client/shared/utils/locale/set-document-locale.js +2 -8
- package/dist/react/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
- package/dist/react/src/core/logger/get-logger.js +26 -31
- package/dist/react/src/core/logger/global-logger-pool.js +4 -4
- package/dist/react/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
- package/dist/react/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
- package/dist/react/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
- package/dist/react/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
- package/dist/react/src/core/messages/merge-messages.js +17 -28
- package/dist/react/src/core/messages/utils/is-valid-messages.js +22 -37
- package/dist/react/src/core/messages/utils/nest-object-from-path.js +5 -17
- package/dist/react/src/core/utils/deep-merge.js +24 -42
- package/dist/react/src/core/utils/resolve-loader-options.js +6 -29
- package/dist/react/src/policies/should-persist-on-first-visit.js +1 -4
- package/dist/svelte/export/svelte/index.js +0 -6
- package/dist/svelte/src/client/shared/messages/create-refetch-messages.js +41 -51
- package/dist/svelte/src/client/shared/provider/effective-state.js +2 -6
- package/dist/svelte/src/client/shared/utils/build-cookie-string.js +18 -27
- package/dist/svelte/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
- package/dist/svelte/src/client/shared/utils/locale/set-document-locale.js +2 -8
- package/dist/svelte/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
- package/dist/svelte/src/client/svelte/provider/create-intor-store.js +59 -63
- package/dist/svelte/src/client/svelte/provider/effects/attach-locale-effects.js +20 -25
- package/dist/svelte/src/client/svelte/provider/effects/attach-messages-effects.js +21 -18
- package/dist/svelte/src/client/svelte/provider/get-intor-context.js +4 -4
- package/dist/svelte/src/client/svelte/translator/use-translator.js +11 -16
- package/dist/svelte/src/core/logger/get-logger.js +26 -31
- package/dist/svelte/src/core/logger/global-logger-pool.js +4 -4
- package/dist/svelte/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
- package/dist/svelte/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
- package/dist/svelte/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
- package/dist/svelte/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
- package/dist/svelte/src/core/messages/merge-messages.js +17 -28
- package/dist/svelte/src/core/messages/utils/is-valid-messages.js +22 -37
- package/dist/svelte/src/core/messages/utils/nest-object-from-path.js +5 -17
- package/dist/svelte/src/core/render/create-html-renderer.js +29 -37
- package/dist/svelte/src/core/render/utils/escape-html.js +1 -6
- package/dist/svelte/src/core/render/utils/render-attributes.js +6 -11
- package/dist/svelte/src/core/translator/create-t-rich.js +6 -15
- package/dist/svelte/src/core/utils/deep-merge.js +24 -42
- package/dist/svelte/src/core/utils/resolve-loader-options.js +6 -29
- package/dist/svelte/src/policies/should-persist-on-first-visit.js +1 -4
- package/dist/svelte-kit/src/adapters/svelte-kit/create-intor-handler.js +37 -57
- package/dist/svelte-kit/src/adapters/svelte-kit/use-navigation.js +29 -27
- package/dist/svelte-kit/src/adapters/svelte-kit/utils/is-svelte-kit-ssg.js +4 -11
- package/dist/svelte-kit/src/client/shared/navigation/execute-navigation.js +19 -37
- package/dist/svelte-kit/src/client/shared/utils/build-cookie-string.js +18 -27
- package/dist/svelte-kit/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
- package/dist/svelte-kit/src/core/constants/locale-placeholder.js +0 -1
- package/dist/svelte-kit/src/core/locale/canonicalize-locale.js +7 -18
- package/dist/svelte-kit/src/core/locale/match-locale.js +24 -50
- package/dist/svelte-kit/src/core/locale/parse-locale.js +12 -22
- package/dist/svelte-kit/src/core/utils/normalizers/normalize-pathname.js +19 -37
- package/dist/svelte-kit/src/core/utils/normalizers/normalize-query.js +6 -20
- package/dist/svelte-kit/src/core/utils/resolve-loader-options.js +6 -29
- package/dist/svelte-kit/src/policies/shoud-full-reload.js +2 -5
- package/dist/svelte-kit/src/policies/should-sync-locale.js +1 -4
- package/dist/svelte-kit/src/routing/inbound/resolve-inbound.js +22 -37
- package/dist/svelte-kit/src/routing/inbound/resolve-locale/resolve-locale.js +22 -39
- package/dist/svelte-kit/src/routing/inbound/resolve-pathname/resolve-pathname.js +24 -30
- package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/all.js +10 -23
- package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/except-default.js +11 -24
- package/dist/svelte-kit/src/routing/inbound/resolve-pathname/strategies/none.js +1 -4
- package/dist/svelte-kit/src/routing/locale/get-locale-from-accept-language.js +21 -36
- package/dist/svelte-kit/src/routing/locale/get-locale-from-host.js +5 -28
- package/dist/svelte-kit/src/routing/locale/get-locale-from-pathname.js +11 -37
- package/dist/svelte-kit/src/routing/locale/get-locale-from-query.js +2 -17
- package/dist/svelte-kit/src/routing/outbound/decide-strategy.js +9 -9
- package/dist/svelte-kit/src/routing/outbound/determine-target.js +28 -44
- package/dist/svelte-kit/src/routing/outbound/resolve-outbound.js +12 -16
- package/dist/svelte-kit/src/routing/outbound/utils/derive-host-destination.js +5 -9
- package/dist/svelte-kit/src/routing/outbound/utils/derive-query-destination.js +4 -7
- package/dist/svelte-kit/src/routing/outbound/utils/is-external-destination.js +1 -7
- package/dist/svelte-kit/src/routing/pathname/canonicalize-pathname.js +25 -67
- package/dist/svelte-kit/src/routing/pathname/localize-pathname.js +12 -30
- package/dist/svelte-kit/src/routing/pathname/materialize-pathname.js +9 -44
- package/dist/svelte-kit/src/routing/pathname/standardize-pathname.js +6 -30
- package/dist/types/src/routing/outbound/decide-strategy.d.ts +1 -1
- package/dist/types/src/routing/outbound/decide-strategy.d.ts.map +1 -1
- package/dist/vue/src/client/shared/messages/create-refetch-messages.js +41 -51
- package/dist/vue/src/client/shared/provider/effective-state.js +2 -6
- package/dist/vue/src/client/shared/utils/build-cookie-string.js +18 -27
- package/dist/vue/src/client/shared/utils/locale/get-locale-from-cookie.js +5 -12
- package/dist/vue/src/client/shared/utils/locale/set-document-locale.js +2 -8
- package/dist/vue/src/client/shared/utils/locale/set-locale-cookie.js +2 -9
- package/dist/vue/src/client/vue/helpers/use-intor.js +20 -42
- package/dist/vue/src/client/vue/provider/effects/use-locale-effects.js +23 -24
- package/dist/vue/src/client/vue/provider/effects/use-messages-effects.js +15 -24
- package/dist/vue/src/client/vue/provider/inject-intor-context.js +4 -4
- package/dist/vue/src/client/vue/provider/intor-provider.js +61 -66
- package/dist/vue/src/client/vue/render/create-vue-renderer.js +18 -24
- package/dist/vue/src/client/vue/translator/create-t-rich.js +5 -17
- package/dist/vue/src/client/vue/translator/trans.js +24 -31
- package/dist/vue/src/client/vue/translator/use-translator.js +12 -17
- package/dist/vue/src/core/logger/get-logger.js +26 -31
- package/dist/vue/src/core/logger/global-logger-pool.js +4 -4
- package/dist/vue/src/core/messages/load-remote-messages/collect-remote-resources.js +13 -22
- package/dist/vue/src/core/messages/load-remote-messages/fetch-remote-resource.js +30 -39
- package/dist/vue/src/core/messages/load-remote-messages/load-remote-messages.js +72 -89
- package/dist/vue/src/core/messages/load-remote-messages/resolve-remote-resources.js +7 -17
- package/dist/vue/src/core/messages/merge-messages.js +17 -28
- package/dist/vue/src/core/messages/utils/is-valid-messages.js +22 -37
- package/dist/vue/src/core/messages/utils/nest-object-from-path.js +5 -17
- package/dist/vue/src/core/utils/deep-merge.js +24 -42
- package/dist/vue/src/core/utils/resolve-loader-options.js +6 -29
- package/dist/vue/src/policies/should-persist-on-first-visit.js +1 -4
- package/package.json +2 -2
|
@@ -5,27 +5,12 @@ import 'intor-translator';
|
|
|
5
5
|
import { detectBrowserLocale } from '../utils/locale/detect-browser-locale.js';
|
|
6
6
|
import { getLocaleFromCookie } from '../utils/locale/get-locale-from-cookie.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Resolve the active locale in a browser-only environment.
|
|
10
|
-
*
|
|
11
|
-
* This helper is intended for pure client-side setups where
|
|
12
|
-
* no server-side locale resolution is involved.
|
|
13
|
-
*
|
|
14
|
-
* Resolution order:
|
|
15
|
-
* 1. Locale from cookie
|
|
16
|
-
* 2. Locale from browser preference
|
|
17
|
-
* 3. Fallback to `defaultLocale`
|
|
18
|
-
*
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
21
8
|
function getClientLocale(config) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const localeCandidate = cookieLocale || browserLocale;
|
|
28
|
-
return matchLocale(localeCandidate, supportedLocales) || defaultLocale;
|
|
9
|
+
const { defaultLocale, supportedLocales, cookie } = config;
|
|
10
|
+
const cookieLocale = getLocaleFromCookie(cookie.name);
|
|
11
|
+
const browserLocale = detectBrowserLocale();
|
|
12
|
+
const localeCandidate = cookieLocale || browserLocale;
|
|
13
|
+
return matchLocale(localeCandidate, supportedLocales) || defaultLocale;
|
|
29
14
|
}
|
|
30
15
|
|
|
31
16
|
export { getClientLocale };
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Detect the preferred locale from the browser.
|
|
3
|
-
*
|
|
4
|
-
* This function relies on `navigator.languages` and `navigator.language`.
|
|
5
|
-
*/
|
|
6
1
|
function detectBrowserLocale() {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
return navigator.languages?.[0] || navigator.language || undefined;
|
|
2
|
+
if (typeof navigator === "undefined") return void 0;
|
|
3
|
+
return navigator.languages?.[0] || navigator.language || void 0;
|
|
10
4
|
}
|
|
11
5
|
|
|
12
6
|
export { detectBrowserLocale };
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the locale value from the browser cookie.
|
|
3
|
-
*
|
|
4
|
-
* This function relies on `document.cookie`.
|
|
5
|
-
*/
|
|
6
1
|
function getLocaleFromCookie(cookieName) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return undefined;
|
|
13
|
-
return decodeURIComponent(entry.slice(cookieName.length + 1));
|
|
2
|
+
if (typeof document === "undefined") return void 0;
|
|
3
|
+
const cookies = document.cookie.split(";").map((c) => c.trim());
|
|
4
|
+
const entry = cookies.find((c) => c.startsWith(`${cookieName}=`));
|
|
5
|
+
if (!entry) return void 0;
|
|
6
|
+
return decodeURIComponent(entry.slice(cookieName.length + 1));
|
|
14
7
|
}
|
|
15
8
|
|
|
16
9
|
export { getLocaleFromCookie };
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
// Default cookie options
|
|
2
1
|
const DEFAULT_COOKIE_OPTIONS = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
2
|
+
persist: true,
|
|
3
|
+
name: "intor.locale",
|
|
4
|
+
domain: void 0,
|
|
5
|
+
path: "/",
|
|
6
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
7
|
+
// 365 days
|
|
8
|
+
httpOnly: false,
|
|
9
|
+
secure: process.env["NODE_ENV"] !== "development",
|
|
10
|
+
sameSite: "lax"
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
export { DEFAULT_COOKIE_OPTIONS };
|
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
// Default routing options
|
|
2
1
|
const DEFAULT_ROUTING_OPTIONS = {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
basePath: "/",
|
|
3
|
+
localePrefix: "none",
|
|
4
|
+
inbound: {
|
|
5
|
+
localeSources: ["path", "query", "cookie", "detected"],
|
|
6
|
+
queryKey: "locale",
|
|
7
|
+
firstVisit: { localeSource: "browser", persist: true, redirect: true }
|
|
8
|
+
},
|
|
9
|
+
outbound: {
|
|
10
|
+
localeCarrier: "path",
|
|
11
|
+
queryKey: "locale",
|
|
12
|
+
host: { map: {} },
|
|
13
|
+
forceFullReload: false
|
|
14
|
+
}
|
|
16
15
|
};
|
|
17
16
|
|
|
18
17
|
export { DEFAULT_ROUTING_OPTIONS };
|
|
@@ -5,51 +5,35 @@ import { validateDefaultLocale } from './validators/validate-default-locale.js';
|
|
|
5
5
|
import { validateId } from './validators/validate-id.js';
|
|
6
6
|
import { validateSupportedLocales } from './validators/validate-supported-locales.js';
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* Defines the canonical Intor configuration.
|
|
10
|
-
*
|
|
11
|
-
* This is the primary entry point for creating a validated,
|
|
12
|
-
* runtime-ready Intor configuration.
|
|
13
|
-
*
|
|
14
|
-
* It transforms a user-provided raw config into a normalized form by:
|
|
15
|
-
* - enforcing required invariants
|
|
16
|
-
* - resolving derived options
|
|
17
|
-
* - applying stable defaults
|
|
18
|
-
*
|
|
19
|
-
* This function is pure and side-effect free.
|
|
20
|
-
*
|
|
21
|
-
* @public
|
|
22
|
-
*/
|
|
23
8
|
const defineIntorConfig = (config) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
};
|
|
9
|
+
const id = validateId(config.id ?? "default");
|
|
10
|
+
const supportedLocales = validateSupportedLocales(
|
|
11
|
+
id,
|
|
12
|
+
config.supportedLocales
|
|
13
|
+
);
|
|
14
|
+
const supportedSet = new Set(supportedLocales);
|
|
15
|
+
const defaultLocale = validateDefaultLocale(
|
|
16
|
+
id,
|
|
17
|
+
config.defaultLocale,
|
|
18
|
+
supportedSet
|
|
19
|
+
);
|
|
20
|
+
const fallbackLocales = resolveFallbackLocales(config, id, supportedSet);
|
|
21
|
+
const cookie = resolveCookieOptions(config.cookie);
|
|
22
|
+
const routing = resolveRoutingOptions(config.routing);
|
|
23
|
+
return {
|
|
24
|
+
id,
|
|
25
|
+
...config.messages !== void 0 ? { messages: config.messages } : {},
|
|
26
|
+
...config.loader !== void 0 ? { loader: config.loader } : {},
|
|
27
|
+
defaultLocale,
|
|
28
|
+
supportedLocales,
|
|
29
|
+
fallbackLocales,
|
|
30
|
+
...config.translator !== void 0 ? { translator: config.translator } : {},
|
|
31
|
+
cookie,
|
|
32
|
+
routing,
|
|
33
|
+
logger: { id, ...config.logger },
|
|
34
|
+
...config.client !== void 0 ? { client: config.client } : {},
|
|
35
|
+
...config.server !== void 0 ? { server: config.server } : {}
|
|
36
|
+
};
|
|
53
37
|
};
|
|
54
38
|
|
|
55
39
|
export { defineIntorConfig };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_COOKIE_OPTIONS } from '../constants/cookie.js';
|
|
2
2
|
|
|
3
3
|
const resolveCookieOptions = (cookie = {}) => {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
return {
|
|
5
|
+
...DEFAULT_COOKIE_OPTIONS,
|
|
6
|
+
...cookie
|
|
7
|
+
};
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export { resolveCookieOptions };
|
|
@@ -2,59 +2,42 @@ import { getLogger } from '../../core/logger/get-logger.js';
|
|
|
2
2
|
import 'p-limit';
|
|
3
3
|
import 'intor-translator';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Resolves fallbackLocales into a runtime-safe mapping.
|
|
7
|
-
*
|
|
8
|
-
* Invalid entries are ignored and reported via warnings.
|
|
9
|
-
*/
|
|
10
5
|
const resolveFallbackLocales = (config, id, supportedSet) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
const { defaultLocale, fallbackLocales } = config;
|
|
7
|
+
if (!fallbackLocales || typeof fallbackLocales !== "object") {
|
|
8
|
+
return {};
|
|
9
|
+
}
|
|
10
|
+
const logger = getLogger({ ...config.logger, id }).child({
|
|
11
|
+
scope: "resolve-fallback-locales"
|
|
12
|
+
});
|
|
13
|
+
const resolvedMap = {};
|
|
14
|
+
const invalidMap = /* @__PURE__ */ new Map();
|
|
15
|
+
for (const [locale, fallbacks] of Object.entries(fallbackLocales)) {
|
|
16
|
+
if (!supportedSet.has(locale) && locale !== defaultLocale) {
|
|
17
|
+
logger.warn(
|
|
18
|
+
`Fallback locale "${locale}" is not listed in supportedLocales.`
|
|
19
|
+
);
|
|
20
|
+
continue;
|
|
15
21
|
}
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
// Guard: fallback rules for unreachable locales are ignored.
|
|
26
|
-
if (!supportedSet.has(locale) && locale !== defaultLocale) {
|
|
27
|
-
logger.warn(`Fallback locale "${locale}" is not listed in supportedLocales.`);
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
const fallbackArray = Array.isArray(fallbacks) ? fallbacks : [];
|
|
31
|
-
const validFallbacks = [];
|
|
32
|
-
const invalidFallbacks = [];
|
|
33
|
-
for (const fallback of fallbackArray) {
|
|
34
|
-
// A fallback target is considered valid if:
|
|
35
|
-
// - It exists in `supportedLocales`
|
|
36
|
-
// - It is the literal value "default"
|
|
37
|
-
if (fallback === "default" || supportedSet.has(fallback)) {
|
|
38
|
-
validFallbacks.push(fallback);
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
invalidFallbacks.push(fallback);
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
if (invalidFallbacks.length > 0)
|
|
45
|
-
invalidMap.set(locale, invalidFallbacks);
|
|
46
|
-
if (validFallbacks.length > 0)
|
|
47
|
-
resolvedMap[locale] = validFallbacks;
|
|
48
|
-
}
|
|
49
|
-
// ---------------------------------------------------------------------------
|
|
50
|
-
// Diagnostics: report ignored fallback entries
|
|
51
|
-
// ---------------------------------------------------------------------------
|
|
52
|
-
for (const [locale, invalids] of invalidMap.entries()) {
|
|
53
|
-
logger.warn(`Invalid fallback locales for "${locale}".`, {
|
|
54
|
-
invalids: invalids.join(", "),
|
|
55
|
-
});
|
|
22
|
+
const fallbackArray = Array.isArray(fallbacks) ? fallbacks : [];
|
|
23
|
+
const validFallbacks = [];
|
|
24
|
+
const invalidFallbacks = [];
|
|
25
|
+
for (const fallback of fallbackArray) {
|
|
26
|
+
if (fallback === "default" || supportedSet.has(fallback)) {
|
|
27
|
+
validFallbacks.push(fallback);
|
|
28
|
+
} else {
|
|
29
|
+
invalidFallbacks.push(fallback);
|
|
30
|
+
}
|
|
56
31
|
}
|
|
57
|
-
|
|
32
|
+
if (invalidFallbacks.length > 0) invalidMap.set(locale, invalidFallbacks);
|
|
33
|
+
if (validFallbacks.length > 0) resolvedMap[locale] = validFallbacks;
|
|
34
|
+
}
|
|
35
|
+
for (const [locale, invalids] of invalidMap.entries()) {
|
|
36
|
+
logger.warn(`Invalid fallback locales for "${locale}".`, {
|
|
37
|
+
invalids: invalids.join(", ")
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return resolvedMap;
|
|
58
41
|
};
|
|
59
42
|
|
|
60
43
|
export { resolveFallbackLocales };
|
|
@@ -6,76 +6,47 @@ import 'intor-translator';
|
|
|
6
6
|
import { DEFAULT_ROUTING_OPTIONS } from '../constants/routing.js';
|
|
7
7
|
import '../constants/cookie.js';
|
|
8
8
|
|
|
9
|
-
/**
|
|
10
|
-
* Resolves routing configuration into a fully normalized form.
|
|
11
|
-
*
|
|
12
|
-
* - Flat shortcuts are projected into structured options.
|
|
13
|
-
* - Structured options override projected values.
|
|
14
|
-
* - Defaults are applied last.
|
|
15
|
-
*/
|
|
16
9
|
function resolveRoutingOptions(raw) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
10
|
+
if (!raw) {
|
|
11
|
+
return enforceRoutingInvariants(DEFAULT_ROUTING_OPTIONS);
|
|
12
|
+
}
|
|
13
|
+
const projectedFromFlat = projectFlatToStructured(raw);
|
|
14
|
+
const structuredOverrides = stripFlatShortcuts(raw);
|
|
15
|
+
const defined = deepMerge(projectedFromFlat, structuredOverrides);
|
|
16
|
+
const merged = deepMerge(DEFAULT_ROUTING_OPTIONS, defined);
|
|
17
|
+
return enforceRoutingInvariants(merged);
|
|
25
18
|
}
|
|
26
|
-
/**
|
|
27
|
-
* Enforces runtime invariants for routing configuration.
|
|
28
|
-
*
|
|
29
|
-
* Invariants:
|
|
30
|
-
* - basePath is normalized
|
|
31
|
-
* - basePath always starts with "/"
|
|
32
|
-
* - root basePath is represented as "/"
|
|
33
|
-
*/
|
|
34
19
|
function enforceRoutingInvariants(routing) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
: "/";
|
|
38
|
-
return { ...routing, basePath: normalizedBase };
|
|
20
|
+
const normalizedBase = routing.basePath && routing.basePath !== "/" ? normalizePathname(routing.basePath) : "/";
|
|
21
|
+
return { ...routing, basePath: normalizedBase };
|
|
39
22
|
}
|
|
40
|
-
/** Assigns a value to the target only if it is explicitly defined. */
|
|
41
23
|
function assignIfDefined(target, key, value) {
|
|
42
|
-
|
|
43
|
-
target[key] = value;
|
|
24
|
+
if (value !== void 0) target[key] = value;
|
|
44
25
|
}
|
|
45
|
-
/** Projects flat routing shortcuts into structured options. */
|
|
46
26
|
function projectFlatToStructured(flat) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
assignIfDefined(outbound, "forceFullReload", flat.forceFullReload);
|
|
63
|
-
if (Object.keys(outbound).length > 0)
|
|
64
|
-
structured.outbound = outbound;
|
|
65
|
-
return structured;
|
|
27
|
+
const structured = {};
|
|
28
|
+
assignIfDefined(structured, "basePath", flat.basePath);
|
|
29
|
+
assignIfDefined(structured, "localePrefix", flat.localePrefix);
|
|
30
|
+
const inbound = {};
|
|
31
|
+
assignIfDefined(inbound, "localeSources", flat.localeSources);
|
|
32
|
+
assignIfDefined(inbound, "queryKey", flat.queryKey);
|
|
33
|
+
assignIfDefined(inbound, "firstVisit", flat.firstVisit);
|
|
34
|
+
if (Object.keys(inbound).length > 0) structured.inbound = inbound;
|
|
35
|
+
const outbound = {};
|
|
36
|
+
assignIfDefined(outbound, "localeCarrier", flat.localeCarrier);
|
|
37
|
+
assignIfDefined(outbound, "queryKey", flat.queryKey);
|
|
38
|
+
assignIfDefined(outbound, "host", flat.host);
|
|
39
|
+
assignIfDefined(outbound, "forceFullReload", flat.forceFullReload);
|
|
40
|
+
if (Object.keys(outbound).length > 0) structured.outbound = outbound;
|
|
41
|
+
return structured;
|
|
66
42
|
}
|
|
67
|
-
/** Removes flat shortcuts, preserving structured overrides only. */
|
|
68
43
|
function stripFlatShortcuts(raw) {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
structured.inbound = raw.inbound;
|
|
76
|
-
if ("outbound" in raw)
|
|
77
|
-
structured.outbound = raw.outbound;
|
|
78
|
-
return structured;
|
|
44
|
+
const structured = {};
|
|
45
|
+
if ("basePath" in raw) structured.basePath = raw.basePath;
|
|
46
|
+
if ("localePrefix" in raw) structured.localePrefix = raw.localePrefix;
|
|
47
|
+
if ("inbound" in raw) structured.inbound = raw.inbound;
|
|
48
|
+
if ("outbound" in raw) structured.outbound = raw.outbound;
|
|
49
|
+
return structured;
|
|
79
50
|
}
|
|
80
51
|
|
|
81
52
|
export { resolveRoutingOptions };
|
|
@@ -3,20 +3,15 @@ import 'logry';
|
|
|
3
3
|
import 'p-limit';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Validates that the configured defaultLocale is supported.
|
|
8
|
-
*
|
|
9
|
-
* Fails fast if `defaultLocale` is not included in `supportedLocales`.
|
|
10
|
-
*/
|
|
11
6
|
const validateDefaultLocale = (id, defaultLocale, supportedSet) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
if (!supportedSet.has(defaultLocale)) {
|
|
8
|
+
throw new IntorError({
|
|
9
|
+
id,
|
|
10
|
+
code: INTOR_ERROR_CODE.CONFIG_UNSUPPORTED_DEFAULT_LOCALE,
|
|
11
|
+
message: `"defaultLocale" must be included in "supportedLocales".`
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return defaultLocale;
|
|
20
15
|
};
|
|
21
16
|
|
|
22
17
|
export { validateDefaultLocale };
|
|
@@ -3,20 +3,15 @@ import 'logry';
|
|
|
3
3
|
import 'p-limit';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Validates that the given id is a non-empty string.
|
|
8
|
-
*
|
|
9
|
-
* Fails fast if the id is empty or whitespace-only.
|
|
10
|
-
*/
|
|
11
6
|
const validateId = (id) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
if (id.trim() === "") {
|
|
8
|
+
throw new IntorError({
|
|
9
|
+
id,
|
|
10
|
+
code: INTOR_ERROR_CODE.CONFIG_INVALID_ID,
|
|
11
|
+
message: `"id" must be a non-empty string.`
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return id;
|
|
20
15
|
};
|
|
21
16
|
|
|
22
17
|
export { validateId };
|
|
@@ -3,20 +3,15 @@ import 'logry';
|
|
|
3
3
|
import 'p-limit';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Validates that supportedLocales is provided and non-empty.
|
|
8
|
-
*
|
|
9
|
-
* Fails fast when missing.
|
|
10
|
-
*/
|
|
11
6
|
const validateSupportedLocales = (id, supportedLocales) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
if (!supportedLocales || supportedLocales.length === 0) {
|
|
8
|
+
throw new IntorError({
|
|
9
|
+
id,
|
|
10
|
+
code: INTOR_ERROR_CODE.CONFIG_MISSING_SUPPORTED_LOCALES,
|
|
11
|
+
message: `"supportedLocales" must be specified.`
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
return supportedLocales;
|
|
20
15
|
};
|
|
21
16
|
|
|
22
17
|
export { validateSupportedLocales };
|
|
@@ -1,35 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Framework-level error used by Intor.
|
|
3
|
-
*
|
|
4
|
-
* Extends the native Error with optional structured metadata.
|
|
5
|
-
*
|
|
6
|
-
* @public
|
|
7
|
-
*/
|
|
8
1
|
class IntorError extends Error {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
if (Error.captureStackTrace)
|
|
21
|
-
Error.captureStackTrace(this, IntorError);
|
|
22
|
-
}
|
|
2
|
+
code;
|
|
3
|
+
id;
|
|
4
|
+
constructor({ message, code, id }) {
|
|
5
|
+
const fullMessage = id ? `[${id}] ${message}` : message;
|
|
6
|
+
super(fullMessage);
|
|
7
|
+
this.name = "IntorError";
|
|
8
|
+
if (id) this.id = id;
|
|
9
|
+
if (code) this.code = code;
|
|
10
|
+
Object.setPrototypeOf(this, new.target.prototype);
|
|
11
|
+
if (Error.captureStackTrace) Error.captureStackTrace(this, IntorError);
|
|
12
|
+
}
|
|
23
13
|
}
|
|
24
|
-
/**
|
|
25
|
-
* Built-in error codes used by Intor.
|
|
26
|
-
*
|
|
27
|
-
* @public
|
|
28
|
-
*/
|
|
29
14
|
const INTOR_ERROR_CODE = {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
15
|
+
CONFIG_INVALID_ID: "INTOR_CONFIG_INVALID_ID",
|
|
16
|
+
CONFIG_MISSING_SUPPORTED_LOCALES: "INTOR_CONFIG_MISSING_SUPPORTED_LOCALES",
|
|
17
|
+
CONFIG_UNSUPPORTED_DEFAULT_LOCALE: "INTOR_CONFIG_UNSUPPORTED_DEFAULT_LOCALE"
|
|
33
18
|
};
|
|
34
19
|
|
|
35
20
|
export { INTOR_ERROR_CODE, IntorError };
|
|
@@ -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
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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 };
|