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
|
@@ -2,37 +2,19 @@ import { canonicalizePathname } from './canonicalize-pathname.js';
|
|
|
2
2
|
import { materializePathname } from './materialize-pathname.js';
|
|
3
3
|
import { standardizePathname } from './standardize-pathname.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Localizes a pathname by composing canonicalization,
|
|
7
|
-
* standardization, and locale prefix strategies.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* ```ts
|
|
11
|
-
* // config.supportedLocales: ["en-US"]
|
|
12
|
-
* // config.routing.basePath: "/app"
|
|
13
|
-
* // config.routing.prefix: "all"
|
|
14
|
-
* localizePathname("/app/en-US/about", config, "en-US");
|
|
15
|
-
* // => {
|
|
16
|
-
* // pathname: '/app/en-US/about'
|
|
17
|
-
* // canonicalPathname: '/about',
|
|
18
|
-
* // templatedPathname: '/app/{locale}/about',
|
|
19
|
-
* // }
|
|
20
|
-
* ```
|
|
21
|
-
*
|
|
22
|
-
* @public
|
|
23
|
-
*/
|
|
24
5
|
const localizePathname = (rawPathname, config, locale) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
6
|
+
const canonicalPathname = canonicalizePathname(rawPathname, config);
|
|
7
|
+
const standardizedPathname = standardizePathname(canonicalPathname, config);
|
|
8
|
+
const materializedPathname = materializePathname(
|
|
9
|
+
standardizedPathname,
|
|
10
|
+
config,
|
|
11
|
+
locale
|
|
12
|
+
);
|
|
13
|
+
return {
|
|
14
|
+
canonicalPathname,
|
|
15
|
+
templatedPathname: standardizedPathname,
|
|
16
|
+
pathname: materializedPathname
|
|
17
|
+
};
|
|
36
18
|
};
|
|
37
19
|
|
|
38
20
|
export { localizePathname };
|
|
@@ -3,51 +3,16 @@ import 'logry';
|
|
|
3
3
|
import 'p-limit';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Materializes a standardized pathname into a concrete, locale-aware URL.
|
|
8
|
-
*
|
|
9
|
-
* This function resolves the `{locale}` placeholder according to the
|
|
10
|
-
* configured `localePrefix` strategy and produces the final pathname.
|
|
11
|
-
*
|
|
12
|
-
* Behavior:
|
|
13
|
-
* - "all": always injects the locale segment
|
|
14
|
-
* - "except-default": injects the locale unless it equals `defaultLocale`
|
|
15
|
-
* - "none": removes the locale placeholder entirely
|
|
16
|
-
*
|
|
17
|
-
* Invariants:
|
|
18
|
-
* - `standardizedPathname` must be produced by `standardizePathname`
|
|
19
|
-
* - The pathname must contain exactly one `{locale}` placeholder
|
|
20
|
-
* - The placeholder must appear as the first path segment
|
|
21
|
-
*
|
|
22
|
-
* This function performs structural transformation only.
|
|
23
|
-
* It does not normalize or sanitize the resulting pathname.
|
|
24
|
-
*
|
|
25
|
-
* @example
|
|
26
|
-
* ```ts
|
|
27
|
-
* // config.routing.localePrefix: "all"
|
|
28
|
-
* materializePathname("/app/{locale}/about", config, "en");
|
|
29
|
-
* // => /app/en/about
|
|
30
|
-
*
|
|
31
|
-
* // config.routing.localePrefix: "none"
|
|
32
|
-
* materializePathname("/app/{locale}/about", config, "en");
|
|
33
|
-
* // => /app/about
|
|
34
|
-
* ```
|
|
35
|
-
*/
|
|
36
6
|
const materializePathname = (standardizedPathname, config, locale) => {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
// localePrefix: "all"
|
|
47
|
-
if (localePrefix === "all")
|
|
48
|
-
return injectLocale();
|
|
49
|
-
// localePrefix: "except-default"
|
|
50
|
-
return locale === config.defaultLocale ? removeLocale() : injectLocale();
|
|
7
|
+
const { localePrefix } = config.routing;
|
|
8
|
+
const removeLocale = () => {
|
|
9
|
+
const result = standardizedPathname.replace(`/${LOCALE_PLACEHOLDER}`, "");
|
|
10
|
+
return result === "" ? "/" : result;
|
|
11
|
+
};
|
|
12
|
+
const injectLocale = () => standardizedPathname.replace(LOCALE_PLACEHOLDER, locale);
|
|
13
|
+
if (localePrefix === "none") return removeLocale();
|
|
14
|
+
if (localePrefix === "all") return injectLocale();
|
|
15
|
+
return locale === config.defaultLocale ? removeLocale() : injectLocale();
|
|
51
16
|
};
|
|
52
17
|
|
|
53
18
|
export { materializePathname };
|
|
@@ -3,37 +3,13 @@ import 'logry';
|
|
|
3
3
|
import 'p-limit';
|
|
4
4
|
import 'intor-translator';
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* Standardizes a canonical pathname into an internal routing template.
|
|
8
|
-
*
|
|
9
|
-
* Standardized representation:
|
|
10
|
-
* - Prepends the deployment prefix (`basePath`) if defined
|
|
11
|
-
* - Injects the `{locale}` placeholder as the first path segment
|
|
12
|
-
* - Preserves the canonical pathname structure
|
|
13
|
-
*
|
|
14
|
-
* Input must be a canonical pathname.
|
|
15
|
-
*
|
|
16
|
-
* Output is an internal routing template and
|
|
17
|
-
* is not a locale-resolved URL.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* ```ts
|
|
21
|
-
* // config.routing.basePath: "/app",
|
|
22
|
-
* standardizePathname("/about", config);
|
|
23
|
-
* // => "/app/{locale}/about"
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
6
|
const standardizePathname = (canonicalPathname, config) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
return basePath
|
|
35
|
-
? `${basePath}/${LOCALE_PLACEHOLDER}${canonicalPathname}`
|
|
36
|
-
: `/${LOCALE_PLACEHOLDER}${canonicalPathname}`;
|
|
7
|
+
const { routing } = config;
|
|
8
|
+
const basePath = routing.basePath && routing.basePath !== "/" ? routing.basePath : "";
|
|
9
|
+
if (canonicalPathname === "/") {
|
|
10
|
+
return basePath ? `${basePath}/${LOCALE_PLACEHOLDER}` : `/${LOCALE_PLACEHOLDER}`;
|
|
11
|
+
}
|
|
12
|
+
return basePath ? `${basePath}/${LOCALE_PLACEHOLDER}${canonicalPathname}` : `/${LOCALE_PLACEHOLDER}${canonicalPathname}`;
|
|
37
13
|
};
|
|
38
14
|
|
|
39
15
|
export { standardizePathname };
|
|
@@ -1,51 +1,32 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { getClientLocale } from 'intor';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Client-side Intor runtime helper.
|
|
6
|
-
*
|
|
7
|
-
* Manages locale state and dynamic message loading
|
|
8
|
-
* in pure client-side (SPA) environments.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
4
|
function useIntor(config, loader) {
|
|
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
|
-
React.useEffect(() => {
|
|
40
|
-
void onLocaleChange(locale);
|
|
41
|
-
}, [locale, onLocaleChange]);
|
|
42
|
-
return {
|
|
43
|
-
config,
|
|
44
|
-
locale,
|
|
45
|
-
messages,
|
|
46
|
-
isLoading,
|
|
47
|
-
onLocaleChange,
|
|
48
|
-
};
|
|
5
|
+
const locale = React.useMemo(() => getClientLocale(config), [config]);
|
|
6
|
+
const [messages, setMessages] = React.useState(config.messages || {});
|
|
7
|
+
const [isLoading, setIsLoading] = React.useState(true);
|
|
8
|
+
const activeLocaleRef = React.useRef(locale);
|
|
9
|
+
const onLocaleChange = React.useCallback(
|
|
10
|
+
async (newLocale) => {
|
|
11
|
+
activeLocaleRef.current = newLocale;
|
|
12
|
+
setIsLoading(true);
|
|
13
|
+
const loaded = await loader(config, newLocale);
|
|
14
|
+
if (activeLocaleRef.current !== newLocale) return;
|
|
15
|
+
setMessages(loaded);
|
|
16
|
+
setIsLoading(false);
|
|
17
|
+
},
|
|
18
|
+
[config, loader]
|
|
19
|
+
);
|
|
20
|
+
React.useEffect(() => {
|
|
21
|
+
void onLocaleChange(locale);
|
|
22
|
+
}, [locale, onLocaleChange]);
|
|
23
|
+
return {
|
|
24
|
+
config,
|
|
25
|
+
locale,
|
|
26
|
+
messages,
|
|
27
|
+
isLoading,
|
|
28
|
+
onLocaleChange
|
|
29
|
+
};
|
|
49
30
|
}
|
|
50
31
|
|
|
51
32
|
export { useIntor };
|
|
@@ -9,31 +9,26 @@ import { setLocaleCookie } from '../../../shared/utils/locale/set-locale-cookie.
|
|
|
9
9
|
import { setDocumentLocale } from '../../../shared/utils/locale/set-document-locale.js';
|
|
10
10
|
|
|
11
11
|
function useLocaleEffects(config, locale) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
// -----------------------------------------------------------------------
|
|
33
|
-
if (cookie.persist) {
|
|
34
|
-
setLocaleCookie(cookie, locale);
|
|
35
|
-
}
|
|
36
|
-
}, [locale, cookie, routing.inbound.firstVisit.persist]);
|
|
12
|
+
const { cookie, routing } = config;
|
|
13
|
+
const isFirstSyncRef = React.useRef(true);
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
setDocumentLocale(locale);
|
|
16
|
+
if (isFirstSyncRef.current) {
|
|
17
|
+
isFirstSyncRef.current = false;
|
|
18
|
+
const localeCookie = getLocaleFromCookie(cookie.name);
|
|
19
|
+
const isFirstVisit = !localeCookie;
|
|
20
|
+
if (shouldPersistOnFirstVisit(
|
|
21
|
+
isFirstVisit,
|
|
22
|
+
routing.inbound.firstVisit.persist
|
|
23
|
+
) && cookie.persist) {
|
|
24
|
+
setLocaleCookie(cookie, locale);
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (cookie.persist) {
|
|
29
|
+
setLocaleCookie(cookie, locale);
|
|
30
|
+
}
|
|
31
|
+
}, [locale, cookie, routing.inbound.firstVisit.persist]);
|
|
37
32
|
}
|
|
38
33
|
|
|
39
34
|
export { useLocaleEffects };
|
|
@@ -3,22 +3,23 @@ import * as React from 'react';
|
|
|
3
3
|
import { createRefetchMessages } from '../../../shared/messages/create-refetch-messages.js';
|
|
4
4
|
|
|
5
5
|
function useMessagesEffects(config, locale, setRuntimeMessages, setInternalIsLoading) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}),
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const refetchMessages = React.useMemo(
|
|
7
|
+
() => createRefetchMessages({
|
|
8
|
+
config,
|
|
9
|
+
onLoadingStart: () => setInternalIsLoading(true),
|
|
10
|
+
onLoadingEnd: () => setInternalIsLoading(false),
|
|
11
|
+
onMessages: setRuntimeMessages
|
|
12
|
+
}),
|
|
13
|
+
[config, setRuntimeMessages, setInternalIsLoading]
|
|
14
|
+
);
|
|
15
|
+
const isInitialRenderRef = React.useRef(true);
|
|
16
|
+
React.useEffect(() => {
|
|
17
|
+
if (isInitialRenderRef.current) {
|
|
18
|
+
isInitialRenderRef.current = false;
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
void refetchMessages(locale);
|
|
22
|
+
}, [refetchMessages, locale]);
|
|
22
23
|
}
|
|
23
24
|
|
|
24
25
|
export { useMessagesEffects };
|
|
@@ -1,76 +1,73 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx } from 'react/jsx-runtime';
|
|
3
2
|
import { Translator } from 'intor-translator';
|
|
4
3
|
import * as React from 'react';
|
|
5
4
|
import { resolveEffectiveMessages, resolveEffectiveIsLoading } from '../../shared/provider/effective-state.js';
|
|
6
5
|
import { useLocaleEffects } from './effects/use-locale-effects.js';
|
|
7
6
|
import { useMessagesEffects } from './effects/use-messages-effects.js';
|
|
8
7
|
|
|
9
|
-
const IntorContext = React.createContext(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
}, [initialLocale]);
|
|
73
|
-
return (jsx(IntorContext.Provider, { value: { config, locale, setLocale, translator }, children: children }));
|
|
8
|
+
const IntorContext = React.createContext(
|
|
9
|
+
void 0
|
|
10
|
+
);
|
|
11
|
+
function IntorProvider({
|
|
12
|
+
value: {
|
|
13
|
+
config,
|
|
14
|
+
locale: initialLocale,
|
|
15
|
+
messages,
|
|
16
|
+
handlers,
|
|
17
|
+
hooks,
|
|
18
|
+
onLocaleChange,
|
|
19
|
+
isLoading: externalIsLoading
|
|
20
|
+
},
|
|
21
|
+
children
|
|
22
|
+
}) {
|
|
23
|
+
const [locale, setLocaleState] = React.useState(initialLocale);
|
|
24
|
+
const [runtimeMessages, setRuntimeMessages] = React.useState(null);
|
|
25
|
+
const [internalIsLoading, setInternalIsLoading] = React.useState(false);
|
|
26
|
+
const setLocale = React.useCallback(
|
|
27
|
+
(newLocale) => {
|
|
28
|
+
if (newLocale === locale) return;
|
|
29
|
+
setLocaleState(newLocale);
|
|
30
|
+
void onLocaleChange?.(newLocale);
|
|
31
|
+
},
|
|
32
|
+
[locale, onLocaleChange]
|
|
33
|
+
);
|
|
34
|
+
const effectiveIsLoading = resolveEffectiveIsLoading(
|
|
35
|
+
!!externalIsLoading,
|
|
36
|
+
internalIsLoading
|
|
37
|
+
);
|
|
38
|
+
const effectiveMessages = resolveEffectiveMessages(
|
|
39
|
+
runtimeMessages,
|
|
40
|
+
messages,
|
|
41
|
+
config.messages
|
|
42
|
+
);
|
|
43
|
+
const { loadingMessage, missingMessage } = config.translator ?? {};
|
|
44
|
+
const translator = React.useMemo(() => {
|
|
45
|
+
return new Translator({
|
|
46
|
+
messages: effectiveMessages,
|
|
47
|
+
locale,
|
|
48
|
+
isLoading: effectiveIsLoading,
|
|
49
|
+
fallbackLocales: config.fallbackLocales,
|
|
50
|
+
...loadingMessage !== void 0 ? { loadingMessage } : {},
|
|
51
|
+
...missingMessage !== void 0 ? { missingMessage } : {},
|
|
52
|
+
...handlers !== void 0 ? { handlers } : {},
|
|
53
|
+
...hooks !== void 0 ? { hooks } : {}
|
|
54
|
+
});
|
|
55
|
+
}, [
|
|
56
|
+
effectiveMessages,
|
|
57
|
+
locale,
|
|
58
|
+
effectiveIsLoading,
|
|
59
|
+
config.fallbackLocales,
|
|
60
|
+
loadingMessage,
|
|
61
|
+
missingMessage,
|
|
62
|
+
handlers,
|
|
63
|
+
hooks
|
|
64
|
+
]);
|
|
65
|
+
useLocaleEffects(config, locale);
|
|
66
|
+
useMessagesEffects(config, locale, setRuntimeMessages, setInternalIsLoading);
|
|
67
|
+
React.useEffect(() => {
|
|
68
|
+
if (initialLocale !== locale) setLocaleState(initialLocale);
|
|
69
|
+
}, [initialLocale]);
|
|
70
|
+
return /* @__PURE__ */ React.createElement(IntorContext.Provider, { value: { config, locale, setLocale, translator } }, children);
|
|
74
71
|
}
|
|
75
72
|
|
|
76
73
|
export { IntorContext, IntorProvider };
|
|
@@ -2,10 +2,10 @@ import React__default from 'react';
|
|
|
2
2
|
import { IntorContext } from './intor-provider.js';
|
|
3
3
|
|
|
4
4
|
function useIntorContext() {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const context = React__default.useContext(IntorContext);
|
|
6
|
+
if (!context)
|
|
7
|
+
throw new Error("useIntorContext must be used within IntorProvider");
|
|
8
|
+
return context;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
export { useIntorContext };
|
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Create a React renderer for semantic rich messages.
|
|
5
|
-
*/
|
|
6
3
|
const createReactRenderer = (tagRenderers) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return value;
|
|
26
|
-
},
|
|
27
|
-
};
|
|
4
|
+
return {
|
|
5
|
+
/** Render plain text nodes */
|
|
6
|
+
text(value) {
|
|
7
|
+
return value;
|
|
8
|
+
},
|
|
9
|
+
/** Render semantic tag nodes */
|
|
10
|
+
tag(name, _attributes, children) {
|
|
11
|
+
const tagRenderer = tagRenderers?.[name];
|
|
12
|
+
if (tagRenderer) {
|
|
13
|
+
return typeof tagRenderer === "function" ? tagRenderer(children) : tagRenderer;
|
|
14
|
+
}
|
|
15
|
+
return React.createElement(name, null, ...children);
|
|
16
|
+
},
|
|
17
|
+
/** Render raw (non-tokenized) message values */
|
|
18
|
+
raw(value) {
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
28
22
|
};
|
|
29
23
|
|
|
30
24
|
export { createReactRenderer };
|
|
@@ -2,29 +2,16 @@ import { renderRichMessage } from 'intor-translator';
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { createReactRenderer } from '../render/create-react-renderer.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Create a React-specific rich translation function.
|
|
7
|
-
*
|
|
8
|
-
* This adapter bridges the core Translator with the React rich
|
|
9
|
-
* message rendering flow.
|
|
10
|
-
*
|
|
11
|
-
* - Resolves translated messages via `translator.t`
|
|
12
|
-
* - Renders semantic tags using React renderers
|
|
13
|
-
* - Supports optional scoped keys via `preKey`
|
|
14
|
-
*
|
|
15
|
-
* Intended for React client usage only.
|
|
16
|
-
*/
|
|
17
5
|
const createTRich = (t) => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
};
|
|
6
|
+
return (key, tagRenderers, replacements) => {
|
|
7
|
+
const message = t(key, replacements);
|
|
8
|
+
const reactRenderer = createReactRenderer(tagRenderers);
|
|
9
|
+
const nodes = renderRichMessage(message, reactRenderer);
|
|
10
|
+
if (!Array.isArray(nodes)) return nodes;
|
|
11
|
+
return nodes.map(
|
|
12
|
+
(node, i) => React.isValidElement(node) && node.key == null ? React.cloneElement(node, { key: i }) : node
|
|
13
|
+
);
|
|
14
|
+
};
|
|
28
15
|
};
|
|
29
16
|
|
|
30
17
|
export { createTRich };
|
|
@@ -2,23 +2,18 @@ import '../provider/intor-provider.js';
|
|
|
2
2
|
import { useIntorContext } from '../provider/use-intor-context.js';
|
|
3
3
|
import { createTRich } from './create-t-rich.js';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* React hook for accessing the active, scope-aware translator instance.
|
|
7
|
-
*
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
10
5
|
function useTranslator(preKey) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const { translator, setLocale } = useIntorContext();
|
|
7
|
+
const scoped = translator.scoped(preKey);
|
|
8
|
+
return {
|
|
9
|
+
messages: translator.messages,
|
|
10
|
+
locale: translator.locale,
|
|
11
|
+
isLoading: translator.isLoading,
|
|
12
|
+
setLocale,
|
|
13
|
+
hasKey: scoped.hasKey,
|
|
14
|
+
t: scoped.t,
|
|
15
|
+
tRich: createTRich(scoped.t)
|
|
16
|
+
};
|
|
22
17
|
}
|
|
23
18
|
|
|
24
19
|
export { useTranslator };
|