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,35 +1,24 @@
|
|
|
1
1
|
import { getLogger } from '../logger/get-logger.js';
|
|
2
2
|
import { deepMerge } from '../utils/deep-merge.js';
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* Merge locale-specific messages with runtime overrides.
|
|
6
|
-
*
|
|
7
|
-
* - Only merges messages under the given locale
|
|
8
|
-
* - Emits debug logs for add / override events
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
4
|
function mergeMessages(a, b, { config, locale, onEvent }) {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
...a,
|
|
31
|
-
[locale]: merged,
|
|
32
|
-
};
|
|
5
|
+
const baseLogger = getLogger({ ...config.logger, id: config.id });
|
|
6
|
+
const logger = baseLogger.child({ scope: "merge-messages" });
|
|
7
|
+
const merged = deepMerge(a?.[locale] ?? {}, b?.[locale] ?? {}, {
|
|
8
|
+
onOverride: (event) => {
|
|
9
|
+
if (onEvent) {
|
|
10
|
+
onEvent(event);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const { kind, path, next, prev } = event;
|
|
14
|
+
if (kind === "add") return;
|
|
15
|
+
logger.debug(`Override | ${locale}: "${path}"`, { prev, next });
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
return {
|
|
19
|
+
...a,
|
|
20
|
+
[locale]: merged
|
|
21
|
+
};
|
|
33
22
|
}
|
|
34
23
|
|
|
35
24
|
export { mergeMessages };
|
|
@@ -1,44 +1,29 @@
|
|
|
1
|
-
/** Check if a value is a plain object (not null, not array) */
|
|
2
1
|
function isPlainObject(value) {
|
|
3
|
-
|
|
2
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
4
3
|
}
|
|
5
|
-
/**
|
|
6
|
-
* Check if a value is a valid MessageObject.
|
|
7
|
-
*
|
|
8
|
-
* - Supports all MessageValue variants (primitive, array, object).
|
|
9
|
-
* - Uses an iterative approach to avoid stack overflow.
|
|
10
|
-
*/
|
|
11
4
|
function isValidMessages(value) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (current === null ||
|
|
19
|
-
typeof current === "string" ||
|
|
20
|
-
typeof current === "number" ||
|
|
21
|
-
typeof current === "boolean") {
|
|
22
|
-
continue;
|
|
23
|
-
}
|
|
24
|
-
// array → validate each item
|
|
25
|
-
if (Array.isArray(current)) {
|
|
26
|
-
for (const item of current) {
|
|
27
|
-
stack.push(item);
|
|
28
|
-
}
|
|
29
|
-
continue;
|
|
30
|
-
}
|
|
31
|
-
// object → validate each value
|
|
32
|
-
if (isPlainObject(current)) {
|
|
33
|
-
for (const v of Object.values(current)) {
|
|
34
|
-
stack.push(v);
|
|
35
|
-
}
|
|
36
|
-
continue;
|
|
37
|
-
}
|
|
38
|
-
// everything else is invalid
|
|
39
|
-
return false;
|
|
5
|
+
if (!isPlainObject(value)) return false;
|
|
6
|
+
const stack = [value];
|
|
7
|
+
while (stack.length > 0) {
|
|
8
|
+
const current = stack.pop();
|
|
9
|
+
if (current === null || typeof current === "string" || typeof current === "number" || typeof current === "boolean") {
|
|
10
|
+
continue;
|
|
40
11
|
}
|
|
41
|
-
|
|
12
|
+
if (Array.isArray(current)) {
|
|
13
|
+
for (const item of current) {
|
|
14
|
+
stack.push(item);
|
|
15
|
+
}
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
if (isPlainObject(current)) {
|
|
19
|
+
for (const v of Object.values(current)) {
|
|
20
|
+
stack.push(v);
|
|
21
|
+
}
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
return true;
|
|
42
27
|
}
|
|
43
28
|
|
|
44
29
|
export { isPlainObject, isValidMessages };
|
|
@@ -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,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,34 +1,11 @@
|
|
|
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
|
+
{
|
|
3
|
+
const client = config.client?.loader;
|
|
4
|
+
if (client) {
|
|
5
|
+
return { mode: "remote", ...client };
|
|
31
6
|
}
|
|
7
|
+
return config.server?.loader ?? config.loader;
|
|
8
|
+
}
|
|
32
9
|
};
|
|
33
10
|
|
|
34
11
|
export { resolveLoaderOptions };
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Allow locale persistence based on first-visit policy.
|
|
3
|
-
*/
|
|
4
1
|
function shouldPersistOnFirstVisit(isFirstVisit, persistOnFirstVisit) {
|
|
5
|
-
|
|
2
|
+
return !isFirstVisit || persistOnFirstVisit;
|
|
6
3
|
}
|
|
7
4
|
|
|
8
5
|
export { shouldPersistOnFirstVisit };
|
|
@@ -3,12 +3,6 @@ import IntorProviderComponent from '../../src/client/svelte/provider/intor-provi
|
|
|
3
3
|
import 'svelte';
|
|
4
4
|
export { useTranslator } from '../../src/client/svelte/translator/use-translator.js';
|
|
5
5
|
|
|
6
|
-
// intor / svelte
|
|
7
|
-
/**
|
|
8
|
-
* Svelte provider component for Intor.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
6
|
const IntorProvider = IntorProviderComponent;
|
|
13
7
|
|
|
14
8
|
export { IntorProvider };
|
|
@@ -4,57 +4,47 @@ import { loadRemoteMessages } from '../../../core/messages/load-remote-messages/
|
|
|
4
4
|
import { mergeMessages } from '../../../core/messages/merge-messages.js';
|
|
5
5
|
import 'intor-translator';
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
finally {
|
|
51
|
-
// Clear loading state only if this request is still the active one
|
|
52
|
-
if (controller === currentController &&
|
|
53
|
-
!currentController.signal.aborted) {
|
|
54
|
-
onLoadingEnd?.();
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
};
|
|
7
|
+
const createRefetchMessages = ({
|
|
8
|
+
config,
|
|
9
|
+
onLoadingStart,
|
|
10
|
+
onLoadingEnd,
|
|
11
|
+
onMessages
|
|
12
|
+
}) => {
|
|
13
|
+
let controller = null;
|
|
14
|
+
return async function refetchMessages(newLocale) {
|
|
15
|
+
const loader = resolveLoaderOptions(config);
|
|
16
|
+
if (!loader || loader.mode !== "remote") return;
|
|
17
|
+
const { namespaces, concurrency, url, headers } = loader;
|
|
18
|
+
controller?.abort();
|
|
19
|
+
const currentController = new AbortController();
|
|
20
|
+
controller = currentController;
|
|
21
|
+
onLoadingStart?.();
|
|
22
|
+
try {
|
|
23
|
+
const loadedMessages = await loadRemoteMessages({
|
|
24
|
+
locale: newLocale,
|
|
25
|
+
fallbackLocales: config.fallbackLocales[newLocale] || [],
|
|
26
|
+
...namespaces !== void 0 ? { namespaces } : {},
|
|
27
|
+
...concurrency !== void 0 ? { concurrency } : {},
|
|
28
|
+
fetch: globalThis.fetch,
|
|
29
|
+
url,
|
|
30
|
+
...headers !== void 0 ? { headers } : {},
|
|
31
|
+
signal: currentController.signal,
|
|
32
|
+
loggerOptions: config.logger
|
|
33
|
+
});
|
|
34
|
+
if (controller === currentController && !currentController.signal.aborted) {
|
|
35
|
+
onMessages?.(
|
|
36
|
+
mergeMessages(config.messages, loadedMessages, {
|
|
37
|
+
config,
|
|
38
|
+
locale: newLocale
|
|
39
|
+
})
|
|
40
|
+
);
|
|
41
|
+
}
|
|
42
|
+
} finally {
|
|
43
|
+
if (controller === currentController && !currentController.signal.aborted) {
|
|
44
|
+
onLoadingEnd?.();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
58
48
|
};
|
|
59
49
|
|
|
60
50
|
export { createRefetchMessages };
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
// runtime > external > config
|
|
2
|
-
// Always resolves to a non-null message object.
|
|
3
1
|
function resolveEffectiveMessages(runtime, external, configMessages) {
|
|
4
|
-
|
|
2
|
+
return runtime ?? external ?? configMessages ?? {};
|
|
5
3
|
}
|
|
6
|
-
// external > internal
|
|
7
|
-
// Loading is active if either source is truthy
|
|
8
4
|
function resolveEffectiveIsLoading(external, internal) {
|
|
9
|
-
|
|
5
|
+
return !!external || internal;
|
|
10
6
|
}
|
|
11
7
|
|
|
12
8
|
export { resolveEffectiveIsLoading, resolveEffectiveMessages };
|
|
@@ -1,31 +1,22 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Build a serialized cookie string.
|
|
3
|
-
*/
|
|
4
1
|
const buildCookieString = (cookieOptions, value) => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
// Add Secure flag if not explicitly disabled
|
|
25
|
-
if (secure !== false) {
|
|
26
|
-
parts.push(`Secure`);
|
|
27
|
-
}
|
|
28
|
-
return parts.join("; ");
|
|
2
|
+
const { name, maxAge, path, domain, sameSite, secure } = cookieOptions;
|
|
3
|
+
const parts = [`${name}=${encodeURIComponent(value)}`];
|
|
4
|
+
if (maxAge !== void 0) {
|
|
5
|
+
const expires = new Date(Date.now() + maxAge * 1e3).toUTCString();
|
|
6
|
+
parts.push(`expires=${expires}`, `max-age=${maxAge}`);
|
|
7
|
+
}
|
|
8
|
+
parts.push(`path=${path ?? "/"}`);
|
|
9
|
+
if (domain) {
|
|
10
|
+
parts.push(`domain=${domain}`);
|
|
11
|
+
}
|
|
12
|
+
if (sameSite) {
|
|
13
|
+
const normalized = sameSite.charAt(0).toUpperCase() + sameSite.slice(1).toLowerCase();
|
|
14
|
+
parts.push(`SameSite=${normalized}`);
|
|
15
|
+
}
|
|
16
|
+
if (secure !== false) {
|
|
17
|
+
parts.push(`Secure`);
|
|
18
|
+
}
|
|
19
|
+
return parts.join("; ");
|
|
29
20
|
};
|
|
30
21
|
|
|
31
22
|
export { buildCookieString };
|
|
@@ -1,16 +1,9 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Gets the locale value from the browser cookie.
|
|
3
|
-
*
|
|
4
|
-
* This function relies on `document.cookie`.
|
|
5
|
-
*/
|
|
6
1
|
function getLocaleFromCookie(cookieName) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return undefined;
|
|
13
|
-
return decodeURIComponent(entry.slice(cookieName.length + 1));
|
|
2
|
+
if (typeof document === "undefined") return void 0;
|
|
3
|
+
const cookies = document.cookie.split(";").map((c) => c.trim());
|
|
4
|
+
const entry = cookies.find((c) => c.startsWith(`${cookieName}=`));
|
|
5
|
+
if (!entry) return void 0;
|
|
6
|
+
return decodeURIComponent(entry.slice(cookieName.length + 1));
|
|
14
7
|
}
|
|
15
8
|
|
|
16
9
|
export { getLocaleFromCookie };
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Set the document language attribute.
|
|
3
|
-
*
|
|
4
|
-
* This function relies on `document.documentElement.lang`.
|
|
5
|
-
*/
|
|
6
1
|
function setDocumentLocale(locale) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
document.documentElement.lang = locale;
|
|
2
|
+
if (typeof document === "undefined") return;
|
|
3
|
+
document.documentElement.lang = locale;
|
|
10
4
|
}
|
|
11
5
|
|
|
12
6
|
export { setDocumentLocale };
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { buildCookieString } from '../build-cookie-string.js';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* Persist locale to a cookie.
|
|
5
|
-
*
|
|
6
|
-
* This function relies on `document.cookie`.
|
|
7
|
-
*/
|
|
8
3
|
const setLocaleCookie = (cookieOptions, locale) => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
// Build and apply the cookie string
|
|
12
|
-
document.cookie = buildCookieString(cookieOptions, locale);
|
|
4
|
+
if (typeof document === "undefined") return;
|
|
5
|
+
document.cookie = buildCookieString(cookieOptions, locale);
|
|
13
6
|
};
|
|
14
7
|
|
|
15
8
|
export { setLocaleCookie };
|
|
@@ -5,71 +5,67 @@ import { resolveEffectiveIsLoading, resolveEffectiveMessages } from '../../share
|
|
|
5
5
|
import { attachLocaleEffects } from './effects/attach-locale-effects.js';
|
|
6
6
|
import { attachMessagesEffects } from './effects/attach-messages-effects.js';
|
|
7
7
|
|
|
8
|
-
const INTOR_CONTEXT_KEY = Symbol("IntorContext");
|
|
9
|
-
function buildIntorStores({
|
|
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
|
-
|
|
8
|
+
const INTOR_CONTEXT_KEY = /* @__PURE__ */ Symbol("IntorContext");
|
|
9
|
+
function buildIntorStores({
|
|
10
|
+
config,
|
|
11
|
+
locale: initialLocale,
|
|
12
|
+
messages,
|
|
13
|
+
handlers,
|
|
14
|
+
hooks,
|
|
15
|
+
onLocaleChange,
|
|
16
|
+
isLoading: externalIsLoading
|
|
17
|
+
}) {
|
|
18
|
+
const locale = writable(initialLocale);
|
|
19
|
+
const runtimeMessages = writable(null);
|
|
20
|
+
const internalIsLoading = writable(false);
|
|
21
|
+
function setLocale(next) {
|
|
22
|
+
const current = get(locale);
|
|
23
|
+
if (next === current) return;
|
|
24
|
+
locale.set(next);
|
|
25
|
+
void onLocaleChange?.(next);
|
|
26
|
+
}
|
|
27
|
+
const externalIsLoadingStore = typeof externalIsLoading === "object" && "subscribe" in externalIsLoading ? externalIsLoading : readable(!!externalIsLoading);
|
|
28
|
+
const effectiveIsLoading = derived(
|
|
29
|
+
[externalIsLoadingStore, internalIsLoading],
|
|
30
|
+
([$external, $internal]) => resolveEffectiveIsLoading($external, $internal)
|
|
31
|
+
);
|
|
32
|
+
const effectiveMessages = derived(
|
|
33
|
+
runtimeMessages,
|
|
34
|
+
($runtime) => resolveEffectiveMessages($runtime, messages, config.messages)
|
|
35
|
+
);
|
|
36
|
+
const { loadingMessage, missingMessage } = config.translator ?? {};
|
|
37
|
+
const translator = derived(
|
|
38
|
+
[effectiveMessages, locale, effectiveIsLoading],
|
|
39
|
+
([$messages, $locale, $isLoading]) => new Translator({
|
|
40
|
+
messages: $messages,
|
|
41
|
+
locale: $locale,
|
|
42
|
+
isLoading: $isLoading,
|
|
43
|
+
fallbackLocales: config.fallbackLocales,
|
|
44
|
+
...loadingMessage !== void 0 ? { loadingMessage } : {},
|
|
45
|
+
...missingMessage !== void 0 ? { missingMessage } : {},
|
|
46
|
+
...handlers !== void 0 ? { handlers } : {},
|
|
47
|
+
...hooks !== void 0 ? { hooks } : {}
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
return {
|
|
51
|
+
config,
|
|
52
|
+
locale,
|
|
53
|
+
setLocale,
|
|
54
|
+
translator,
|
|
55
|
+
runtimeMessages,
|
|
56
|
+
internalIsLoading
|
|
57
|
+
};
|
|
57
58
|
}
|
|
58
|
-
/**
|
|
59
|
-
* Svelte initializer for Intor.
|
|
60
|
-
*
|
|
61
|
-
* @public
|
|
62
|
-
*/
|
|
63
59
|
function createIntorStore(value) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
60
|
+
const stores = buildIntorStores(value);
|
|
61
|
+
attachLocaleEffects(stores.locale, value.config);
|
|
62
|
+
attachMessagesEffects({
|
|
63
|
+
config: value.config,
|
|
64
|
+
locale: stores.locale,
|
|
65
|
+
runtimeMessages: stores.runtimeMessages,
|
|
66
|
+
internalIsLoading: stores.internalIsLoading
|
|
67
|
+
});
|
|
68
|
+
setContext(INTOR_CONTEXT_KEY, stores);
|
|
73
69
|
}
|
|
74
70
|
|
|
75
71
|
export { INTOR_CONTEXT_KEY, buildIntorStores, createIntorStore };
|