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.
- package/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/core/export/index.js +1 -0
- 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/export/next/server/index.js +1 -0
- package/dist/next/src/adapters/next/create-intor-handler.js +39 -48
- package/dist/next/src/adapters/next/header-keys.js +9 -0
- 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 +13 -24
- 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/server/read-intor-url-state.js +13 -0
- 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/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/export/index.d.ts +1 -1
- package/dist/types/export/index.d.ts.map +1 -1
- package/dist/types/export/next/server/index.d.ts +1 -1
- package/dist/types/export/next/server/index.d.ts.map +1 -1
- package/dist/types/src/adapters/fastify/intor-fastify-plugin.d.ts.map +1 -1
- package/dist/types/src/adapters/next/create-intor-handler.d.ts.map +1 -1
- package/dist/types/src/{core/constants/headers.d.ts → adapters/next/header-keys.d.ts} +3 -2
- package/dist/types/src/adapters/next/header-keys.d.ts.map +1 -0
- package/dist/types/src/adapters/next/server/get-locale.d.ts.map +1 -1
- package/dist/types/src/adapters/next/server/index.d.ts +1 -0
- package/dist/types/src/adapters/next/server/index.d.ts.map +1 -1
- package/dist/types/src/adapters/next/server/read-intor-url-state.d.ts +13 -0
- package/dist/types/src/adapters/next/server/read-intor-url-state.d.ts.map +1 -0
- package/dist/types/src/core/constants/index.d.ts +0 -1
- package/dist/types/src/core/constants/index.d.ts.map +1 -1
- package/dist/types/src/core/constants/locale-placeholder.d.ts +5 -0
- package/dist/types/src/core/constants/locale-placeholder.d.ts.map +1 -1
- package/dist/types/src/core/index.d.ts +1 -1
- package/dist/types/src/core/index.d.ts.map +1 -1
- package/dist/types/src/edge/translator/init-translator.d.ts.map +1 -1
- 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/types/src/server/translator/init-translator.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 +53 -65
- package/dist/next/src/core/constants/headers.js +0 -8
- package/dist/types/src/core/constants/headers.d.ts.map +0 -1
|
@@ -4,39 +4,33 @@ import { exceptDefault } from './strategies/except-default.js';
|
|
|
4
4
|
import { none } from './strategies/none.js';
|
|
5
5
|
|
|
6
6
|
const assertNever = (x) => {
|
|
7
|
-
|
|
7
|
+
throw new Error(`Unhandled prefix strategy: ${String(x)}`);
|
|
8
8
|
};
|
|
9
|
-
/**
|
|
10
|
-
* Resolves the canonical pathname based on locale prefix behavior.
|
|
11
|
-
*
|
|
12
|
-
* The resolved pathname represents the final, normalized form
|
|
13
|
-
* used for routing and navigation.
|
|
14
|
-
*/
|
|
15
9
|
const resolvePathname = (config, rawPathname, context) => {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
case "except-default": {
|
|
24
|
-
directive = exceptDefault(config, context);
|
|
25
|
-
break;
|
|
26
|
-
}
|
|
27
|
-
case "none": {
|
|
28
|
-
directive = none();
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
default: {
|
|
32
|
-
return assertNever(localePrefix);
|
|
33
|
-
}
|
|
10
|
+
const { localePrefix } = config.routing;
|
|
11
|
+
let directive;
|
|
12
|
+
switch (localePrefix) {
|
|
13
|
+
case "all": {
|
|
14
|
+
directive = all(config, context);
|
|
15
|
+
break;
|
|
34
16
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
17
|
+
case "except-default": {
|
|
18
|
+
directive = exceptDefault(config, context);
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case "none": {
|
|
22
|
+
directive = none();
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
default: {
|
|
26
|
+
return assertNever(localePrefix);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const { pathname } = localizePathname(rawPathname, config, context.locale);
|
|
30
|
+
return {
|
|
31
|
+
pathname,
|
|
32
|
+
shouldRedirect: directive.type === "redirect"
|
|
33
|
+
};
|
|
40
34
|
};
|
|
41
35
|
|
|
42
36
|
export { resolvePathname };
|
|
@@ -1,34 +1,18 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve pathname decision for routing prefix strategy: "all".
|
|
3
|
-
*/
|
|
4
1
|
function all(config, context) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// ----------------------------------------------------------
|
|
17
|
-
if (hasRedirected) {
|
|
18
|
-
return { type: "pass" };
|
|
19
|
-
}
|
|
20
|
-
// ----------------------------------------------------------
|
|
21
|
-
// Apply first-visit redirect policy
|
|
22
|
-
// ----------------------------------------------------------
|
|
23
|
-
if (isFirstVisit) {
|
|
24
|
-
if (!redirect)
|
|
25
|
-
return { type: "pass" };
|
|
26
|
-
return { type: "redirect" };
|
|
27
|
-
}
|
|
28
|
-
// ----------------------------------------------------------
|
|
29
|
-
// Redirect to the locale-prefixed URL
|
|
30
|
-
// ----------------------------------------------------------
|
|
2
|
+
const { hasPathLocale, hasPersisted, hasRedirected } = context;
|
|
3
|
+
const { redirect } = config.routing.inbound.firstVisit;
|
|
4
|
+
const isFirstVisit = !hasPersisted;
|
|
5
|
+
if (hasPathLocale) {
|
|
6
|
+
return { type: "pass" };
|
|
7
|
+
}
|
|
8
|
+
if (hasRedirected) {
|
|
9
|
+
return { type: "pass" };
|
|
10
|
+
}
|
|
11
|
+
if (isFirstVisit) {
|
|
12
|
+
if (!redirect) return { type: "pass" };
|
|
31
13
|
return { type: "redirect" };
|
|
14
|
+
}
|
|
15
|
+
return { type: "redirect" };
|
|
32
16
|
}
|
|
33
17
|
|
|
34
18
|
export { all };
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve pathname decision for routing prefix strategy: "except-default".
|
|
3
|
-
*/
|
|
4
1
|
function exceptDefault(config, context) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
// ----------------------------------------------------------
|
|
18
|
-
if (hasRedirected) {
|
|
19
|
-
return { type: "pass" };
|
|
20
|
-
}
|
|
21
|
-
// ----------------------------------------------------------
|
|
22
|
-
// Apply first-visit redirect policy
|
|
23
|
-
// ----------------------------------------------------------
|
|
24
|
-
if (isFirstVisit) {
|
|
25
|
-
if (!redirect)
|
|
26
|
-
return { type: "pass" };
|
|
27
|
-
return isDefaultLocale ? { type: "pass" } : { type: "redirect" };
|
|
28
|
-
}
|
|
29
|
-
// ----------------------------------------------------------
|
|
30
|
-
// Redirect non-default locale to the locale-prefixed URL
|
|
31
|
-
// ----------------------------------------------------------
|
|
2
|
+
const { hasPathLocale, hasPersisted, hasRedirected } = context;
|
|
3
|
+
const { redirect } = config.routing.inbound.firstVisit;
|
|
4
|
+
const isFirstVisit = !hasPersisted;
|
|
5
|
+
const isDefaultLocale = context.locale === config.defaultLocale;
|
|
6
|
+
if (hasPathLocale) {
|
|
7
|
+
return { type: "pass" };
|
|
8
|
+
}
|
|
9
|
+
if (hasRedirected) {
|
|
10
|
+
return { type: "pass" };
|
|
11
|
+
}
|
|
12
|
+
if (isFirstVisit) {
|
|
13
|
+
if (!redirect) return { type: "pass" };
|
|
32
14
|
return isDefaultLocale ? { type: "pass" } : { type: "redirect" };
|
|
15
|
+
}
|
|
16
|
+
return isDefaultLocale ? { type: "pass" } : { type: "redirect" };
|
|
33
17
|
}
|
|
34
18
|
|
|
35
19
|
export { exceptDefault };
|
|
@@ -1,40 +1,25 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get locale candidate from the `Accept-Language` header.
|
|
3
|
-
*
|
|
4
|
-
* Parses language priorities and returns the highest-priority
|
|
5
|
-
* language present in `supportedLocales`, without normalization.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* getLocaleFromAcceptLanguage("en-US,en;q=0.8,zh-TW;q=0.9", ["en-US", "zh-TW"])
|
|
10
|
-
* // => "en-US"
|
|
11
|
-
*
|
|
12
|
-
* getLocaleFromAcceptLanguage("fr,ja;q=0.9", ["en", "zh-TW"])
|
|
13
|
-
* // => undefined
|
|
14
|
-
* ```
|
|
15
|
-
*/
|
|
16
1
|
const getLocaleFromAcceptLanguage = (acceptLanguageHeader, supportedLocales) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
2
|
+
if (!acceptLanguageHeader || supportedLocales.length === 0) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
const supportedLocalesSet = new Set(supportedLocales);
|
|
6
|
+
const parsedLanguages = acceptLanguageHeader.split(",").map((part) => {
|
|
7
|
+
const segments = part.split(";");
|
|
8
|
+
const rawLang = segments[0];
|
|
9
|
+
const rawQ = segments[1];
|
|
10
|
+
const lang = rawLang.trim();
|
|
11
|
+
const q = rawQ !== void 0 ? Number.parseFloat(rawQ.split("=")[1] ?? "") : 1;
|
|
12
|
+
return {
|
|
13
|
+
lang,
|
|
14
|
+
q: Number.isNaN(q) ? 0 : q
|
|
15
|
+
// Invalid q values have lowest priority
|
|
16
|
+
};
|
|
17
|
+
});
|
|
18
|
+
const sortedByPriority = parsedLanguages.sort((a, b) => b.q - a.q);
|
|
19
|
+
const preferred = sortedByPriority.find(
|
|
20
|
+
({ lang }) => supportedLocalesSet.has(lang)
|
|
21
|
+
)?.lang;
|
|
22
|
+
return preferred;
|
|
38
23
|
};
|
|
39
24
|
|
|
40
25
|
export { getLocaleFromAcceptLanguage };
|
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get locale candidate from hostname.
|
|
3
|
-
*
|
|
4
|
-
* Returns the left-most hostname label, without validation or normalization.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* ```ts
|
|
8
|
-
* getLocaleFromHost("en.example.com")
|
|
9
|
-
* // => "en"
|
|
10
|
-
*
|
|
11
|
-
* getLocaleFromHost("example.com")
|
|
12
|
-
* // => "example"
|
|
13
|
-
*
|
|
14
|
-
* getLocaleFromHost("api.jp.example.com")
|
|
15
|
-
* // => "api"
|
|
16
|
-
*
|
|
17
|
-
* getLocaleFromHost("localhost")
|
|
18
|
-
* // => undefined
|
|
19
|
-
* ```
|
|
20
|
-
*/
|
|
21
1
|
function getLocaleFromHost(host) {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (parts.length < 2)
|
|
28
|
-
return;
|
|
29
|
-
return parts[0];
|
|
2
|
+
if (!host) return;
|
|
3
|
+
const hostname = host.split(":")[0];
|
|
4
|
+
const parts = hostname.split(".");
|
|
5
|
+
if (parts.length < 2) return;
|
|
6
|
+
return parts[0];
|
|
30
7
|
}
|
|
31
8
|
|
|
32
9
|
export { getLocaleFromHost };
|
|
@@ -3,44 +3,18 @@ import 'logry';
|
|
|
3
3
|
import 'p-limit';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Get locale from pathname.
|
|
8
|
-
*
|
|
9
|
-
* Extracts the first pathname segment (after basePath) as a locale
|
|
10
|
-
* if it exactly matches one of the supported locales.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* getLocaleFromPathname(config, "/en/about")
|
|
15
|
-
* // => "en"
|
|
16
|
-
* getLocaleFromPathname(config, "/zh-TW")
|
|
17
|
-
* // => "zh-TW"
|
|
18
|
-
* getLocaleFromPathname(config, "/about")
|
|
19
|
-
* // => undefined
|
|
20
|
-
*
|
|
21
|
-
* // config.routing.basePath: "/app"
|
|
22
|
-
* getLocaleFromPathname(config, "/app/en/dashboard")
|
|
23
|
-
* // => "en"
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
6
|
function getLocaleFromPathname(pathname, config) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
39
|
-
// 3. Detect locale segment
|
|
40
|
-
const firstSegment = prefixedPathname.split("/").find(Boolean);
|
|
41
|
-
return firstSegment && supportedLocales.includes(firstSegment)
|
|
42
|
-
? firstSegment
|
|
43
|
-
: undefined;
|
|
7
|
+
const { routing, supportedLocales } = config;
|
|
8
|
+
const { basePath } = routing;
|
|
9
|
+
const normalizedPathname = normalizePathname(pathname);
|
|
10
|
+
let prefixedPathname = normalizedPathname;
|
|
11
|
+
if (basePath && normalizedPathname === basePath) {
|
|
12
|
+
prefixedPathname = "/";
|
|
13
|
+
} else if (basePath && normalizedPathname.startsWith(basePath + "/")) {
|
|
14
|
+
prefixedPathname = normalizedPathname.slice(basePath.length);
|
|
15
|
+
}
|
|
16
|
+
const firstSegment = prefixedPathname.split("/").find(Boolean);
|
|
17
|
+
return firstSegment && supportedLocales.includes(firstSegment) ? firstSegment : void 0;
|
|
44
18
|
}
|
|
45
19
|
|
|
46
20
|
export { getLocaleFromPathname };
|
|
@@ -1,21 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Get locale candidate from URL query parameters.
|
|
3
|
-
*
|
|
4
|
-
* Extracts the value of the configured query key, without
|
|
5
|
-
* validation or normalization.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* ```ts
|
|
9
|
-
* getLocaleFromQuery({ locale: "en" }, "locale")
|
|
10
|
-
* // => "en"
|
|
11
|
-
*
|
|
12
|
-
* getLocaleFromQuery({}, "locale")
|
|
13
|
-
* // => undefined
|
|
14
|
-
*/
|
|
15
1
|
function getLocaleFromQuery(query, queryKey) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return query[queryKey];
|
|
2
|
+
if (!query) return;
|
|
3
|
+
return query[queryKey];
|
|
19
4
|
}
|
|
20
5
|
|
|
21
6
|
export { getLocaleFromQuery };
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { shouldFullReload } from '../../policies/shoud-full-reload.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
function decideStrategy(config, target, currentLocale) {
|
|
4
|
+
if (target.isExternal) {
|
|
5
|
+
return "external";
|
|
6
|
+
}
|
|
7
|
+
const isLocaleChange = target.locale !== currentLocale;
|
|
8
|
+
if (isLocaleChange && shouldFullReload(config)) {
|
|
9
|
+
return "reload";
|
|
10
|
+
}
|
|
11
|
+
return "client";
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export { decideStrategy };
|
|
@@ -4,52 +4,36 @@ import { deriveHostDestination } from './utils/derive-host-destination.js';
|
|
|
4
4
|
import { deriveQueryDestination } from './utils/derive-query-destination.js';
|
|
5
5
|
import { isExternalDestination } from './utils/is-external-destination.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Determines the outbound routing target.
|
|
9
|
-
*/
|
|
10
7
|
function determineTarget(config, currentLocale, currentPathname, intent) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
case "host": {
|
|
36
|
-
destination = deriveHostDestination(rawDestination, config, locale);
|
|
37
|
-
break;
|
|
38
|
-
}
|
|
39
|
-
case "query": {
|
|
40
|
-
destination = deriveQueryDestination(rawDestination, config, locale);
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
default: {
|
|
44
|
-
destination = rawDestination;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
8
|
+
const { supportedLocales, routing } = config;
|
|
9
|
+
const locale = intent?.locale && supportedLocales.includes(intent?.locale) ? intent?.locale : currentLocale;
|
|
10
|
+
const rawDestination = intent?.destination ?? canonicalizePathname(currentPathname, config);
|
|
11
|
+
const isExternal = isExternalDestination(rawDestination);
|
|
12
|
+
let destination = rawDestination;
|
|
13
|
+
if (!isExternal) {
|
|
14
|
+
switch (routing.outbound.localeCarrier) {
|
|
15
|
+
case "path": {
|
|
16
|
+
destination = localizePathname(rawDestination, config, locale).pathname;
|
|
17
|
+
break;
|
|
18
|
+
}
|
|
19
|
+
case "host": {
|
|
20
|
+
destination = deriveHostDestination(rawDestination, config, locale);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case "query": {
|
|
24
|
+
destination = deriveQueryDestination(rawDestination, config, locale);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
default: {
|
|
28
|
+
destination = rawDestination;
|
|
29
|
+
}
|
|
47
30
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
31
|
+
}
|
|
32
|
+
return {
|
|
33
|
+
locale,
|
|
34
|
+
destination,
|
|
35
|
+
isExternal
|
|
36
|
+
};
|
|
53
37
|
}
|
|
54
38
|
|
|
55
39
|
export { determineTarget };
|
|
@@ -1,23 +1,19 @@
|
|
|
1
1
|
import { decideStrategy } from './decide-strategy.js';
|
|
2
2
|
import { determineTarget } from './determine-target.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Resolve an outbound routing attempt into an executable result.
|
|
6
|
-
*/
|
|
7
4
|
function resolveOutbound(config, currentLocale, currentPathname, intent) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
5
|
+
const target = determineTarget(
|
|
6
|
+
config,
|
|
7
|
+
currentLocale,
|
|
8
|
+
currentPathname,
|
|
9
|
+
intent
|
|
10
|
+
);
|
|
11
|
+
const strategy = decideStrategy(config, target, currentLocale);
|
|
12
|
+
return {
|
|
13
|
+
locale: target.locale,
|
|
14
|
+
destination: target.destination,
|
|
15
|
+
kind: strategy
|
|
16
|
+
};
|
|
21
17
|
}
|
|
22
18
|
|
|
23
19
|
export { resolveOutbound };
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derives a locale-specific destination using host-based navigation.
|
|
3
|
-
*/
|
|
4
1
|
const deriveHostDestination = (rawDestination, config, locale) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return `${url.protocol}//${resolvedHost}${url.pathname}${url.search}`;
|
|
2
|
+
const { host } = config.routing.outbound;
|
|
3
|
+
const resolvedHost = host.map[locale] ?? host.default;
|
|
4
|
+
if (!resolvedHost) return rawDestination;
|
|
5
|
+
const url = new URL(rawDestination, "http://localhost");
|
|
6
|
+
return `${url.protocol}//${resolvedHost}${url.pathname}${url.search}`;
|
|
11
7
|
};
|
|
12
8
|
|
|
13
9
|
export { deriveHostDestination };
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Derives a locale-specific destination using query-based navigation.
|
|
3
|
-
*/
|
|
4
1
|
const deriveQueryDestination = (rawDestination, config, locale) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
2
|
+
const { queryKey } = config.routing.outbound;
|
|
3
|
+
const url = new URL(rawDestination, "http://localhost");
|
|
4
|
+
url.searchParams.set(queryKey, locale);
|
|
5
|
+
return `${url.pathname}${url.search}`;
|
|
9
6
|
};
|
|
10
7
|
|
|
11
8
|
export { deriveQueryDestination };
|
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Determines whether a navigation target should bypass app routing.
|
|
3
|
-
*
|
|
4
|
-
* Any value with an explicit scheme (e.g. http:, https:, mailto:)
|
|
5
|
-
* is treated as external navigation.
|
|
6
|
-
*/
|
|
7
1
|
const isExternalDestination = (destination) => {
|
|
8
|
-
|
|
2
|
+
return /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(destination);
|
|
9
3
|
};
|
|
10
4
|
|
|
11
5
|
export { isExternalDestination };
|
|
@@ -4,75 +4,33 @@ import 'logry';
|
|
|
4
4
|
import 'p-limit';
|
|
5
5
|
import 'intor-translator';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Returns the internal canonical pathname.
|
|
9
|
-
*
|
|
10
|
-
* Canonical representation is the locale-neutral and deployment-neutral
|
|
11
|
-
* internal routing form used for identity and routing computation.
|
|
12
|
-
*
|
|
13
|
-
* Guarantees:
|
|
14
|
-
* - Pathname is normalized
|
|
15
|
-
* - Deployment prefix (`basePath`) is removed
|
|
16
|
-
* - Leading locale segment or `{locale}` placeholder is removed
|
|
17
|
-
* - Only the first path segment is evaluated for locale stripping
|
|
18
|
-
* - Result always starts with "/"
|
|
19
|
-
* - Root is represented as "/"
|
|
20
|
-
*
|
|
21
|
-
* Accepts `{locale}` as a locale placeholder segment.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```ts
|
|
25
|
-
* // config.supportedLocales: ["en"]
|
|
26
|
-
* // config.routing.basePath: "/app"
|
|
27
|
-
* // config.routing.prefix: "all"
|
|
28
|
-
* canonicalizePathname("/app/en/about", config);
|
|
29
|
-
* // => "/about"
|
|
30
|
-
*```
|
|
31
|
-
*/
|
|
32
7
|
function canonicalizePathname(rawPathname, config) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
if (basePath) {
|
|
41
|
-
|
|
42
|
-
path = "/";
|
|
43
|
-
}
|
|
44
|
-
else if (path.startsWith(basePath + "/")) {
|
|
45
|
-
path = path.slice(basePath.length);
|
|
46
|
-
}
|
|
8
|
+
const { routing, supportedLocales } = config;
|
|
9
|
+
const normalizedPathname = normalizePathname(rawPathname);
|
|
10
|
+
const basePath = routing.basePath === "/" ? "" : routing.basePath;
|
|
11
|
+
let path = normalizedPathname;
|
|
12
|
+
if (basePath) {
|
|
13
|
+
if (path === basePath) {
|
|
14
|
+
path = "/";
|
|
15
|
+
} else if (path.startsWith(basePath + "/")) {
|
|
16
|
+
path = path.slice(basePath.length);
|
|
47
17
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
else if (supportedLocales.includes(firstSegment)) {
|
|
66
|
-
localeLength = firstSegment.length;
|
|
67
|
-
}
|
|
68
|
-
// ---------------------------------------------------------------------------
|
|
69
|
-
// Strip locale segment (if any)
|
|
70
|
-
// ---------------------------------------------------------------------------
|
|
71
|
-
if (localeLength !== undefined) {
|
|
72
|
-
const stripped = path.slice(localeLength + 1);
|
|
73
|
-
return stripped || "/";
|
|
74
|
-
}
|
|
75
|
-
return path;
|
|
18
|
+
}
|
|
19
|
+
if (path === "/") return "/";
|
|
20
|
+
const segmentStart = 1;
|
|
21
|
+
const nextSlash = path.indexOf("/", segmentStart);
|
|
22
|
+
const firstSegment = nextSlash === -1 ? path.slice(segmentStart) : path.slice(segmentStart, nextSlash);
|
|
23
|
+
let localeLength;
|
|
24
|
+
if (firstSegment === LOCALE_PLACEHOLDER) {
|
|
25
|
+
localeLength = firstSegment.length;
|
|
26
|
+
} else if (supportedLocales.includes(firstSegment)) {
|
|
27
|
+
localeLength = firstSegment.length;
|
|
28
|
+
}
|
|
29
|
+
if (localeLength !== void 0) {
|
|
30
|
+
const stripped = path.slice(localeLength + 1);
|
|
31
|
+
return stripped || "/";
|
|
32
|
+
}
|
|
33
|
+
return path;
|
|
76
34
|
}
|
|
77
35
|
|
|
78
36
|
export { canonicalizePathname };
|