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
|
@@ -1,21 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Wraps a value inside nested objects according to a given path.
|
|
3
|
-
*
|
|
4
|
-
* @example
|
|
5
|
-
* ```ts
|
|
6
|
-
* const value = { a: "A" };
|
|
7
|
-
*
|
|
8
|
-
* nestObjectFromPath(["auth", "verify"], value); // → { auth: { verify: { a: "A" } } }
|
|
9
|
-
*
|
|
10
|
-
* nestObjectFromPath([], value); // → { a: "A" }
|
|
11
|
-
* ```
|
|
12
|
-
*/
|
|
13
1
|
function nestObjectFromPath(path, value) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
2
|
+
let obj = value;
|
|
3
|
+
for (let i = path.length - 1; i >= 0; i--) {
|
|
4
|
+
obj = { [path[i]]: obj };
|
|
5
|
+
}
|
|
6
|
+
return obj;
|
|
19
7
|
}
|
|
20
8
|
|
|
21
9
|
export { nestObjectFromPath };
|
|
@@ -1,44 +1,36 @@
|
|
|
1
1
|
import { escapeHtml } from './utils/escape-html.js';
|
|
2
2
|
import { renderAttributes } from './utils/render-attributes.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Create an HTML string renderer for semantic rich messages.
|
|
6
|
-
*
|
|
7
|
-
* - Transforms semantic rich AST nodes into escaped HTML strings.
|
|
8
|
-
* - Can be used in any HTML-based environment.
|
|
9
|
-
*
|
|
10
|
-
* This renderer is intentionally minimal and stateless.
|
|
11
|
-
*/
|
|
12
4
|
const createHtmlRenderer = (tagRenderers) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
5
|
+
return {
|
|
6
|
+
/** Render plain text nodes */
|
|
7
|
+
text(value) {
|
|
8
|
+
return escapeHtml(value);
|
|
9
|
+
},
|
|
10
|
+
/** Render semantic tag nodes */
|
|
11
|
+
tag(name, attributes, children) {
|
|
12
|
+
const tagRenderer = tagRenderers?.[name];
|
|
13
|
+
if (tagRenderer) {
|
|
14
|
+
return typeof tagRenderer === "function" ? tagRenderer(children) : tagRenderer;
|
|
15
|
+
}
|
|
16
|
+
return `<${name}${renderAttributes(attributes)}>${children.join(
|
|
17
|
+
""
|
|
18
|
+
)}</${name}>`;
|
|
19
|
+
},
|
|
20
|
+
/** Render raw (non-tokenized) message values as escaped HTML strings */
|
|
21
|
+
raw(value) {
|
|
22
|
+
if (value == null) return "";
|
|
23
|
+
if (typeof value === "string" || typeof value === "number") {
|
|
24
|
+
return escapeHtml(String(value));
|
|
25
|
+
}
|
|
26
|
+
if (Array.isArray(value)) {
|
|
27
|
+
return value.map((v) => escapeHtml(String(v))).join("");
|
|
28
|
+
}
|
|
29
|
+
throw new Error(
|
|
30
|
+
"[intor] HTML renderer cannot render raw non-primitive values."
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
42
34
|
};
|
|
43
35
|
|
|
44
36
|
export { createHtmlRenderer };
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
function escapeHtml(value) {
|
|
2
|
-
|
|
3
|
-
.replaceAll("&", "&")
|
|
4
|
-
.replaceAll("<", "<")
|
|
5
|
-
.replaceAll(">", ">")
|
|
6
|
-
.replaceAll('"', """)
|
|
7
|
-
.replaceAll("'", "'");
|
|
2
|
+
return value.replaceAll("&", "&").replaceAll("<", "<").replaceAll(">", ">").replaceAll('"', """).replaceAll("'", "'");
|
|
8
3
|
}
|
|
9
4
|
|
|
10
5
|
export { escapeHtml };
|
|
@@ -1,17 +1,12 @@
|
|
|
1
1
|
import { escapeHtml } from './escape-html.js';
|
|
2
2
|
|
|
3
3
|
function renderAttributes(attributes) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
if (value == null)
|
|
11
|
-
return "";
|
|
12
|
-
return ` ${key}="${escapeHtml(String(value))}"`;
|
|
13
|
-
})
|
|
14
|
-
.join("");
|
|
4
|
+
if (!attributes) return "";
|
|
5
|
+
return Object.entries(attributes).map(([key, value]) => {
|
|
6
|
+
if (value === true) return ` ${key}`;
|
|
7
|
+
if (value == null) return "";
|
|
8
|
+
return ` ${key}="${escapeHtml(String(value))}"`;
|
|
9
|
+
}).join("");
|
|
15
10
|
}
|
|
16
11
|
|
|
17
12
|
export { renderAttributes };
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { renderRichMessage } from 'intor-translator';
|
|
2
2
|
import { createHtmlRenderer } from '../render/create-html-renderer.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Create an HTML-string rich translation function.
|
|
6
|
-
*
|
|
7
|
-
* - Resolves translated messages via `translator.t`
|
|
8
|
-
* - Renders semantic rich tags into escaped HTML strings
|
|
9
|
-
* - Supports optional scoped keys via `preKey`
|
|
10
|
-
*
|
|
11
|
-
* Can be used in any HTML-based environment (Astro, Svelte, SSR, etc.).
|
|
12
|
-
*/
|
|
13
4
|
const createTRich = (t) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
return (key, tagRenderers, replacements) => {
|
|
6
|
+
const message = t(key, replacements);
|
|
7
|
+
const renderer = createHtmlRenderer(tagRenderers);
|
|
8
|
+
const nodes = renderRichMessage(message, renderer);
|
|
9
|
+
return nodes.join("");
|
|
10
|
+
};
|
|
20
11
|
};
|
|
21
12
|
|
|
22
13
|
export { createTRich };
|
|
@@ -1,31 +1,23 @@
|
|
|
1
1
|
import { Translator } from 'intor-translator';
|
|
2
2
|
import { mergeMessages } from '../messages/merge-messages.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Create a server-side Translator instance for a fixed locale.
|
|
6
|
-
*
|
|
7
|
-
* - Merges static config messages with runtime-loaded messages
|
|
8
|
-
* - Initializes a Translator bound to a specific locale
|
|
9
|
-
* - Injects fallback rules, handlers, and hooks from config
|
|
10
|
-
*/
|
|
11
4
|
function createTranslator(params) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
return translator;
|
|
5
|
+
const { config, locale, messages, handlers, hooks } = params;
|
|
6
|
+
const finalMessages = mergeMessages(config.messages, messages, {
|
|
7
|
+
config,
|
|
8
|
+
locale
|
|
9
|
+
});
|
|
10
|
+
const { loadingMessage, missingMessage } = config.translator ?? {};
|
|
11
|
+
const translator = new Translator({
|
|
12
|
+
locale,
|
|
13
|
+
messages: finalMessages,
|
|
14
|
+
fallbackLocales: config.fallbackLocales,
|
|
15
|
+
...loadingMessage !== void 0 ? { loadingMessage } : {},
|
|
16
|
+
...missingMessage !== void 0 ? { missingMessage } : {},
|
|
17
|
+
...handlers !== void 0 ? { handlers } : {},
|
|
18
|
+
...hooks !== void 0 ? { hooks } : {}
|
|
19
|
+
});
|
|
20
|
+
return translator;
|
|
29
21
|
}
|
|
30
22
|
|
|
31
23
|
export { createTranslator };
|
|
@@ -1,47 +1,29 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Deeply merges two plain objects.
|
|
3
|
-
*
|
|
4
|
-
* - Nested plain objects → merged recursively
|
|
5
|
-
* - Arrays / primitives → `b` overwrites `a`
|
|
6
|
-
*
|
|
7
|
-
* Debug behavior (optional):
|
|
8
|
-
* - Emits override events via `onOverride`
|
|
9
|
-
* - Zero overhead when no options are provided
|
|
10
|
-
*
|
|
11
|
-
* This function always returns a new plain object.
|
|
12
|
-
*/
|
|
13
1
|
const deepMerge = (a = {}, b = {}, options) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
path: nextPath.join("."),
|
|
37
|
-
prev: aValue,
|
|
38
|
-
next: bValue,
|
|
39
|
-
kind: isAdd ? "add" : "override",
|
|
40
|
-
});
|
|
41
|
-
result[key] = bValue;
|
|
42
|
-
}
|
|
2
|
+
const result = { ...a };
|
|
3
|
+
const basePath = options?._path ?? [];
|
|
4
|
+
for (const key in b) {
|
|
5
|
+
if (!Object.prototype.hasOwnProperty.call(b, key)) continue;
|
|
6
|
+
const aValue = a[key];
|
|
7
|
+
const bValue = b[key];
|
|
8
|
+
const nextPath = [...basePath, key];
|
|
9
|
+
if (aValue && bValue && typeof aValue === "object" && typeof bValue === "object" && !Array.isArray(aValue) && !Array.isArray(bValue)) {
|
|
10
|
+
result[key] = deepMerge(
|
|
11
|
+
aValue,
|
|
12
|
+
bValue,
|
|
13
|
+
options ? { ...options, _path: nextPath } : void 0
|
|
14
|
+
);
|
|
15
|
+
} else {
|
|
16
|
+
const isAdd = aValue === void 0;
|
|
17
|
+
options?.onOverride?.({
|
|
18
|
+
path: nextPath.join("."),
|
|
19
|
+
prev: aValue,
|
|
20
|
+
next: bValue,
|
|
21
|
+
kind: isAdd ? "add" : "override"
|
|
22
|
+
});
|
|
23
|
+
result[key] = bValue;
|
|
43
24
|
}
|
|
44
|
-
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
45
27
|
};
|
|
46
28
|
|
|
47
29
|
export { deepMerge };
|
|
@@ -1,45 +1,19 @@
|
|
|
1
1
|
const CACHE_KEY_DELIMITER = "|";
|
|
2
|
-
const sanitize = (k) => k
|
|
3
|
-
.replaceAll(/[\u200B-\u200D\uFEFF]/g, "")
|
|
4
|
-
.replaceAll(/[\r\n]/g, "")
|
|
5
|
-
.trim();
|
|
6
|
-
/**
|
|
7
|
-
* Normalizes a value into a stable cache key string.
|
|
8
|
-
*
|
|
9
|
-
* - Supports primitive values and structured array keys.
|
|
10
|
-
* - Produces deterministic output suitable for cache identifiers.
|
|
11
|
-
*
|
|
12
|
-
* Notes:
|
|
13
|
-
* - `null`, `undefined`, or empty arrays return `null`.
|
|
14
|
-
* - Special tokens are used for boolean, null, and undefined values
|
|
15
|
-
* to preserve semantic differences.
|
|
16
|
-
*/
|
|
2
|
+
const sanitize = (k) => k.replaceAll(/[\u200B-\u200D\uFEFF]/g, "").replaceAll(/[\r\n]/g, "").trim();
|
|
17
3
|
const normalizeCacheKey = (key, delimiter = CACHE_KEY_DELIMITER) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (typeof k === "boolean")
|
|
32
|
-
return k ? "__true" : "__false";
|
|
33
|
-
return sanitize(String(k));
|
|
34
|
-
});
|
|
35
|
-
// Join segments into a single deterministic cache key
|
|
36
|
-
return normalized.join(delimiter);
|
|
37
|
-
}
|
|
38
|
-
// Normalize boolean primitives explicitly
|
|
39
|
-
if (typeof key === "boolean")
|
|
40
|
-
return key ? "__true" : "__false";
|
|
41
|
-
// Fallback: stringify primitive values
|
|
42
|
-
return String(key);
|
|
4
|
+
if (key === null || key === void 0) return null;
|
|
5
|
+
if (Array.isArray(key)) {
|
|
6
|
+
if (key.length === 0) return null;
|
|
7
|
+
const normalized = key.map((k) => {
|
|
8
|
+
if (k === null) return "__null";
|
|
9
|
+
if (k === void 0) return "__undefined";
|
|
10
|
+
if (typeof k === "boolean") return k ? "__true" : "__false";
|
|
11
|
+
return sanitize(String(k));
|
|
12
|
+
});
|
|
13
|
+
return normalized.join(delimiter);
|
|
14
|
+
}
|
|
15
|
+
if (typeof key === "boolean") return key ? "__true" : "__false";
|
|
16
|
+
return String(key);
|
|
43
17
|
};
|
|
44
18
|
|
|
45
19
|
export { normalizeCacheKey };
|
|
@@ -1,42 +1,24 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalizes a raw pathname string into a consistent structural form.
|
|
3
|
-
*
|
|
4
|
-
* Canonical guarantees:
|
|
5
|
-
* - Leading and trailing whitespace (code points ≤ 32) are trimmed
|
|
6
|
-
* - Consecutive slashes are collapsed into a single slash
|
|
7
|
-
* - The result always starts with a single "/"
|
|
8
|
-
* - Redundant trailing slashes are removed
|
|
9
|
-
* - The root path is represented as "/"
|
|
10
|
-
*
|
|
11
|
-
* This function is deterministic and allocation-minimized.
|
|
12
|
-
*/
|
|
13
1
|
const normalizePathname = (rawPathname) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
hasSlash = true;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
result += hasSlash || result === "" ? "/" + char : char;
|
|
36
|
-
hasSlash = false;
|
|
37
|
-
}
|
|
2
|
+
const length = rawPathname.length;
|
|
3
|
+
let start = 0;
|
|
4
|
+
let end = length - 1;
|
|
5
|
+
while (start <= end && rawPathname.codePointAt(start) <= 32) start++;
|
|
6
|
+
while (end >= start && rawPathname.codePointAt(end) <= 32) end--;
|
|
7
|
+
if (start > end) return "/";
|
|
8
|
+
let result = "";
|
|
9
|
+
let hasSlash = false;
|
|
10
|
+
for (let i = start; i <= end; i++) {
|
|
11
|
+
const char = rawPathname[i];
|
|
12
|
+
if (char === "/") {
|
|
13
|
+
if (!hasSlash) {
|
|
14
|
+
hasSlash = true;
|
|
15
|
+
}
|
|
16
|
+
} else {
|
|
17
|
+
result += hasSlash || result === "" ? "/" + char : char;
|
|
18
|
+
hasSlash = false;
|
|
38
19
|
}
|
|
39
|
-
|
|
20
|
+
}
|
|
21
|
+
return result || "/";
|
|
40
22
|
};
|
|
41
23
|
|
|
42
24
|
export { normalizePathname };
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Normalize a raw query object into a string-only map.
|
|
3
|
-
*
|
|
4
|
-
* This utility is used to sanitize framework-specific query inputs
|
|
5
|
-
* into a stable shape that the routing core
|
|
6
|
-
* can safely consume.
|
|
7
|
-
*
|
|
8
|
-
* Behavior:
|
|
9
|
-
* - Keeps only entries whose values are strings
|
|
10
|
-
* - Ignores arrays, objects, and other non-string values
|
|
11
|
-
* - Does not throw or attempt to coerce values
|
|
12
|
-
*
|
|
13
|
-
* This function is intentionally conservative by design.
|
|
14
|
-
*/
|
|
15
1
|
function normalizeQuery(query) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
2
|
+
const normalized = {};
|
|
3
|
+
for (const [key, value] of Object.entries(query)) {
|
|
4
|
+
if (typeof value === "string") {
|
|
5
|
+
normalized[key] = value;
|
|
21
6
|
}
|
|
22
|
-
|
|
7
|
+
}
|
|
8
|
+
return normalized;
|
|
23
9
|
}
|
|
24
10
|
|
|
25
11
|
export { normalizeQuery };
|
|
@@ -1,22 +1,15 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Parse a raw HTTP Cookie header into a key-value record.
|
|
3
|
-
*/
|
|
4
1
|
function parseCookieHeader(cookieHeader) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const value = pair.slice(index + 1).trim();
|
|
17
|
-
record[key] = decodeURIComponent(value);
|
|
18
|
-
}
|
|
19
|
-
return record;
|
|
2
|
+
if (!cookieHeader) return {};
|
|
3
|
+
const record = {};
|
|
4
|
+
const pairs = cookieHeader.split(";");
|
|
5
|
+
for (const pair of pairs) {
|
|
6
|
+
const index = pair.indexOf("=");
|
|
7
|
+
if (index === -1) continue;
|
|
8
|
+
const key = pair.slice(0, index).trim();
|
|
9
|
+
const value = pair.slice(index + 1).trim();
|
|
10
|
+
record[key] = decodeURIComponent(value);
|
|
11
|
+
}
|
|
12
|
+
return record;
|
|
20
13
|
}
|
|
21
14
|
|
|
22
15
|
export { parseCookieHeader };
|
|
@@ -1,38 +1,12 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Resolve the effective message loader for a given runtime.
|
|
3
|
-
*
|
|
4
|
-
* Loader resolution follows an inheritance-based priority model:
|
|
5
|
-
*
|
|
6
|
-
* - client runtime:
|
|
7
|
-
* client.loader → server.loader → root loader
|
|
8
|
-
*
|
|
9
|
-
* - server runtime:
|
|
10
|
-
* server.loader → root loader
|
|
11
|
-
*
|
|
12
|
-
* This allows the client runtime to inherit server behavior
|
|
13
|
-
* when no explicit client loader is provided.
|
|
14
|
-
*
|
|
15
|
-
* Notes:
|
|
16
|
-
* - Static `messages` are intentionally NOT handled here.
|
|
17
|
-
* - Returning `undefined` indicates that no loader is enabled
|
|
18
|
-
* for the given runtime.
|
|
19
|
-
*/
|
|
20
1
|
const resolveLoaderOptions = (config, runtime) => {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const client = config.client?.loader;
|
|
26
|
-
if (client) {
|
|
27
|
-
// Client loader is always remote by design
|
|
28
|
-
return { mode: "remote", ...client };
|
|
29
|
-
}
|
|
30
|
-
return config.server?.loader ?? config.loader;
|
|
2
|
+
if (runtime === "client") {
|
|
3
|
+
const client = config.client?.loader;
|
|
4
|
+
if (client) {
|
|
5
|
+
return { mode: "remote", ...client };
|
|
31
6
|
}
|
|
32
|
-
// ------------------------------------------------
|
|
33
|
-
// runtime: server
|
|
34
|
-
// ------------------------------------------------
|
|
35
7
|
return config.server?.loader ?? config.loader;
|
|
8
|
+
}
|
|
9
|
+
return config.server?.loader ?? config.loader;
|
|
36
10
|
};
|
|
37
11
|
|
|
38
12
|
export { resolveLoaderOptions };
|
|
@@ -4,27 +4,21 @@ import 'intor-translator';
|
|
|
4
4
|
import { createTRich } from '../../core/translator/create-t-rich.js';
|
|
5
5
|
import { initTranslator } from '../translator/init-translator.js';
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* Get a edge-runtime translator for the current execution context.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
7
|
async function getTranslator(config, params) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
8
|
+
const { locale, fetch = globalThis.fetch, preKey, handlers, hooks } = params;
|
|
9
|
+
const translator = await initTranslator(config, locale, {
|
|
10
|
+
fetch,
|
|
11
|
+
...handlers !== void 0 ? { handlers } : {},
|
|
12
|
+
...hooks !== void 0 ? { hooks } : {}
|
|
13
|
+
});
|
|
14
|
+
const scoped = translator.scoped(preKey);
|
|
15
|
+
return {
|
|
16
|
+
messages: translator.messages,
|
|
17
|
+
locale: translator.locale,
|
|
18
|
+
hasKey: scoped.hasKey,
|
|
19
|
+
t: scoped.t,
|
|
20
|
+
tRich: createTRich(scoped.t)
|
|
21
|
+
};
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
export { getTranslator };
|
|
@@ -3,39 +3,31 @@ import { loadRemoteMessages } from '../../core/messages/load-remote-messages/loa
|
|
|
3
3
|
import { createTranslator } from '../../core/translator/create-translator.js';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Initialize a locale-bound Translator snapshot.
|
|
8
|
-
*
|
|
9
|
-
* - Loads translation messages using the configured remote loader, if present.
|
|
10
|
-
* - Creates an immutable Translator instance for edge runtimes
|
|
11
|
-
*/
|
|
12
6
|
async function initTranslator(config, locale, options) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
loggerOptions: config.logger,
|
|
28
|
-
});
|
|
29
|
-
messages = loaded || {};
|
|
30
|
-
}
|
|
31
|
-
// Create immutable translator snapshot
|
|
32
|
-
return createTranslator({
|
|
33
|
-
config,
|
|
34
|
-
locale,
|
|
35
|
-
messages,
|
|
36
|
-
...(handlers !== undefined ? { handlers } : {}),
|
|
37
|
-
...(hooks !== undefined ? { hooks } : {}),
|
|
7
|
+
const { loader } = config;
|
|
8
|
+
const { fetch, handlers, hooks } = options;
|
|
9
|
+
let messages = {};
|
|
10
|
+
if (loader && loader.mode === "remote") {
|
|
11
|
+
const { namespaces, concurrency, url, headers } = loader;
|
|
12
|
+
const loaded = await loadRemoteMessages({
|
|
13
|
+
locale,
|
|
14
|
+
fallbackLocales: config.fallbackLocales[locale] || [],
|
|
15
|
+
...namespaces !== void 0 ? { namespaces } : {},
|
|
16
|
+
...concurrency !== void 0 ? { concurrency } : {},
|
|
17
|
+
fetch,
|
|
18
|
+
url,
|
|
19
|
+
...headers !== void 0 ? { headers } : {},
|
|
20
|
+
loggerOptions: config.logger
|
|
38
21
|
});
|
|
22
|
+
messages = loaded || {};
|
|
23
|
+
}
|
|
24
|
+
return createTranslator({
|
|
25
|
+
config,
|
|
26
|
+
locale,
|
|
27
|
+
messages,
|
|
28
|
+
...handlers !== void 0 ? { handlers } : {},
|
|
29
|
+
...hooks !== void 0 ? { hooks } : {}
|
|
30
|
+
});
|
|
39
31
|
}
|
|
40
32
|
|
|
41
33
|
export { initTranslator };
|