@sebbro/paraglide-lite 0.1.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 +21 -0
- package/README.md +67 -0
- package/bin/run.js +4 -0
- package/dist/bundler-plugins/esbuild.d.ts +1 -0
- package/dist/bundler-plugins/esbuild.d.ts.map +1 -0
- package/dist/bundler-plugins/esbuild.js +4 -0
- package/dist/bundler-plugins/esbuild.js.map +1 -0
- package/dist/bundler-plugins/index.d.ts +6 -0
- package/dist/bundler-plugins/index.d.ts.map +1 -0
- package/dist/bundler-plugins/index.js +7 -0
- package/dist/bundler-plugins/index.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.d.ts +19 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.js +85 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.test.d.ts +2 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.test.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.test.js +53 -0
- package/dist/bundler-plugins/lazy-modules/scan-message-keys.test.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/ssr.d.ts +31 -0
- package/dist/bundler-plugins/lazy-modules/ssr.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/ssr.js +42 -0
- package/dist/bundler-plugins/lazy-modules/ssr.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/ssr.test.d.ts +2 -0
- package/dist/bundler-plugins/lazy-modules/ssr.test.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/ssr.test.js +48 -0
- package/dist/bundler-plugins/lazy-modules/ssr.test.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/virtual-ids.d.ts +7 -0
- package/dist/bundler-plugins/lazy-modules/virtual-ids.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/virtual-ids.js +30 -0
- package/dist/bundler-plugins/lazy-modules/virtual-ids.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/virtual.d.ts +86 -0
- package/dist/bundler-plugins/lazy-modules/virtual.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/virtual.js +2 -0
- package/dist/bundler-plugins/lazy-modules/virtual.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.d.ts +18 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.js +328 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.js.map +1 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.test.d.ts +2 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.test.d.ts.map +1 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.test.js +45 -0
- package/dist/bundler-plugins/lazy-modules/vite-plugin.test.js.map +1 -0
- package/dist/bundler-plugins/per-locale-build/constants.d.ts +2 -0
- package/dist/bundler-plugins/per-locale-build/constants.d.ts.map +1 -0
- package/dist/bundler-plugins/per-locale-build/constants.js +3 -0
- package/dist/bundler-plugins/per-locale-build/constants.js.map +1 -0
- package/dist/bundler-plugins/per-locale-build/index.d.ts +6 -0
- package/dist/bundler-plugins/per-locale-build/index.d.ts.map +1 -0
- package/dist/bundler-plugins/per-locale-build/index.js +43 -0
- package/dist/bundler-plugins/per-locale-build/index.js.map +1 -0
- package/dist/bundler-plugins/per-locale-build/locale-id.d.ts +8 -0
- package/dist/bundler-plugins/per-locale-build/locale-id.d.ts.map +1 -0
- package/dist/bundler-plugins/per-locale-build/locale-id.js +13 -0
- package/dist/bundler-plugins/per-locale-build/locale-id.js.map +1 -0
- package/dist/bundler-plugins/per-locale-build/types.d.ts +4 -0
- package/dist/bundler-plugins/per-locale-build/types.d.ts.map +1 -0
- package/dist/bundler-plugins/per-locale-build/types.js +2 -0
- package/dist/bundler-plugins/per-locale-build/types.js.map +1 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.d.ts +51 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.d.ts.map +1 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.js +250 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.js.map +1 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.test.d.ts +1 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.test.d.ts.map +1 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.test.js +250 -0
- package/dist/bundler-plugins/per-locale-build/vite-environments.test.js.map +1 -0
- package/dist/bundler-plugins/plugin-core.d.ts +74 -0
- package/dist/bundler-plugins/plugin-core.d.ts.map +1 -0
- package/dist/bundler-plugins/plugin-core.js +292 -0
- package/dist/bundler-plugins/plugin-core.js.map +1 -0
- package/dist/bundler-plugins/rolldown.d.ts +10 -0
- package/dist/bundler-plugins/rolldown.d.ts.map +1 -0
- package/dist/bundler-plugins/rolldown.js +36 -0
- package/dist/bundler-plugins/rolldown.js.map +1 -0
- package/dist/bundler-plugins/rolldown.test.d.ts +1 -0
- package/dist/bundler-plugins/rolldown.test.d.ts.map +1 -0
- package/dist/bundler-plugins/rolldown.test.js +72 -0
- package/dist/bundler-plugins/rolldown.test.js.map +1 -0
- package/dist/bundler-plugins/rollup.d.ts +1 -0
- package/dist/bundler-plugins/rollup.d.ts.map +1 -0
- package/dist/bundler-plugins/rollup.js +4 -0
- package/dist/bundler-plugins/rollup.js.map +1 -0
- package/dist/bundler-plugins/rspack.d.ts +1 -0
- package/dist/bundler-plugins/rspack.d.ts.map +1 -0
- package/dist/bundler-plugins/rspack.js +4 -0
- package/dist/bundler-plugins/rspack.js.map +1 -0
- package/dist/bundler-plugins/unplugin.d.ts +3 -0
- package/dist/bundler-plugins/unplugin.d.ts.map +1 -0
- package/dist/bundler-plugins/unplugin.js +62 -0
- package/dist/bundler-plugins/unplugin.js.map +1 -0
- package/dist/bundler-plugins/unplugin.test.d.ts +1 -0
- package/dist/bundler-plugins/unplugin.test.d.ts.map +1 -0
- package/dist/bundler-plugins/unplugin.test.js +256 -0
- package/dist/bundler-plugins/unplugin.test.js.map +1 -0
- package/dist/bundler-plugins/virtual-modules.test.d.ts +1 -0
- package/dist/bundler-plugins/virtual-modules.test.d.ts.map +1 -0
- package/dist/bundler-plugins/virtual-modules.test.js +77 -0
- package/dist/bundler-plugins/virtual-modules.test.js.map +1 -0
- package/dist/bundler-plugins/vite.d.ts +17 -0
- package/dist/bundler-plugins/vite.d.ts.map +1 -0
- package/dist/bundler-plugins/vite.js +15 -0
- package/dist/bundler-plugins/vite.js.map +1 -0
- package/dist/bundler-plugins/vite.test.d.ts +1 -0
- package/dist/bundler-plugins/vite.test.d.ts.map +1 -0
- package/dist/bundler-plugins/vite.test.js +61 -0
- package/dist/bundler-plugins/vite.test.js.map +1 -0
- package/dist/bundler-plugins/webpack.d.ts +1 -0
- package/dist/bundler-plugins/webpack.d.ts.map +1 -0
- package/dist/bundler-plugins/webpack.js +4 -0
- package/dist/bundler-plugins/webpack.js.map +1 -0
- package/dist/cli/commands/compile/command.d.ts +2 -0
- package/dist/cli/commands/compile/command.d.ts.map +1 -0
- package/dist/cli/commands/compile/command.js +225 -0
- package/dist/cli/commands/compile/command.js.map +1 -0
- package/dist/cli/commands/compile/command.test.d.ts +1 -0
- package/dist/cli/commands/compile/command.test.d.ts.map +1 -0
- package/dist/cli/commands/compile/command.test.js +69 -0
- package/dist/cli/commands/compile/command.test.js.map +1 -0
- package/dist/cli/commands/init/command.d.ts +2 -0
- package/dist/cli/commands/init/command.d.ts.map +1 -0
- package/dist/cli/commands/init/command.js +90 -0
- package/dist/cli/commands/init/command.js.map +1 -0
- package/dist/cli/defaults.d.ts +11 -0
- package/dist/cli/defaults.d.ts.map +1 -0
- package/dist/cli/defaults.js +13 -0
- package/dist/cli/defaults.js.map +1 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +11 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/steps/add-vite-plugin.d.ts +31 -0
- package/dist/cli/steps/add-vite-plugin.d.ts.map +1 -0
- package/dist/cli/steps/add-vite-plugin.js +65 -0
- package/dist/cli/steps/add-vite-plugin.js.map +1 -0
- package/dist/cli/steps/add-vite-plugin.test.d.ts +1 -0
- package/dist/cli/steps/add-vite-plugin.test.d.ts.map +1 -0
- package/dist/cli/steps/add-vite-plugin.test.js +74 -0
- package/dist/cli/steps/add-vite-plugin.test.js.map +1 -0
- package/dist/cli/steps/check-for-uncomitted-changes.d.ts +5 -0
- package/dist/cli/steps/check-for-uncomitted-changes.d.ts.map +1 -0
- package/dist/cli/steps/check-for-uncomitted-changes.js +37 -0
- package/dist/cli/steps/check-for-uncomitted-changes.js.map +1 -0
- package/dist/cli/steps/detect-bundler.d.ts +10 -0
- package/dist/cli/steps/detect-bundler.d.ts.map +1 -0
- package/dist/cli/steps/detect-bundler.js +22 -0
- package/dist/cli/steps/detect-bundler.js.map +1 -0
- package/dist/cli/steps/detect-bundler.test.d.ts +1 -0
- package/dist/cli/steps/detect-bundler.test.d.ts.map +1 -0
- package/dist/cli/steps/detect-bundler.test.js +29 -0
- package/dist/cli/steps/detect-bundler.test.js.map +1 -0
- package/dist/cli/steps/initialize-messages.d.ts +11 -0
- package/dist/cli/steps/initialize-messages.d.ts.map +1 -0
- package/dist/cli/steps/initialize-messages.js +31 -0
- package/dist/cli/steps/initialize-messages.js.map +1 -0
- package/dist/cli/steps/prompt-for-outdir.d.ts +8 -0
- package/dist/cli/steps/prompt-for-outdir.d.ts.map +1 -0
- package/dist/cli/steps/prompt-for-outdir.js +19 -0
- package/dist/cli/steps/prompt-for-outdir.js.map +1 -0
- package/dist/cli/steps/update-package-json.d.ts +11 -0
- package/dist/cli/steps/update-package-json.d.ts.map +1 -0
- package/dist/cli/steps/update-package-json.js +34 -0
- package/dist/cli/steps/update-package-json.js.map +1 -0
- package/dist/cli/steps/update-ts-config.d.ts +26 -0
- package/dist/cli/steps/update-ts-config.d.ts.map +1 -0
- package/dist/cli/steps/update-ts-config.js +270 -0
- package/dist/cli/steps/update-ts-config.js.map +1 -0
- package/dist/cli/steps/update-ts-config.test.d.ts +1 -0
- package/dist/cli/steps/update-ts-config.test.d.ts.map +1 -0
- package/dist/cli/steps/update-ts-config.test.js +60 -0
- package/dist/cli/steps/update-ts-config.test.js.map +1 -0
- package/dist/cli/utils.d.ts +36 -0
- package/dist/cli/utils.d.ts.map +1 -0
- package/dist/cli/utils.js +20 -0
- package/dist/cli/utils.js.map +1 -0
- package/dist/compiler/assert-url-pattern-available.d.ts +7 -0
- package/dist/compiler/assert-url-pattern-available.d.ts.map +1 -0
- package/dist/compiler/assert-url-pattern-available.js +17 -0
- package/dist/compiler/assert-url-pattern-available.js.map +1 -0
- package/dist/compiler/compile-annotation.d.ts +12 -0
- package/dist/compiler/compile-annotation.d.ts.map +1 -0
- package/dist/compiler/compile-annotation.js +136 -0
- package/dist/compiler/compile-annotation.js.map +1 -0
- package/dist/compiler/compile-bundle.d.ts +28 -0
- package/dist/compiler/compile-bundle.d.ts.map +1 -0
- package/dist/compiler/compile-bundle.js +431 -0
- package/dist/compiler/compile-bundle.js.map +1 -0
- package/dist/compiler/compile-bundle.test.d.ts +1 -0
- package/dist/compiler/compile-bundle.test.d.ts.map +1 -0
- package/dist/compiler/compile-bundle.test.js +399 -0
- package/dist/compiler/compile-bundle.test.js.map +1 -0
- package/dist/compiler/compile-local-variable.d.ts +16 -0
- package/dist/compiler/compile-local-variable.d.ts.map +1 -0
- package/dist/compiler/compile-local-variable.js +28 -0
- package/dist/compiler/compile-local-variable.js.map +1 -0
- package/dist/compiler/compile-local-variable.test.d.ts +1 -0
- package/dist/compiler/compile-local-variable.test.d.ts.map +1 -0
- package/dist/compiler/compile-local-variable.test.js +359 -0
- package/dist/compiler/compile-local-variable.test.js.map +1 -0
- package/dist/compiler/compile-message.d.ts +8 -0
- package/dist/compiler/compile-message.d.ts.map +1 -0
- package/dist/compiler/compile-message.js +174 -0
- package/dist/compiler/compile-message.js.map +1 -0
- package/dist/compiler/compile-message.test.d.ts +1 -0
- package/dist/compiler/compile-message.test.d.ts.map +1 -0
- package/dist/compiler/compile-message.test.js +1060 -0
- package/dist/compiler/compile-message.test.js.map +1 -0
- package/dist/compiler/compile-pattern.d.ts +29 -0
- package/dist/compiler/compile-pattern.d.ts.map +1 -0
- package/dist/compiler/compile-pattern.js +143 -0
- package/dist/compiler/compile-pattern.js.map +1 -0
- package/dist/compiler/compile-pattern.test.d.ts +1 -0
- package/dist/compiler/compile-pattern.test.d.ts.map +1 -0
- package/dist/compiler/compile-pattern.test.js +255 -0
- package/dist/compiler/compile-pattern.test.js.map +1 -0
- package/dist/compiler/compile-project.d.ts +21 -0
- package/dist/compiler/compile-project.d.ts.map +1 -0
- package/dist/compiler/compile-project.js +147 -0
- package/dist/compiler/compile-project.js.map +1 -0
- package/dist/compiler/compile-project.test.d.ts +1 -0
- package/dist/compiler/compile-project.test.d.ts.map +1 -0
- package/dist/compiler/compile-project.test.js +1709 -0
- package/dist/compiler/compile-project.test.js.map +1 -0
- package/dist/compiler/compile.bench.d.ts +1 -0
- package/dist/compiler/compile.bench.d.ts.map +1 -0
- package/dist/compiler/compile.bench.js +89 -0
- package/dist/compiler/compile.bench.js.map +1 -0
- package/dist/compiler/compile.d.ts +24 -0
- package/dist/compiler/compile.d.ts.map +1 -0
- package/dist/compiler/compile.js +106 -0
- package/dist/compiler/compile.js.map +1 -0
- package/dist/compiler/compile.test.d.ts +1 -0
- package/dist/compiler/compile.test.d.ts.map +1 -0
- package/dist/compiler/compile.test.js +66 -0
- package/dist/compiler/compile.test.js.map +1 -0
- package/dist/compiler/compiler-options.d.ts +466 -0
- package/dist/compiler/compiler-options.d.ts.map +1 -0
- package/dist/compiler/compiler-options.js +22 -0
- package/dist/compiler/compiler-options.js.map +1 -0
- package/dist/compiler/create-paraglide.d.ts +21 -0
- package/dist/compiler/create-paraglide.d.ts.map +1 -0
- package/dist/compiler/create-paraglide.js +69 -0
- package/dist/compiler/create-paraglide.js.map +1 -0
- package/dist/compiler/create-paraglide.test.d.ts +1 -0
- package/dist/compiler/create-paraglide.test.d.ts.map +1 -0
- package/dist/compiler/create-paraglide.test.js +55 -0
- package/dist/compiler/create-paraglide.test.js.map +1 -0
- package/dist/compiler/create-readme.d.ts +9 -0
- package/dist/compiler/create-readme.d.ts.map +1 -0
- package/dist/compiler/create-readme.js +127 -0
- package/dist/compiler/create-readme.js.map +1 -0
- package/dist/compiler/emit-files.d.ts +15 -0
- package/dist/compiler/emit-files.d.ts.map +1 -0
- package/dist/compiler/emit-files.js +58 -0
- package/dist/compiler/emit-files.js.map +1 -0
- package/dist/compiler/emit-files.test.d.ts +1 -0
- package/dist/compiler/emit-files.test.d.ts.map +1 -0
- package/dist/compiler/emit-files.test.js +43 -0
- package/dist/compiler/emit-files.test.js.map +1 -0
- package/dist/compiler/emit-ts-declarations.d.ts +11 -0
- package/dist/compiler/emit-ts-declarations.d.ts.map +1 -0
- package/dist/compiler/emit-ts-declarations.interop.test.d.ts +1 -0
- package/dist/compiler/emit-ts-declarations.interop.test.d.ts.map +1 -0
- package/dist/compiler/emit-ts-declarations.interop.test.js +33 -0
- package/dist/compiler/emit-ts-declarations.interop.test.js.map +1 -0
- package/dist/compiler/emit-ts-declarations.js +353 -0
- package/dist/compiler/emit-ts-declarations.js.map +1 -0
- package/dist/compiler/emit-ts-declarations.test.d.ts +1 -0
- package/dist/compiler/emit-ts-declarations.test.d.ts.map +1 -0
- package/dist/compiler/emit-ts-declarations.test.js +161 -0
- package/dist/compiler/emit-ts-declarations.test.js.map +1 -0
- package/dist/compiler/index.d.ts +13 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +11 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/jsdoc-types.d.ts +21 -0
- package/dist/compiler/jsdoc-types.d.ts.map +1 -0
- package/dist/compiler/jsdoc-types.js +59 -0
- package/dist/compiler/jsdoc-types.js.map +1 -0
- package/dist/compiler/jsdoc-types.test.d.ts +1 -0
- package/dist/compiler/jsdoc-types.test.d.ts.map +1 -0
- package/dist/compiler/jsdoc-types.test.js +100 -0
- package/dist/compiler/jsdoc-types.test.js.map +1 -0
- package/dist/compiler/lazy-modules/compile-cache.d.ts +37 -0
- package/dist/compiler/lazy-modules/compile-cache.d.ts.map +1 -0
- package/dist/compiler/lazy-modules/compile-cache.js +34 -0
- package/dist/compiler/lazy-modules/compile-cache.js.map +1 -0
- package/dist/compiler/lazy-modules/compile-project.lazy.test.d.ts +2 -0
- package/dist/compiler/lazy-modules/compile-project.lazy.test.d.ts.map +1 -0
- package/dist/compiler/lazy-modules/compile-project.lazy.test.js +65 -0
- package/dist/compiler/lazy-modules/compile-project.lazy.test.js.map +1 -0
- package/dist/compiler/lazy-modules/create-loader.d.ts +18 -0
- package/dist/compiler/lazy-modules/create-loader.d.ts.map +1 -0
- package/dist/compiler/lazy-modules/create-loader.js +182 -0
- package/dist/compiler/lazy-modules/create-loader.js.map +1 -0
- package/dist/compiler/lazy-modules/create-loader.test.d.ts +2 -0
- package/dist/compiler/lazy-modules/create-loader.test.d.ts.map +1 -0
- package/dist/compiler/lazy-modules/create-loader.test.js +82 -0
- package/dist/compiler/lazy-modules/create-loader.test.js.map +1 -0
- package/dist/compiler/lazy-modules/manifest.d.ts +32 -0
- package/dist/compiler/lazy-modules/manifest.d.ts.map +1 -0
- package/dist/compiler/lazy-modules/manifest.js +11 -0
- package/dist/compiler/lazy-modules/manifest.js.map +1 -0
- package/dist/compiler/match-literals.d.ts +2 -0
- package/dist/compiler/match-literals.d.ts.map +1 -0
- package/dist/compiler/match-literals.js +42 -0
- package/dist/compiler/match-literals.js.map +1 -0
- package/dist/compiler/output-structure/lazy-modules.d.ts +27 -0
- package/dist/compiler/output-structure/lazy-modules.d.ts.map +1 -0
- package/dist/compiler/output-structure/lazy-modules.js +157 -0
- package/dist/compiler/output-structure/lazy-modules.js.map +1 -0
- package/dist/compiler/output-structure/lazy-modules.test.d.ts +2 -0
- package/dist/compiler/output-structure/lazy-modules.test.d.ts.map +1 -0
- package/dist/compiler/output-structure/lazy-modules.test.js +128 -0
- package/dist/compiler/output-structure/lazy-modules.test.js.map +1 -0
- package/dist/compiler/output-structure/locale-modules.d.ts +4 -0
- package/dist/compiler/output-structure/locale-modules.d.ts.map +1 -0
- package/dist/compiler/output-structure/locale-modules.js +81 -0
- package/dist/compiler/output-structure/locale-modules.js.map +1 -0
- package/dist/compiler/output-structure/locale-modules.test.d.ts +1 -0
- package/dist/compiler/output-structure/locale-modules.test.d.ts.map +1 -0
- package/dist/compiler/output-structure/locale-modules.test.js +163 -0
- package/dist/compiler/output-structure/locale-modules.test.js.map +1 -0
- package/dist/compiler/output-structure/message-modules.d.ts +4 -0
- package/dist/compiler/output-structure/message-modules.d.ts.map +1 -0
- package/dist/compiler/output-structure/message-modules.js +100 -0
- package/dist/compiler/output-structure/message-modules.js.map +1 -0
- package/dist/compiler/output-structure/message-modules.test.d.ts +1 -0
- package/dist/compiler/output-structure/message-modules.test.d.ts.map +1 -0
- package/dist/compiler/output-structure/message-modules.test.js +148 -0
- package/dist/compiler/output-structure/message-modules.test.js.map +1 -0
- package/dist/compiler/per-locale-build.d.ts +2 -0
- package/dist/compiler/per-locale-build.d.ts.map +1 -0
- package/dist/compiler/per-locale-build.js +3 -0
- package/dist/compiler/per-locale-build.js.map +1 -0
- package/dist/compiler/registry.d.ts +13 -0
- package/dist/compiler/registry.d.ts.map +1 -0
- package/dist/compiler/registry.js +60 -0
- package/dist/compiler/registry.js.map +1 -0
- package/dist/compiler/resolve-tsc-js-path.d.ts +9 -0
- package/dist/compiler/resolve-tsc-js-path.d.ts.map +1 -0
- package/dist/compiler/resolve-tsc-js-path.js +23 -0
- package/dist/compiler/resolve-tsc-js-path.js.map +1 -0
- package/dist/compiler/runtime/check-locale.d.ts +31 -0
- package/dist/compiler/runtime/check-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/check-locale.js +51 -0
- package/dist/compiler/runtime/check-locale.js.map +1 -0
- package/dist/compiler/runtime/check-locale.test.d.ts +1 -0
- package/dist/compiler/runtime/check-locale.test.d.ts.map +1 -0
- package/dist/compiler/runtime/check-locale.test.js +84 -0
- package/dist/compiler/runtime/check-locale.test.js.map +1 -0
- package/dist/compiler/runtime/create-runtime.d.ts +35 -0
- package/dist/compiler/runtime/create-runtime.d.ts.map +1 -0
- package/dist/compiler/runtime/create-runtime.js +196 -0
- package/dist/compiler/runtime/create-runtime.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.d.ts +13 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.js +43 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.js +149 -0
- package/dist/compiler/runtime/extract-locale-from-cookie.test.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.d.ts +13 -0
- package/dist/compiler/runtime/extract-locale-from-header.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.js +45 -0
- package/dist/compiler/runtime/extract-locale-from-header.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.d.ts +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.js +55 -0
- package/dist/compiler/runtime/extract-locale-from-header.test.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.d.ts +12 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.js +33 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.d.ts +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.js +45 -0
- package/dist/compiler/runtime/extract-locale-from-navigator.test.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.d.ts +34 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.js +70 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.test.d.ts +1 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.test.js +119 -0
- package/dist/compiler/runtime/extract-locale-from-request-async.test.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.d.ts +41 -0
- package/dist/compiler/runtime/extract-locale-from-request.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.js +96 -0
- package/dist/compiler/runtime/extract-locale-from-request.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.d.ts +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.js +351 -0
- package/dist/compiler/runtime/extract-locale-from-request.test.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.d.ts +11 -0
- package/dist/compiler/runtime/extract-locale-from-url.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.js +68 -0
- package/dist/compiler/runtime/extract-locale-from-url.js.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.d.ts +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.d.ts.map +1 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.js +127 -0
- package/dist/compiler/runtime/extract-locale-from-url.test.js.map +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.d.ts +44 -0
- package/dist/compiler/runtime/generate-static-localized-urls.d.ts.map +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.js +133 -0
- package/dist/compiler/runtime/generate-static-localized-urls.js.map +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.d.ts.map +1 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.js +159 -0
- package/dist/compiler/runtime/generate-static-localized-urls.test.js.map +1 -0
- package/dist/compiler/runtime/get-locale.d.ts +42 -0
- package/dist/compiler/runtime/get-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/get-locale.js +158 -0
- package/dist/compiler/runtime/get-locale.js.map +1 -0
- package/dist/compiler/runtime/get-locale.test.d.ts +1 -0
- package/dist/compiler/runtime/get-locale.test.d.ts.map +1 -0
- package/dist/compiler/runtime/get-locale.test.js +295 -0
- package/dist/compiler/runtime/get-locale.test.js.map +1 -0
- package/dist/compiler/runtime/get-text-direction.d.ts +15 -0
- package/dist/compiler/runtime/get-text-direction.d.ts.map +1 -0
- package/dist/compiler/runtime/get-text-direction.js +46 -0
- package/dist/compiler/runtime/get-text-direction.js.map +1 -0
- package/dist/compiler/runtime/get-text-direction.test.d.ts +1 -0
- package/dist/compiler/runtime/get-text-direction.test.d.ts.map +1 -0
- package/dist/compiler/runtime/get-text-direction.test.js +40 -0
- package/dist/compiler/runtime/get-text-direction.test.js.map +1 -0
- package/dist/compiler/runtime/get-url-origin.d.ts +19 -0
- package/dist/compiler/runtime/get-url-origin.d.ts.map +1 -0
- package/dist/compiler/runtime/get-url-origin.js +31 -0
- package/dist/compiler/runtime/get-url-origin.js.map +1 -0
- package/dist/compiler/runtime/get-url-origin.test.d.ts +1 -0
- package/dist/compiler/runtime/get-url-origin.test.d.ts.map +1 -0
- package/dist/compiler/runtime/get-url-origin.test.js +18 -0
- package/dist/compiler/runtime/get-url-origin.test.js.map +1 -0
- package/dist/compiler/runtime/host-routing.d.ts +28 -0
- package/dist/compiler/runtime/host-routing.d.ts.map +1 -0
- package/dist/compiler/runtime/host-routing.js +79 -0
- package/dist/compiler/runtime/host-routing.js.map +1 -0
- package/dist/compiler/runtime/host-routing.test.d.ts +1 -0
- package/dist/compiler/runtime/host-routing.test.d.ts.map +1 -0
- package/dist/compiler/runtime/host-routing.test.js +128 -0
- package/dist/compiler/runtime/host-routing.test.js.map +1 -0
- package/dist/compiler/runtime/localize-href.d.ts +84 -0
- package/dist/compiler/runtime/localize-href.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-href.js +115 -0
- package/dist/compiler/runtime/localize-href.js.map +1 -0
- package/dist/compiler/runtime/localize-href.test.d.ts +1 -0
- package/dist/compiler/runtime/localize-href.test.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-href.test.js +139 -0
- package/dist/compiler/runtime/localize-href.test.js.map +1 -0
- package/dist/compiler/runtime/localize-url.d.ts +95 -0
- package/dist/compiler/runtime/localize-url.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-url.js +327 -0
- package/dist/compiler/runtime/localize-url.js.map +1 -0
- package/dist/compiler/runtime/localize-url.test.d.ts +1 -0
- package/dist/compiler/runtime/localize-url.test.d.ts.map +1 -0
- package/dist/compiler/runtime/localize-url.test.js +533 -0
- package/dist/compiler/runtime/localize-url.test.js.map +1 -0
- package/dist/compiler/runtime/route-strategy.d.ts +32 -0
- package/dist/compiler/runtime/route-strategy.d.ts.map +1 -0
- package/dist/compiler/runtime/route-strategy.js +72 -0
- package/dist/compiler/runtime/route-strategy.js.map +1 -0
- package/dist/compiler/runtime/set-locale.d.ts +46 -0
- package/dist/compiler/runtime/set-locale.d.ts.map +1 -0
- package/dist/compiler/runtime/set-locale.js +172 -0
- package/dist/compiler/runtime/set-locale.js.map +1 -0
- package/dist/compiler/runtime/set-locale.test.d.ts +1 -0
- package/dist/compiler/runtime/set-locale.test.d.ts.map +1 -0
- package/dist/compiler/runtime/set-locale.test.js +555 -0
- package/dist/compiler/runtime/set-locale.test.js.map +1 -0
- package/dist/compiler/runtime/should-redirect.d.ts +100 -0
- package/dist/compiler/runtime/should-redirect.d.ts.map +1 -0
- package/dist/compiler/runtime/should-redirect.js +155 -0
- package/dist/compiler/runtime/should-redirect.js.map +1 -0
- package/dist/compiler/runtime/should-redirect.test.d.ts +1 -0
- package/dist/compiler/runtime/should-redirect.test.d.ts.map +1 -0
- package/dist/compiler/runtime/should-redirect.test.js +270 -0
- package/dist/compiler/runtime/should-redirect.test.js.map +1 -0
- package/dist/compiler/runtime/strategy.d.ts +63 -0
- package/dist/compiler/runtime/strategy.d.ts.map +1 -0
- package/dist/compiler/runtime/strategy.js +65 -0
- package/dist/compiler/runtime/strategy.js.map +1 -0
- package/dist/compiler/runtime/strategy.test.d.ts +1 -0
- package/dist/compiler/runtime/strategy.test.d.ts.map +1 -0
- package/dist/compiler/runtime/strategy.test.js +90 -0
- package/dist/compiler/runtime/strategy.test.js.map +1 -0
- package/dist/compiler/runtime/track-message-call.d.ts +5 -0
- package/dist/compiler/runtime/track-message-call.d.ts.map +1 -0
- package/dist/compiler/runtime/track-message-call.js +14 -0
- package/dist/compiler/runtime/track-message-call.js.map +1 -0
- package/dist/compiler/runtime/track-message-call.test.d.ts +1 -0
- package/dist/compiler/runtime/track-message-call.test.d.ts.map +1 -0
- package/dist/compiler/runtime/track-message-call.test.js +22 -0
- package/dist/compiler/runtime/track-message-call.test.js.map +1 -0
- package/dist/compiler/runtime/type-definitions.d.ts +197 -0
- package/dist/compiler/runtime/type-definitions.d.ts.map +1 -0
- package/dist/compiler/runtime/type-definitions.js +150 -0
- package/dist/compiler/runtime/type-definitions.js.map +1 -0
- package/dist/compiler/runtime/type.d.ts +47 -0
- package/dist/compiler/runtime/type.d.ts.map +1 -0
- package/dist/compiler/runtime/type.js +2 -0
- package/dist/compiler/runtime/type.js.map +1 -0
- package/dist/compiler/runtime/type.test.d.ts +1 -0
- package/dist/compiler/runtime/type.test.d.ts.map +1 -0
- package/dist/compiler/runtime/type.test.js +153 -0
- package/dist/compiler/runtime/type.test.js.map +1 -0
- package/dist/compiler/runtime/url-pattern.d.ts +12 -0
- package/dist/compiler/runtime/url-pattern.d.ts.map +1 -0
- package/dist/compiler/runtime/url-pattern.js +35 -0
- package/dist/compiler/runtime/url-pattern.js.map +1 -0
- package/dist/compiler/runtime/variables.d.ts +128 -0
- package/dist/compiler/runtime/variables.d.ts.map +1 -0
- package/dist/compiler/runtime/variables.js +111 -0
- package/dist/compiler/runtime/variables.js.map +1 -0
- package/dist/compiler/safe-module-id.d.ts +7 -0
- package/dist/compiler/safe-module-id.d.ts.map +1 -0
- package/dist/compiler/safe-module-id.js +78 -0
- package/dist/compiler/safe-module-id.js.map +1 -0
- package/dist/compiler/safe-module-id.test.d.ts +1 -0
- package/dist/compiler/safe-module-id.test.d.ts.map +1 -0
- package/dist/compiler/safe-module-id.test.js +36 -0
- package/dist/compiler/safe-module-id.test.js.map +1 -0
- package/dist/compiler/seed-previous-compilation.d.ts +7 -0
- package/dist/compiler/seed-previous-compilation.d.ts.map +1 -0
- package/dist/compiler/seed-previous-compilation.js +9 -0
- package/dist/compiler/seed-previous-compilation.js.map +1 -0
- package/dist/compiler/server/create-server-file.d.ts +12 -0
- package/dist/compiler/server/create-server-file.d.ts.map +1 -0
- package/dist/compiler/server/create-server-file.js +91 -0
- package/dist/compiler/server/create-server-file.js.map +1 -0
- package/dist/compiler/server/create-server-file.test.d.ts +1 -0
- package/dist/compiler/server/create-server-file.test.d.ts.map +1 -0
- package/dist/compiler/server/create-server-file.test.js +48 -0
- package/dist/compiler/server/create-server-file.test.js.map +1 -0
- package/dist/compiler/server/middleware.d.ts +98 -0
- package/dist/compiler/server/middleware.d.ts.map +1 -0
- package/dist/compiler/server/middleware.js +278 -0
- package/dist/compiler/server/middleware.js.map +1 -0
- package/dist/compiler/server/middleware.test.d.ts +1 -0
- package/dist/compiler/server/middleware.test.d.ts.map +1 -0
- package/dist/compiler/server/middleware.test.js +1001 -0
- package/dist/compiler/server/middleware.test.js.map +1 -0
- package/dist/compiler/server/type.d.ts +6 -0
- package/dist/compiler/server/type.d.ts.map +1 -0
- package/dist/compiler/server/type.js +2 -0
- package/dist/compiler/server/type.js.map +1 -0
- package/dist/compiler/test-helpers.d.ts +30 -0
- package/dist/compiler/test-helpers.d.ts.map +1 -0
- package/dist/compiler/test-helpers.js +50 -0
- package/dist/compiler/test-helpers.js.map +1 -0
- package/dist/compiler/types.d.ts +7 -0
- package/dist/compiler/types.d.ts.map +1 -0
- package/dist/compiler/types.js +2 -0
- package/dist/compiler/types.js.map +1 -0
- package/dist/compiler/variable-access.d.ts +3 -0
- package/dist/compiler/variable-access.d.ts.map +1 -0
- package/dist/compiler/variable-access.js +15 -0
- package/dist/compiler/variable-access.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/messages/ast.d.ts +102 -0
- package/dist/messages/ast.d.ts.map +1 -0
- package/dist/messages/ast.js +8 -0
- package/dist/messages/ast.js.map +1 -0
- package/dist/messages/create-bundle-nested.d.ts +16 -0
- package/dist/messages/create-bundle-nested.d.ts.map +1 -0
- package/dist/messages/create-bundle-nested.js +22 -0
- package/dist/messages/create-bundle-nested.js.map +1 -0
- package/dist/messages/index.d.ts +5 -0
- package/dist/messages/index.d.ts.map +1 -0
- package/dist/messages/index.js +5 -0
- package/dist/messages/index.js.map +1 -0
- package/dist/messages/load-messages.d.ts +19 -0
- package/dist/messages/load-messages.d.ts.map +1 -0
- package/dist/messages/load-messages.js +49 -0
- package/dist/messages/load-messages.js.map +1 -0
- package/dist/messages/message-format/flatten.d.ts +9 -0
- package/dist/messages/message-format/flatten.d.ts.map +1 -0
- package/dist/messages/message-format/flatten.js +32 -0
- package/dist/messages/message-format/flatten.js.map +1 -0
- package/dist/messages/message-format/import-files.d.ts +32 -0
- package/dist/messages/message-format/import-files.d.ts.map +1 -0
- package/dist/messages/message-format/import-files.js +53 -0
- package/dist/messages/message-format/import-files.js.map +1 -0
- package/dist/messages/message-format/import-files.test.d.ts +1 -0
- package/dist/messages/message-format/import-files.test.d.ts.map +1 -0
- package/dist/messages/message-format/import-files.test.js +145 -0
- package/dist/messages/message-format/import-files.test.js.map +1 -0
- package/dist/messages/message-format/index.d.ts +6 -0
- package/dist/messages/message-format/index.d.ts.map +1 -0
- package/dist/messages/message-format/index.js +7 -0
- package/dist/messages/message-format/index.js.map +1 -0
- package/dist/messages/message-format/parse-bundle.d.ts +31 -0
- package/dist/messages/message-format/parse-bundle.d.ts.map +1 -0
- package/dist/messages/message-format/parse-bundle.js +169 -0
- package/dist/messages/message-format/parse-bundle.js.map +1 -0
- package/dist/messages/message-format/parse-declaration.d.ts +2 -0
- package/dist/messages/message-format/parse-declaration.d.ts.map +1 -0
- package/dist/messages/message-format/parse-declaration.js +56 -0
- package/dist/messages/message-format/parse-declaration.js.map +1 -0
- package/dist/messages/message-format/parse-markup.d.ts +4 -0
- package/dist/messages/message-format/parse-markup.d.ts.map +1 -0
- package/dist/messages/message-format/parse-markup.js +167 -0
- package/dist/messages/message-format/parse-markup.js.map +1 -0
- package/dist/messages/message-format/parse-matches.d.ts +5 -0
- package/dist/messages/message-format/parse-matches.d.ts.map +1 -0
- package/dist/messages/message-format/parse-matches.js +31 -0
- package/dist/messages/message-format/parse-matches.js.map +1 -0
- package/dist/messages/message-format/parse-pattern.d.ts +5 -0
- package/dist/messages/message-format/parse-pattern.d.ts.map +1 -0
- package/dist/messages/message-format/parse-pattern.js +120 -0
- package/dist/messages/message-format/parse-pattern.js.map +1 -0
- package/dist/messages/message-format/unique.d.ts +2 -0
- package/dist/messages/message-format/unique.d.ts.map +1 -0
- package/dist/messages/message-format/unique.js +5 -0
- package/dist/messages/message-format/unique.js.map +1 -0
- package/dist/messages/nest-bundles.d.ts +19 -0
- package/dist/messages/nest-bundles.d.ts.map +1 -0
- package/dist/messages/nest-bundles.js +49 -0
- package/dist/messages/nest-bundles.js.map +1 -0
- package/dist/services/account/index.d.ts +14 -0
- package/dist/services/account/index.d.ts.map +1 -0
- package/dist/services/account/index.js +43 -0
- package/dist/services/account/index.js.map +1 -0
- package/dist/services/account/types.d.ts +4 -0
- package/dist/services/account/types.d.ts.map +1 -0
- package/dist/services/account/types.js +2 -0
- package/dist/services/account/types.js.map +1 -0
- package/dist/services/codegen/escape.d.ts +9 -0
- package/dist/services/codegen/escape.d.ts.map +1 -0
- package/dist/services/codegen/escape.js +19 -0
- package/dist/services/codegen/escape.js.map +1 -0
- package/dist/services/codegen/quotes.d.ts +4 -0
- package/dist/services/codegen/quotes.d.ts.map +1 -0
- package/dist/services/codegen/quotes.js +5 -0
- package/dist/services/codegen/quotes.js.map +1 -0
- package/dist/services/env-variables/create-index-file.d.ts +9 -0
- package/dist/services/env-variables/create-index-file.d.ts.map +1 -0
- package/dist/services/env-variables/create-index-file.js +28 -0
- package/dist/services/env-variables/create-index-file.js.map +1 -0
- package/dist/services/env-variables/index.d.ts +3 -0
- package/dist/services/env-variables/index.d.ts.map +1 -0
- package/dist/services/env-variables/index.js +4 -0
- package/dist/services/env-variables/index.js.map +1 -0
- package/dist/services/environment/package.d.ts +9 -0
- package/dist/services/environment/package.d.ts.map +1 -0
- package/dist/services/environment/package.js +31 -0
- package/dist/services/environment/package.js.map +1 -0
- package/dist/services/environment/package.test.d.ts +1 -0
- package/dist/services/environment/package.test.d.ts.map +1 -0
- package/dist/services/environment/package.test.js +21 -0
- package/dist/services/environment/package.test.js.map +1 -0
- package/dist/services/error-handling.d.ts +12 -0
- package/dist/services/error-handling.d.ts.map +1 -0
- package/dist/services/error-handling.js +27 -0
- package/dist/services/error-handling.js.map +1 -0
- package/dist/services/error-handling.test.d.ts +1 -0
- package/dist/services/error-handling.test.d.ts.map +1 -0
- package/dist/services/error-handling.test.js +10 -0
- package/dist/services/error-handling.test.js.map +1 -0
- package/dist/services/file-handling/content-hash.d.ts +9 -0
- package/dist/services/file-handling/content-hash.js +19 -0
- package/dist/services/file-handling/content-hash.js.map +1 -0
- package/dist/services/file-handling/exists.d.ts +7 -0
- package/dist/services/file-handling/exists.d.ts.map +1 -0
- package/dist/services/file-handling/exists.js +24 -0
- package/dist/services/file-handling/exists.js.map +1 -0
- package/dist/services/file-handling/exists.test.d.ts +1 -0
- package/dist/services/file-handling/exists.test.d.ts.map +1 -0
- package/dist/services/file-handling/exists.test.js +27 -0
- package/dist/services/file-handling/exists.test.js.map +1 -0
- package/dist/services/file-handling/types.d.ts +4 -0
- package/dist/services/file-handling/types.d.ts.map +1 -0
- package/dist/services/file-handling/types.js +2 -0
- package/dist/services/file-handling/types.js.map +1 -0
- package/dist/services/file-handling/write-output.d.ts +21 -0
- package/dist/services/file-handling/write-output.d.ts.map +1 -0
- package/dist/services/file-handling/write-output.js +157 -0
- package/dist/services/file-handling/write-output.js.map +1 -0
- package/dist/services/file-handling/write-output.test.d.ts +1 -0
- package/dist/services/file-handling/write-output.test.d.ts.map +1 -0
- package/dist/services/file-handling/write-output.test.js +217 -0
- package/dist/services/file-handling/write-output.test.js.map +1 -0
- package/dist/services/file-watching/tracked-fs.d.ts +25 -0
- package/dist/services/file-watching/tracked-fs.d.ts.map +1 -0
- package/dist/services/file-watching/tracked-fs.js +94 -0
- package/dist/services/file-watching/tracked-fs.js.map +1 -0
- package/dist/services/file-watching/tracked-fs.test.d.ts +1 -0
- package/dist/services/file-watching/tracked-fs.test.d.ts.map +1 -0
- package/dist/services/file-watching/tracked-fs.test.js +87 -0
- package/dist/services/file-watching/tracked-fs.test.js.map +1 -0
- package/dist/services/logger/index.d.ts +17 -0
- package/dist/services/logger/index.d.ts.map +1 -0
- package/dist/services/logger/index.js +58 -0
- package/dist/services/logger/index.js.map +1 -0
- package/dist/services/lookup.d.ts +14 -0
- package/dist/services/lookup.d.ts.map +1 -0
- package/dist/services/lookup.js +24 -0
- package/dist/services/lookup.js.map +1 -0
- package/dist/urlpattern-polyfill/index.d.ts +2 -0
- package/dist/urlpattern-polyfill/index.d.ts.map +1 -0
- package/dist/urlpattern-polyfill/index.js +2 -0
- package/dist/urlpattern-polyfill/index.js.map +1 -0
- package/dist/utilities/detect-json-formatting.d.ts +10 -0
- package/dist/utilities/detect-json-formatting.d.ts.map +1 -0
- package/dist/utilities/detect-json-formatting.js +80 -0
- package/dist/utilities/detect-json-formatting.js.map +1 -0
- package/dist/utilities/node-normalize-path.d.ts +1 -0
- package/dist/utilities/node-normalize-path.d.ts.map +1 -0
- package/dist/utilities/node-normalize-path.js +10 -0
- package/dist/utilities/node-normalize-path.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { toLocale } from "./check-locale.js";
|
|
2
|
+
import { cookieName } from "./variables.js";
|
|
3
|
+
const cookieNamePattern = cookieName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
4
|
+
const localeCookiePattern = new RegExp(`(?:^|;\\s*)${cookieNamePattern}=([^;]*)`);
|
|
5
|
+
const noCachedLocale = Symbol();
|
|
6
|
+
/** @type {Locale | undefined | typeof noCachedLocale} */
|
|
7
|
+
let cachedLocaleFromCookie = noCachedLocale;
|
|
8
|
+
/**
|
|
9
|
+
* Clears the cached locale from `document.cookie`.
|
|
10
|
+
*/
|
|
11
|
+
export function clearLocaleCookieCache() {
|
|
12
|
+
cachedLocaleFromCookie = noCachedLocale;
|
|
13
|
+
}
|
|
14
|
+
function scheduleLocaleCookieCacheClear() {
|
|
15
|
+
if (typeof queueMicrotask === "function") {
|
|
16
|
+
queueMicrotask(clearLocaleCookieCache);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
Promise.resolve().then(clearLocaleCookieCache);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Extracts a cookie from the document.
|
|
24
|
+
*
|
|
25
|
+
* Will return undefined if the document is not available or if the cookie is not set.
|
|
26
|
+
* The `document` object is not available in server-side rendering, so this function should not be called in that context.
|
|
27
|
+
*
|
|
28
|
+
* @returns {Locale | undefined}
|
|
29
|
+
*/
|
|
30
|
+
export function extractLocaleFromCookie() {
|
|
31
|
+
if (typeof document === "undefined") {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
if (cachedLocaleFromCookie !== noCachedLocale) {
|
|
35
|
+
return cachedLocaleFromCookie;
|
|
36
|
+
}
|
|
37
|
+
const match = document.cookie.match(localeCookiePattern);
|
|
38
|
+
const locale = match?.[1];
|
|
39
|
+
cachedLocaleFromCookie = toLocale(locale);
|
|
40
|
+
scheduleLocaleCookieCacheClear();
|
|
41
|
+
return cachedLocaleFromCookie;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=extract-locale-from-cookie.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-cookie.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,iBAAiB,GAAG,UAAU,CAAC,OAAO,CAAC,qBAAqB,EAAE,MAAM,CAAC,CAAC;AAC5E,MAAM,mBAAmB,GAAG,IAAI,MAAM,CACrC,cAAc,iBAAiB,UAAU,CACzC,CAAC;AAEF,MAAM,cAAc,GAAG,MAAM,EAAE,CAAC;AAChC,yDAAyD;AACzD,IAAI,sBAAsB,GAAG,cAAc,CAAC;AAE5C;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACrC,sBAAsB,GAAG,cAAc,CAAC;AACzC,CAAC;AAED,SAAS,8BAA8B;IACtC,IAAI,OAAO,cAAc,KAAK,UAAU,EAAE,CAAC;QAC1C,cAAc,CAAC,sBAAsB,CAAC,CAAC;IACxC,CAAC;SAAM,CAAC;QACP,OAAO,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;IAChD,CAAC;AACF,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,uBAAuB;IACtC,IAAI,OAAO,QAAQ,KAAK,WAAW,EAAE,CAAC;QACrC,OAAO;IACR,CAAC;IACD,IAAI,sBAAsB,KAAK,cAAc,EAAE,CAAC;QAC/C,OAAO,sBAAsB,CAAC;IAC/B,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACzD,MAAM,MAAM,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1B,sBAAsB,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;IAC1C,8BAA8B,EAAE,CAAC;IACjC,OAAO,sBAAsB,CAAC;AAC/B,CAAC","sourcesContent":["import { toLocale } from \"./check-locale.js\";\nimport { cookieName } from \"./variables.js\";\n\nconst cookieNamePattern = cookieName.replace(/[.*+?^${}()|[\\]\\\\]/g, \"\\\\$&\");\nconst localeCookiePattern = new RegExp(\n\t`(?:^|;\\\\s*)${cookieNamePattern}=([^;]*)`\n);\n\nconst noCachedLocale = Symbol();\n/** @type {Locale | undefined | typeof noCachedLocale} */\nlet cachedLocaleFromCookie = noCachedLocale;\n\n/**\n * Clears the cached locale from `document.cookie`.\n */\nexport function clearLocaleCookieCache() {\n\tcachedLocaleFromCookie = noCachedLocale;\n}\n\nfunction scheduleLocaleCookieCacheClear() {\n\tif (typeof queueMicrotask === \"function\") {\n\t\tqueueMicrotask(clearLocaleCookieCache);\n\t} else {\n\t\tPromise.resolve().then(clearLocaleCookieCache);\n\t}\n}\n\n/**\n * Extracts a cookie from the document.\n *\n * Will return undefined if the document is not available or if the cookie is not set.\n * The `document` object is not available in server-side rendering, so this function should not be called in that context.\n *\n * @returns {Locale | undefined}\n */\nexport function extractLocaleFromCookie() {\n\tif (typeof document === \"undefined\") {\n\t\treturn;\n\t}\n\tif (cachedLocaleFromCookie !== noCachedLocale) {\n\t\treturn cachedLocaleFromCookie;\n\t}\n\tconst match = document.cookie.match(localeCookiePattern);\n\tconst locale = match?.[1];\n\tcachedLocaleFromCookie = toLocale(locale);\n\tscheduleLocaleCookieCacheClear();\n\treturn cachedLocaleFromCookie;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-cookie.test.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import { createParaglide } from "../create-paraglide.js";
|
|
3
|
+
test("returns undefined if document is not available", async () => {
|
|
4
|
+
// @ts-expect-error - global variable definition
|
|
5
|
+
globalThis.document = undefined;
|
|
6
|
+
const runtime = await createParaglide({
|
|
7
|
+
baseLocale: "en",
|
|
8
|
+
locales: ["en", "de"],
|
|
9
|
+
});
|
|
10
|
+
expect(runtime.extractLocaleFromCookie()).toBeUndefined();
|
|
11
|
+
});
|
|
12
|
+
test("matches the locale of a cookie", async () => {
|
|
13
|
+
const runtime = await createParaglide({
|
|
14
|
+
baseLocale: "en",
|
|
15
|
+
locales: ["en", "de"],
|
|
16
|
+
strategy: ["cookie"],
|
|
17
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
18
|
+
});
|
|
19
|
+
// @ts-expect-error - global variable definition
|
|
20
|
+
globalThis.document = {};
|
|
21
|
+
globalThis.document.cookie =
|
|
22
|
+
"OTHER_COOKIE=fr; PARAGLIDE_LOCALE=de; ANOTHER_COOKIE=en; EXPIRES_COOKIE=es; Max-Age=3600";
|
|
23
|
+
const locale = runtime.extractLocaleFromCookie();
|
|
24
|
+
expect(locale).toBe("de");
|
|
25
|
+
});
|
|
26
|
+
test("caches the locale during immediate repeated cookie reads", async () => {
|
|
27
|
+
const runtime = await createParaglide({
|
|
28
|
+
baseLocale: "en",
|
|
29
|
+
locales: ["en", "de"],
|
|
30
|
+
strategy: ["cookie"],
|
|
31
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
32
|
+
});
|
|
33
|
+
let cookieReadCount = 0;
|
|
34
|
+
// @ts-expect-error - global variable definition
|
|
35
|
+
globalThis.document = {
|
|
36
|
+
get cookie() {
|
|
37
|
+
cookieReadCount += 1;
|
|
38
|
+
return "OTHER_COOKIE=fr; PARAGLIDE_LOCALE=de; ANOTHER_COOKIE=en;";
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
expect(runtime.extractLocaleFromCookie()).toBe("de");
|
|
42
|
+
expect(runtime.extractLocaleFromCookie()).toBe("de");
|
|
43
|
+
expect(cookieReadCount).toBe(1);
|
|
44
|
+
});
|
|
45
|
+
test("cache expires after a microtask", async () => {
|
|
46
|
+
const runtime = await createParaglide({
|
|
47
|
+
baseLocale: "en",
|
|
48
|
+
locales: ["en", "de"],
|
|
49
|
+
strategy: ["cookie"],
|
|
50
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
51
|
+
});
|
|
52
|
+
let cookie = "PARAGLIDE_LOCALE=en;";
|
|
53
|
+
let cookieReadCount = 0;
|
|
54
|
+
// @ts-expect-error - global variable definition
|
|
55
|
+
globalThis.document = {
|
|
56
|
+
get cookie() {
|
|
57
|
+
cookieReadCount += 1;
|
|
58
|
+
return cookie;
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
expect(runtime.extractLocaleFromCookie()).toBe("en");
|
|
62
|
+
cookie = "PARAGLIDE_LOCALE=de;";
|
|
63
|
+
expect(runtime.extractLocaleFromCookie()).toBe("en");
|
|
64
|
+
await Promise.resolve();
|
|
65
|
+
expect(runtime.extractLocaleFromCookie()).toBe("de");
|
|
66
|
+
expect(cookieReadCount).toBe(2);
|
|
67
|
+
});
|
|
68
|
+
test("clears the cache after setLocale writes the cookie", async () => {
|
|
69
|
+
const runtime = await createParaglide({
|
|
70
|
+
baseLocale: "en",
|
|
71
|
+
locales: ["en", "de"],
|
|
72
|
+
strategy: ["cookie"],
|
|
73
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
74
|
+
isServer: "false",
|
|
75
|
+
});
|
|
76
|
+
let cookie = "PARAGLIDE_LOCALE=en;";
|
|
77
|
+
let cookieReadCount = 0;
|
|
78
|
+
// @ts-expect-error - global variable definition
|
|
79
|
+
globalThis.document = {
|
|
80
|
+
get cookie() {
|
|
81
|
+
cookieReadCount += 1;
|
|
82
|
+
return cookie;
|
|
83
|
+
},
|
|
84
|
+
set cookie(value) {
|
|
85
|
+
cookie = value;
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
globalThis.window = {
|
|
89
|
+
location: { href: "https://example.com", reload() { } },
|
|
90
|
+
};
|
|
91
|
+
expect(runtime.extractLocaleFromCookie()).toBe("en");
|
|
92
|
+
runtime.setLocale("de", { reload: false });
|
|
93
|
+
expect(runtime.extractLocaleFromCookie()).toBe("de");
|
|
94
|
+
expect(cookieReadCount).toBe(2);
|
|
95
|
+
});
|
|
96
|
+
test("escapes regex characters in cookie names", async () => {
|
|
97
|
+
const runtime = await createParaglide({
|
|
98
|
+
baseLocale: "en",
|
|
99
|
+
locales: ["en", "de"],
|
|
100
|
+
strategy: ["cookie"],
|
|
101
|
+
cookieName: "PARAGLIDE.LOCALE[app]",
|
|
102
|
+
});
|
|
103
|
+
// @ts-expect-error - global variable definition
|
|
104
|
+
globalThis.document = {};
|
|
105
|
+
globalThis.document.cookie =
|
|
106
|
+
"PARAGLIDE_LOCALE_APP_=en;PARAGLIDE.LOCALE[app]=de;";
|
|
107
|
+
expect(runtime.extractLocaleFromCookie()).toBe("de");
|
|
108
|
+
});
|
|
109
|
+
test("returns undefined for an empty cookie locale", async () => {
|
|
110
|
+
const runtime = await createParaglide({
|
|
111
|
+
baseLocale: "en",
|
|
112
|
+
locales: ["en", "de"],
|
|
113
|
+
strategy: ["cookie"],
|
|
114
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
115
|
+
});
|
|
116
|
+
// @ts-expect-error - global variable definition
|
|
117
|
+
globalThis.document = {};
|
|
118
|
+
globalThis.document.cookie = "OTHER_COOKIE=de;PARAGLIDE_LOCALE=;";
|
|
119
|
+
expect(runtime.extractLocaleFromCookie()).toBeUndefined();
|
|
120
|
+
});
|
|
121
|
+
test("canonicalizes cookie locale casing", async () => {
|
|
122
|
+
const runtime = await createParaglide({
|
|
123
|
+
baseLocale: "en",
|
|
124
|
+
locales: ["en", "de-CH"],
|
|
125
|
+
strategy: ["cookie"],
|
|
126
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
127
|
+
});
|
|
128
|
+
// @ts-expect-error - global variable definition
|
|
129
|
+
globalThis.document = {};
|
|
130
|
+
globalThis.document.cookie = "PARAGLIDE_LOCALE=de-ch;";
|
|
131
|
+
expect(runtime.extractLocaleFromCookie()).toBe("de-CH");
|
|
132
|
+
});
|
|
133
|
+
// useful scenario that avoids throws if the cookie uses an old locale that is
|
|
134
|
+
// not supported anymore or development on localhost shares multiple apps with
|
|
135
|
+
// different locales
|
|
136
|
+
test("returns undefined if the locale is not defined in the locales", async () => {
|
|
137
|
+
const runtime = await createParaglide({
|
|
138
|
+
baseLocale: "en",
|
|
139
|
+
locales: ["en", "de"],
|
|
140
|
+
strategy: ["cookie"],
|
|
141
|
+
cookieName: "PARAGLIDE_LOCALE",
|
|
142
|
+
});
|
|
143
|
+
// @ts-expect-error - global variable definition
|
|
144
|
+
globalThis.document = {};
|
|
145
|
+
globalThis.document.cookie = "PARAGLIDE_LOCALE=fr;";
|
|
146
|
+
const locale = runtime.extractLocaleFromCookie();
|
|
147
|
+
expect(locale).toBeUndefined();
|
|
148
|
+
});
|
|
149
|
+
//# sourceMappingURL=extract-locale-from-cookie.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-cookie.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-cookie.test.ts"],"names":[],"mappings":"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","sourcesContent":["import { test, expect } from \"vitest\";\nimport { createParaglide } from \"../create-paraglide.js\";\n\ntest(\"returns undefined if document is not available\", async () => {\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = undefined;\n\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t});\n\n\texpect(runtime.extractLocaleFromCookie()).toBeUndefined();\n});\n\ntest(\"matches the locale of a cookie\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\tglobalThis.document.cookie =\n\t\t\"OTHER_COOKIE=fr; PARAGLIDE_LOCALE=de; ANOTHER_COOKIE=en; EXPIRES_COOKIE=es; Max-Age=3600\";\n\n\tconst locale = runtime.extractLocaleFromCookie();\n\texpect(locale).toBe(\"de\");\n});\n\ntest(\"caches the locale during immediate repeated cookie reads\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\tlet cookieReadCount = 0;\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {\n\t\tget cookie() {\n\t\t\tcookieReadCount += 1;\n\t\t\treturn \"OTHER_COOKIE=fr; PARAGLIDE_LOCALE=de; ANOTHER_COOKIE=en;\";\n\t\t},\n\t};\n\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"de\");\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"de\");\n\texpect(cookieReadCount).toBe(1);\n});\n\ntest(\"cache expires after a microtask\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\tlet cookie = \"PARAGLIDE_LOCALE=en;\";\n\tlet cookieReadCount = 0;\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {\n\t\tget cookie() {\n\t\t\tcookieReadCount += 1;\n\t\t\treturn cookie;\n\t\t},\n\t};\n\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"en\");\n\tcookie = \"PARAGLIDE_LOCALE=de;\";\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"en\");\n\n\tawait Promise.resolve();\n\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"de\");\n\texpect(cookieReadCount).toBe(2);\n});\n\ntest(\"clears the cache after setLocale writes the cookie\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t\tisServer: \"false\",\n\t});\n\n\tlet cookie = \"PARAGLIDE_LOCALE=en;\";\n\tlet cookieReadCount = 0;\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {\n\t\tget cookie() {\n\t\t\tcookieReadCount += 1;\n\t\t\treturn cookie;\n\t\t},\n\t\tset cookie(value) {\n\t\t\tcookie = value;\n\t\t},\n\t};\n\t(globalThis as any).window = {\n\t\tlocation: { href: \"https://example.com\", reload() {} },\n\t};\n\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"en\");\n\truntime.setLocale(\"de\", { reload: false });\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"de\");\n\texpect(cookieReadCount).toBe(2);\n});\n\ntest(\"escapes regex characters in cookie names\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE.LOCALE[app]\",\n\t});\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\tglobalThis.document.cookie =\n\t\t\"PARAGLIDE_LOCALE_APP_=en;PARAGLIDE.LOCALE[app]=de;\";\n\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"de\");\n});\n\ntest(\"returns undefined for an empty cookie locale\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\tglobalThis.document.cookie = \"OTHER_COOKIE=de;PARAGLIDE_LOCALE=;\";\n\n\texpect(runtime.extractLocaleFromCookie()).toBeUndefined();\n});\n\ntest(\"canonicalizes cookie locale casing\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de-CH\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=de-ch;\";\n\n\texpect(runtime.extractLocaleFromCookie()).toBe(\"de-CH\");\n});\n\n// useful scenario that avoids throws if the cookie uses an old locale that is\n// not supported anymore or development on localhost shares multiple apps with\n// different locales\ntest(\"returns undefined if the locale is not defined in the locales\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"de\"],\n\t\tstrategy: [\"cookie\"],\n\t\tcookieName: \"PARAGLIDE_LOCALE\",\n\t});\n\n\t// @ts-expect-error - global variable definition\n\tglobalThis.document = {};\n\tglobalThis.document.cookie = \"PARAGLIDE_LOCALE=fr;\";\n\n\tconst locale = runtime.extractLocaleFromCookie();\n\texpect(locale).toBeUndefined();\n});\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extracts a locale from the accept-language header.
|
|
3
|
+
*
|
|
4
|
+
* Use the function on the server to extract the locale
|
|
5
|
+
* from the accept-language header that is sent by the client.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const locale = extractLocaleFromHeader(request);
|
|
9
|
+
*
|
|
10
|
+
* @param {Request} request - The request object to extract the locale from.
|
|
11
|
+
* @returns {Locale | undefined} The negotiated preferred language.
|
|
12
|
+
*/
|
|
13
|
+
export declare function extractLocaleFromHeader(request: Request): Locale | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-header.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-header.js"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAHpC,OAGoC,GAFlC,MAAM,GAAG,SAAS,CAoC9B"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { toLocale } from "./check-locale.js";
|
|
2
|
+
/**
|
|
3
|
+
* Extracts a locale from the accept-language header.
|
|
4
|
+
*
|
|
5
|
+
* Use the function on the server to extract the locale
|
|
6
|
+
* from the accept-language header that is sent by the client.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const locale = extractLocaleFromHeader(request);
|
|
10
|
+
*
|
|
11
|
+
* @param {Request} request - The request object to extract the locale from.
|
|
12
|
+
* @returns {Locale | undefined} The negotiated preferred language.
|
|
13
|
+
*/
|
|
14
|
+
export function extractLocaleFromHeader(request) {
|
|
15
|
+
const acceptLanguageHeader = request.headers.get("accept-language");
|
|
16
|
+
if (acceptLanguageHeader) {
|
|
17
|
+
// Parse language preferences with their q-values and base language codes
|
|
18
|
+
const languages = acceptLanguageHeader
|
|
19
|
+
.split(",")
|
|
20
|
+
.map((lang) => {
|
|
21
|
+
const [tag, q = "1"] = lang.trim().split(";q=");
|
|
22
|
+
// Get both the full tag and base language code
|
|
23
|
+
const baseTag = tag?.split("-")[0];
|
|
24
|
+
return {
|
|
25
|
+
fullTag: tag,
|
|
26
|
+
baseTag,
|
|
27
|
+
q: Number(q),
|
|
28
|
+
};
|
|
29
|
+
})
|
|
30
|
+
.sort((a, b) => b.q - a.q);
|
|
31
|
+
for (const lang of languages) {
|
|
32
|
+
const fullLocale = toLocale(lang.fullTag);
|
|
33
|
+
if (fullLocale) {
|
|
34
|
+
return fullLocale;
|
|
35
|
+
}
|
|
36
|
+
const baseLocale = toLocale(lang.baseTag);
|
|
37
|
+
if (baseLocale) {
|
|
38
|
+
return baseLocale;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
return undefined;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=extract-locale-from-header.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-header.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-header.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,uBAAuB,CAAC,OAAO;IAC9C,MAAM,oBAAoB,GAAG,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;IACpE,IAAI,oBAAoB,EAAE,CAAC;QAC1B,yEAAyE;QACzE,MAAM,SAAS,GAAG,oBAAoB;aACpC,KAAK,CAAC,GAAG,CAAC;aACV,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACb,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAChD,+CAA+C;YAC/C,MAAM,OAAO,GAAG,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;YACnC,OAAO;gBACN,OAAO,EAAE,GAAG;gBACZ,OAAO;gBACP,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC;aACZ,CAAC;QACH,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAE5B,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YAC9B,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,UAAU,EAAE,CAAC;gBAChB,OAAO,UAAU,CAAC;YACnB,CAAC;YAED,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,UAAU,EAAE,CAAC;gBAChB,OAAO,UAAU,CAAC;YACnB,CAAC;QACF,CAAC;QAED,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { toLocale } from \"./check-locale.js\";\n\n/**\n * Extracts a locale from the accept-language header.\n *\n * Use the function on the server to extract the locale\n * from the accept-language header that is sent by the client.\n *\n * @example\n * const locale = extractLocaleFromHeader(request);\n *\n * @param {Request} request - The request object to extract the locale from.\n * @returns {Locale | undefined} The negotiated preferred language.\n */\nexport function extractLocaleFromHeader(request) {\n\tconst acceptLanguageHeader = request.headers.get(\"accept-language\");\n\tif (acceptLanguageHeader) {\n\t\t// Parse language preferences with their q-values and base language codes\n\t\tconst languages = acceptLanguageHeader\n\t\t\t.split(\",\")\n\t\t\t.map((lang) => {\n\t\t\t\tconst [tag, q = \"1\"] = lang.trim().split(\";q=\");\n\t\t\t\t// Get both the full tag and base language code\n\t\t\t\tconst baseTag = tag?.split(\"-\")[0];\n\t\t\t\treturn {\n\t\t\t\t\tfullTag: tag,\n\t\t\t\t\tbaseTag,\n\t\t\t\t\tq: Number(q),\n\t\t\t\t};\n\t\t\t})\n\t\t\t.sort((a, b) => b.q - a.q);\n\n\t\tfor (const lang of languages) {\n\t\t\tconst fullLocale = toLocale(lang.fullTag);\n\t\t\tif (fullLocale) {\n\t\t\t\treturn fullLocale;\n\t\t\t}\n\n\t\t\tconst baseLocale = toLocale(lang.baseTag);\n\t\t\tif (baseLocale) {\n\t\t\t\treturn baseLocale;\n\t\t\t}\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\treturn undefined;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-header.test.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-header.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { test, expect } from "vitest";
|
|
2
|
+
import { createParaglide } from "../create-paraglide.js";
|
|
3
|
+
test("returns the preferred locale from Accept-Language header", async () => {
|
|
4
|
+
const runtime = await createParaglide({
|
|
5
|
+
baseLocale: "en",
|
|
6
|
+
locales: ["en", "fr", "de"],
|
|
7
|
+
});
|
|
8
|
+
// simple direct match
|
|
9
|
+
const request = new Request("http://example.com", {
|
|
10
|
+
headers: {
|
|
11
|
+
"Accept-Language": "en-US;q=0.8,fr;q=0.9,de;q=0.6",
|
|
12
|
+
},
|
|
13
|
+
});
|
|
14
|
+
const locale = runtime.extractLocaleFromHeader(request);
|
|
15
|
+
expect(locale).toBe("fr");
|
|
16
|
+
// language tag match
|
|
17
|
+
const request2 = new Request("http://example.com", {
|
|
18
|
+
headers: {
|
|
19
|
+
"Accept-Language": "en-US;q=0.8,nl;q=0.9,de;q=0.7",
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
const locale2 = runtime.extractLocaleFromHeader(request2);
|
|
23
|
+
// Since "nl" isn't in our locales, and "de" has the highest q-value after "nl"
|
|
24
|
+
expect(locale2).toBe("en");
|
|
25
|
+
// no match
|
|
26
|
+
const request3 = new Request("http://example.com", {
|
|
27
|
+
headers: {
|
|
28
|
+
"Accept-Language": "nl;q=0.9,es;q=0.6",
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
const locale3 = runtime.extractLocaleFromHeader(request3);
|
|
32
|
+
expect(locale3).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
test("returns undefined if no Accept-Language header is present", async () => {
|
|
35
|
+
const runtime = await createParaglide({
|
|
36
|
+
baseLocale: "en",
|
|
37
|
+
locales: ["en", "fr", "de"],
|
|
38
|
+
});
|
|
39
|
+
const request = new Request("http://example.com");
|
|
40
|
+
const locale = runtime.extractLocaleFromHeader(request);
|
|
41
|
+
expect(locale).toBeUndefined();
|
|
42
|
+
});
|
|
43
|
+
test("canonicalizes matched locale from Accept-Language header", async () => {
|
|
44
|
+
const runtime = await createParaglide({
|
|
45
|
+
baseLocale: "en",
|
|
46
|
+
locales: ["en", "pt-BR"],
|
|
47
|
+
});
|
|
48
|
+
const request = new Request("http://example.com", {
|
|
49
|
+
headers: {
|
|
50
|
+
"Accept-Language": "pt-br, en;q=0.8",
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
expect(runtime.extractLocaleFromHeader(request)).toBe("pt-BR");
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=extract-locale-from-header.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-header.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-header.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,IAAI,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;IAC3E,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAC3B,CAAC,CAAC;IAEH,sBAAsB;IACtB,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,oBAAoB,EAAE;QACjD,OAAO,EAAE;YACR,iBAAiB,EAAE,+BAA+B;SAClD;KACD,CAAC,CAAC;IACH,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE1B,qBAAqB;IACrB,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,oBAAoB,EAAE;QAClD,OAAO,EAAE;YACR,iBAAiB,EAAE,+BAA+B;SAClD;KACD,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC1D,+EAA+E;IAC/E,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE3B,WAAW;IACX,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,oBAAoB,EAAE;QAClD,OAAO,EAAE;YACR,iBAAiB,EAAE,mBAAmB;SACtC;KACD,CAAC,CAAC;IACH,MAAM,OAAO,GAAG,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IAC1D,MAAM,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,CAAC;AACjC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;IAC5E,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;KAC3B,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,oBAAoB,CAAC,CAAC;IAClD,MAAM,MAAM,GAAG,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC;IACxD,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,EAAE,CAAC;AAChC,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;IAC3E,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;KACxB,CAAC,CAAC;IAEH,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,oBAAoB,EAAE;QACjD,OAAO,EAAE;YACR,iBAAiB,EAAE,iBAAiB;SACpC;KACD,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,uBAAuB,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AAChE,CAAC,CAAC,CAAC","sourcesContent":["import { test, expect } from \"vitest\";\nimport { createParaglide } from \"../create-paraglide.js\";\n\ntest(\"returns the preferred locale from Accept-Language header\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t});\n\n\t// simple direct match\n\tconst request = new Request(\"http://example.com\", {\n\t\theaders: {\n\t\t\t\"Accept-Language\": \"en-US;q=0.8,fr;q=0.9,de;q=0.6\",\n\t\t},\n\t});\n\tconst locale = runtime.extractLocaleFromHeader(request);\n\texpect(locale).toBe(\"fr\");\n\n\t// language tag match\n\tconst request2 = new Request(\"http://example.com\", {\n\t\theaders: {\n\t\t\t\"Accept-Language\": \"en-US;q=0.8,nl;q=0.9,de;q=0.7\",\n\t\t},\n\t});\n\tconst locale2 = runtime.extractLocaleFromHeader(request2);\n\t// Since \"nl\" isn't in our locales, and \"de\" has the highest q-value after \"nl\"\n\texpect(locale2).toBe(\"en\");\n\n\t// no match\n\tconst request3 = new Request(\"http://example.com\", {\n\t\theaders: {\n\t\t\t\"Accept-Language\": \"nl;q=0.9,es;q=0.6\",\n\t\t},\n\t});\n\tconst locale3 = runtime.extractLocaleFromHeader(request3);\n\texpect(locale3).toBeUndefined();\n});\n\ntest(\"returns undefined if no Accept-Language header is present\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t});\n\n\tconst request = new Request(\"http://example.com\");\n\tconst locale = runtime.extractLocaleFromHeader(request);\n\texpect(locale).toBeUndefined();\n});\n\ntest(\"canonicalizes matched locale from Accept-Language header\", async () => {\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"pt-BR\"],\n\t});\n\n\tconst request = new Request(\"http://example.com\", {\n\t\theaders: {\n\t\t\t\"Accept-Language\": \"pt-br, en;q=0.8\",\n\t\t},\n\t});\n\n\texpect(runtime.extractLocaleFromHeader(request)).toBe(\"pt-BR\");\n});\n"]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Negotiates a preferred language from navigator.languages.
|
|
3
|
+
*
|
|
4
|
+
* Use the function on the client to extract the locale
|
|
5
|
+
* from the navigator.languages array.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* const locale = extractLocaleFromNavigator();
|
|
9
|
+
*
|
|
10
|
+
* @returns {Locale | undefined}
|
|
11
|
+
*/
|
|
12
|
+
export declare function extractLocaleFromNavigator(): Locale | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-navigator.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-navigator.js"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,wBAAgB,0BAA0B,IAF7B,MAAM,GAAG,SAAS,CAyB9B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { toLocale } from "./check-locale.js";
|
|
2
|
+
/**
|
|
3
|
+
* Negotiates a preferred language from navigator.languages.
|
|
4
|
+
*
|
|
5
|
+
* Use the function on the client to extract the locale
|
|
6
|
+
* from the navigator.languages array.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const locale = extractLocaleFromNavigator();
|
|
10
|
+
*
|
|
11
|
+
* @returns {Locale | undefined}
|
|
12
|
+
*/
|
|
13
|
+
export function extractLocaleFromNavigator() {
|
|
14
|
+
if (!navigator?.languages?.length) {
|
|
15
|
+
return undefined;
|
|
16
|
+
}
|
|
17
|
+
const languages = navigator.languages.map((lang) => ({
|
|
18
|
+
fullTag: lang,
|
|
19
|
+
baseTag: lang.split("-")[0],
|
|
20
|
+
}));
|
|
21
|
+
for (const lang of languages) {
|
|
22
|
+
const fullLocale = toLocale(lang.fullTag);
|
|
23
|
+
if (fullLocale) {
|
|
24
|
+
return fullLocale;
|
|
25
|
+
}
|
|
26
|
+
const baseLocale = toLocale(lang.baseTag);
|
|
27
|
+
if (baseLocale) {
|
|
28
|
+
return baseLocale;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=extract-locale-from-navigator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-navigator.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-navigator.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAE7C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,0BAA0B;IACzC,IAAI,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;QACnC,OAAO,SAAS,CAAC;IAClB,CAAC;IAED,MAAM,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QACpD,OAAO,EAAE,IAAI;QACb,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;KAC3B,CAAC,CAAC,CAAC;IAEJ,KAAK,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;QAC9B,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,UAAU,EAAE,CAAC;YAChB,OAAO,UAAU,CAAC;QACnB,CAAC;QAED,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,UAAU,EAAE,CAAC;YAChB,OAAO,UAAU,CAAC;QACnB,CAAC;IACF,CAAC;IAED,OAAO,SAAS,CAAC;AAClB,CAAC","sourcesContent":["import { toLocale } from \"./check-locale.js\";\n\n/**\n * Negotiates a preferred language from navigator.languages.\n *\n * Use the function on the client to extract the locale\n * from the navigator.languages array.\n *\n * @example\n * const locale = extractLocaleFromNavigator();\n *\n * @returns {Locale | undefined}\n */\nexport function extractLocaleFromNavigator() {\n\tif (!navigator?.languages?.length) {\n\t\treturn undefined;\n\t}\n\n\tconst languages = navigator.languages.map((lang) => ({\n\t\tfullTag: lang,\n\t\tbaseTag: lang.split(\"-\")[0],\n\t}));\n\n\tfor (const lang of languages) {\n\t\tconst fullLocale = toLocale(lang.fullTag);\n\t\tif (fullLocale) {\n\t\t\treturn fullLocale;\n\t\t}\n\n\t\tconst baseLocale = toLocale(lang.baseTag);\n\t\tif (baseLocale) {\n\t\t\treturn baseLocale;\n\t\t}\n\t}\n\n\treturn undefined;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-navigator.test.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-navigator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { expect, test } from "vitest";
|
|
2
|
+
import { createParaglide } from "../create-paraglide.js";
|
|
3
|
+
test("returns the preferred locale from navigator.languages", async () => {
|
|
4
|
+
const originalNavigator = globalThis.navigator;
|
|
5
|
+
const runtime = await createParaglide({
|
|
6
|
+
baseLocale: "en",
|
|
7
|
+
locales: ["en", "fr", "de"],
|
|
8
|
+
isServer: "false",
|
|
9
|
+
strategy: ["preferredLanguage"],
|
|
10
|
+
});
|
|
11
|
+
// Mock navigator.languages
|
|
12
|
+
Object.defineProperty(globalThis, "navigator", {
|
|
13
|
+
value: {
|
|
14
|
+
languages: ["fr-FR", "en-US", "de"],
|
|
15
|
+
},
|
|
16
|
+
configurable: true,
|
|
17
|
+
});
|
|
18
|
+
expect(runtime.getLocale()).toBe("fr");
|
|
19
|
+
// Restore original navigator
|
|
20
|
+
Object.defineProperty(globalThis, "navigator", {
|
|
21
|
+
value: originalNavigator,
|
|
22
|
+
configurable: true,
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
test("canonicalizes navigator locale casing", async () => {
|
|
26
|
+
const originalNavigator = globalThis.navigator;
|
|
27
|
+
const runtime = await createParaglide({
|
|
28
|
+
baseLocale: "en",
|
|
29
|
+
locales: ["en", "pt-BR"],
|
|
30
|
+
isServer: "false",
|
|
31
|
+
strategy: ["preferredLanguage"],
|
|
32
|
+
});
|
|
33
|
+
Object.defineProperty(globalThis, "navigator", {
|
|
34
|
+
value: {
|
|
35
|
+
languages: ["pt-br", "en-US"],
|
|
36
|
+
},
|
|
37
|
+
configurable: true,
|
|
38
|
+
});
|
|
39
|
+
expect(runtime.getLocale()).toBe("pt-BR");
|
|
40
|
+
Object.defineProperty(globalThis, "navigator", {
|
|
41
|
+
value: originalNavigator,
|
|
42
|
+
configurable: true,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
//# sourceMappingURL=extract-locale-from-navigator.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-navigator.test.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-navigator.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,IAAI,CAAC,uDAAuD,EAAE,KAAK,IAAI,EAAE;IACxE,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC;IAE/C,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC;QAC3B,QAAQ,EAAE,OAAO;QACjB,QAAQ,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC,CAAC;IAEH,2BAA2B;IAC3B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW,EAAE;QAC9C,KAAK,EAAE;YACN,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,CAAC;SACnC;QACD,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAEvC,6BAA6B;IAC7B,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW,EAAE;QAC9C,KAAK,EAAE,iBAAiB;QACxB,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,IAAI,CAAC,uCAAuC,EAAE,KAAK,IAAI,EAAE;IACxD,MAAM,iBAAiB,GAAG,UAAU,CAAC,SAAS,CAAC;IAE/C,MAAM,OAAO,GAAG,MAAM,eAAe,CAAC;QACrC,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC;QACxB,QAAQ,EAAE,OAAO;QACjB,QAAQ,EAAE,CAAC,mBAAmB,CAAC;KAC/B,CAAC,CAAC;IAEH,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW,EAAE;QAC9C,KAAK,EAAE;YACN,SAAS,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC;SAC7B;QACD,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;IAEH,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAE1C,MAAM,CAAC,cAAc,CAAC,UAAU,EAAE,WAAW,EAAE;QAC9C,KAAK,EAAE,iBAAiB;QACxB,YAAY,EAAE,IAAI;KAClB,CAAC,CAAC;AACJ,CAAC,CAAC,CAAC","sourcesContent":["import { expect, test } from \"vitest\";\nimport { createParaglide } from \"../create-paraglide.js\";\n\ntest(\"returns the preferred locale from navigator.languages\", async () => {\n\tconst originalNavigator = globalThis.navigator;\n\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"fr\", \"de\"],\n\t\tisServer: \"false\",\n\t\tstrategy: [\"preferredLanguage\"],\n\t});\n\n\t// Mock navigator.languages\n\tObject.defineProperty(globalThis, \"navigator\", {\n\t\tvalue: {\n\t\t\tlanguages: [\"fr-FR\", \"en-US\", \"de\"],\n\t\t},\n\t\tconfigurable: true,\n\t});\n\n\texpect(runtime.getLocale()).toBe(\"fr\");\n\n\t// Restore original navigator\n\tObject.defineProperty(globalThis, \"navigator\", {\n\t\tvalue: originalNavigator,\n\t\tconfigurable: true,\n\t});\n});\n\ntest(\"canonicalizes navigator locale casing\", async () => {\n\tconst originalNavigator = globalThis.navigator;\n\n\tconst runtime = await createParaglide({\n\t\tbaseLocale: \"en\",\n\t\tlocales: [\"en\", \"pt-BR\"],\n\t\tisServer: \"false\",\n\t\tstrategy: [\"preferredLanguage\"],\n\t});\n\n\tObject.defineProperty(globalThis, \"navigator\", {\n\t\tvalue: {\n\t\t\tlanguages: [\"pt-br\", \"en-US\"],\n\t\t},\n\t\tconfigurable: true,\n\t});\n\n\texpect(runtime.getLocale()).toBe(\"pt-BR\");\n\n\tObject.defineProperty(globalThis, \"navigator\", {\n\t\tvalue: originalNavigator,\n\t\tconfigurable: true,\n\t});\n});\n"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Asynchronously extracts a locale from a request.
|
|
3
|
+
*
|
|
4
|
+
* This function supports async custom server strategies, unlike the synchronous
|
|
5
|
+
* `extractLocaleFromRequest`. Use this function when you have custom server strategies
|
|
6
|
+
* that need to perform asynchronous operations (like database calls) in their getLocale method.
|
|
7
|
+
*
|
|
8
|
+
* The function first processes any custom server strategies asynchronously, then falls back
|
|
9
|
+
* to the synchronous `extractLocaleFromRequest` for all other strategies.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* // Basic usage
|
|
15
|
+
* const locale = await extractLocaleFromRequestAsync(request);
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // With custom async server strategy
|
|
19
|
+
* defineCustomServerStrategy("custom-database", {
|
|
20
|
+
* getLocale: async (request) => {
|
|
21
|
+
* const userId = extractUserIdFromRequest(request);
|
|
22
|
+
* return await getUserLocaleFromDatabase(userId);
|
|
23
|
+
* }
|
|
24
|
+
* });
|
|
25
|
+
*
|
|
26
|
+
* const locale = await extractLocaleFromRequestAsync(request);
|
|
27
|
+
*
|
|
28
|
+
* @param {Request} request - The request object to extract the locale from.
|
|
29
|
+
* @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.
|
|
30
|
+
* @returns {Promise<Locale>} The extracted locale.
|
|
31
|
+
*/
|
|
32
|
+
export declare const extractLocaleFromRequestAsync: (request: Request, options?: {
|
|
33
|
+
effectiveRequestUrl?: string | URL;
|
|
34
|
+
}) => Promise<Locale>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-request-async.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-request-async.js"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,6BAA6B,YAJ/B,OAAO,YACP;IAAE,mBAAmB,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;CAAE,KACpC,OAAO,CAAC,MAAM,CAkC1B,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { customServerStrategies, isCustomStrategy } from "./strategy.js";
|
|
2
|
+
import { getStrategyForUrl } from "./route-strategy.js";
|
|
3
|
+
import { toLocale } from "./check-locale.js";
|
|
4
|
+
import { extractLocaleFromRequestWithStrategies } from "./extract-locale-from-request.js";
|
|
5
|
+
/**
|
|
6
|
+
* Asynchronously extracts a locale from a request.
|
|
7
|
+
*
|
|
8
|
+
* This function supports async custom server strategies, unlike the synchronous
|
|
9
|
+
* `extractLocaleFromRequest`. Use this function when you have custom server strategies
|
|
10
|
+
* that need to perform asynchronous operations (like database calls) in their getLocale method.
|
|
11
|
+
*
|
|
12
|
+
* The function first processes any custom server strategies asynchronously, then falls back
|
|
13
|
+
* to the synchronous `extractLocaleFromRequest` for all other strategies.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* // Basic usage
|
|
19
|
+
* const locale = await extractLocaleFromRequestAsync(request);
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* // With custom async server strategy
|
|
23
|
+
* defineCustomServerStrategy("custom-database", {
|
|
24
|
+
* getLocale: async (request) => {
|
|
25
|
+
* const userId = extractUserIdFromRequest(request);
|
|
26
|
+
* return await getUserLocaleFromDatabase(userId);
|
|
27
|
+
* }
|
|
28
|
+
* });
|
|
29
|
+
*
|
|
30
|
+
* const locale = await extractLocaleFromRequestAsync(request);
|
|
31
|
+
*
|
|
32
|
+
* @param {Request} request - The request object to extract the locale from.
|
|
33
|
+
* @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.
|
|
34
|
+
* @returns {Promise<Locale>} The extracted locale.
|
|
35
|
+
*/
|
|
36
|
+
export const extractLocaleFromRequestAsync = async (request, options = {}) => {
|
|
37
|
+
/** @type {string|undefined} */
|
|
38
|
+
let locale;
|
|
39
|
+
const effectiveRequestUrl = resolveEffectiveRequestUrlFromRequestAsync(request, options.effectiveRequestUrl);
|
|
40
|
+
const strategy = getStrategyForUrl(effectiveRequestUrl);
|
|
41
|
+
// Process custom strategies first, in order
|
|
42
|
+
for (const strat of strategy) {
|
|
43
|
+
if (isCustomStrategy(strat) && customServerStrategies.has(strat)) {
|
|
44
|
+
const handler = customServerStrategies.get(strat);
|
|
45
|
+
if (handler) {
|
|
46
|
+
/** @type {string|undefined} */
|
|
47
|
+
locale = await handler.getLocale(request);
|
|
48
|
+
}
|
|
49
|
+
// If we got a valid locale from this custom strategy, use it
|
|
50
|
+
const matchedLocale = toLocale(locale);
|
|
51
|
+
if (matchedLocale) {
|
|
52
|
+
return matchedLocale;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
// If no custom strategy provided a valid locale, fall back to sync version
|
|
57
|
+
return extractLocaleFromRequestWithStrategies(request, strategy, effectiveRequestUrl);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* @param {Request} request
|
|
61
|
+
* @param {string | URL | undefined} effectiveRequestUrl
|
|
62
|
+
* @returns {URL}
|
|
63
|
+
*/
|
|
64
|
+
function resolveEffectiveRequestUrlFromRequestAsync(request, effectiveRequestUrl = request.url) {
|
|
65
|
+
if (effectiveRequestUrl instanceof URL) {
|
|
66
|
+
return new URL(effectiveRequestUrl.href);
|
|
67
|
+
}
|
|
68
|
+
return new URL(effectiveRequestUrl, request.url);
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=extract-locale-from-request-async.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-request-async.js","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-request-async.js"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAC7C,OAAO,EAAE,sCAAsC,EAAE,MAAM,kCAAkC,CAAC;AAE1F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,6BAA6B,GAAG,KAAK,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,EAAE,EAAE;IAC5E,+BAA+B;IAC/B,IAAI,MAAM,CAAC;IACX,MAAM,mBAAmB,GAAG,0CAA0C,CACrE,OAAO,EACP,OAAO,CAAC,mBAAmB,CAC3B,CAAC;IACF,MAAM,QAAQ,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,CAAC;IAExD,4CAA4C;IAC5C,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE,CAAC;QAC9B,IAAI,gBAAgB,CAAC,KAAK,CAAC,IAAI,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC;YAClE,MAAM,OAAO,GAAG,sBAAsB,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YAClD,IAAI,OAAO,EAAE,CAAC;gBACb,+BAA+B;gBAC/B,MAAM,GAAG,MAAM,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;YAC3C,CAAC;YAED,6DAA6D;YAC7D,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC;YACvC,IAAI,aAAa,EAAE,CAAC;gBACnB,OAAO,aAAa,CAAC;YACtB,CAAC;QACF,CAAC;IACF,CAAC;IAED,2EAA2E;IAC3E,OAAO,sCAAsC,CAC5C,OAAO,EACP,QAAQ,EACR,mBAAmB,CACnB,CAAC;AACH,CAAC,CAAC;AAEF;;;;GAIG;AACH,SAAS,0CAA0C,CAClD,OAAO,EACP,mBAAmB,GAAG,OAAO,CAAC,GAAG;IAEjC,IAAI,mBAAmB,YAAY,GAAG,EAAE,CAAC;QACxC,OAAO,IAAI,GAAG,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC;IAC1C,CAAC;IAED,OAAO,IAAI,GAAG,CAAC,mBAAmB,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;AAClD,CAAC","sourcesContent":["import { customServerStrategies, isCustomStrategy } from \"./strategy.js\";\nimport { getStrategyForUrl } from \"./route-strategy.js\";\nimport { toLocale } from \"./check-locale.js\";\nimport { extractLocaleFromRequestWithStrategies } from \"./extract-locale-from-request.js\";\n\n/**\n * Asynchronously extracts a locale from a request.\n *\n * This function supports async custom server strategies, unlike the synchronous\n * `extractLocaleFromRequest`. Use this function when you have custom server strategies\n * that need to perform asynchronous operations (like database calls) in their getLocale method.\n *\n * The function first processes any custom server strategies asynchronously, then falls back\n * to the synchronous `extractLocaleFromRequest` for all other strategies.\n *\n * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}\n *\n * @example\n * // Basic usage\n * const locale = await extractLocaleFromRequestAsync(request);\n *\n * @example\n * // With custom async server strategy\n * defineCustomServerStrategy(\"custom-database\", {\n * getLocale: async (request) => {\n * const userId = extractUserIdFromRequest(request);\n * return await getUserLocaleFromDatabase(userId);\n * }\n * });\n *\n * const locale = await extractLocaleFromRequestAsync(request);\n *\n * @param {Request} request - The request object to extract the locale from.\n * @param {{ effectiveRequestUrl?: string | URL }} [options] - Effective request URL to use for route matching and locale detection with the URL strategy.\n * @returns {Promise<Locale>} The extracted locale.\n */\nexport const extractLocaleFromRequestAsync = async (request, options = {}) => {\n\t/** @type {string|undefined} */\n\tlet locale;\n\tconst effectiveRequestUrl = resolveEffectiveRequestUrlFromRequestAsync(\n\t\trequest,\n\t\toptions.effectiveRequestUrl\n\t);\n\tconst strategy = getStrategyForUrl(effectiveRequestUrl);\n\n\t// Process custom strategies first, in order\n\tfor (const strat of strategy) {\n\t\tif (isCustomStrategy(strat) && customServerStrategies.has(strat)) {\n\t\t\tconst handler = customServerStrategies.get(strat);\n\t\t\tif (handler) {\n\t\t\t\t/** @type {string|undefined} */\n\t\t\t\tlocale = await handler.getLocale(request);\n\t\t\t}\n\n\t\t\t// If we got a valid locale from this custom strategy, use it\n\t\t\tconst matchedLocale = toLocale(locale);\n\t\t\tif (matchedLocale) {\n\t\t\t\treturn matchedLocale;\n\t\t\t}\n\t\t}\n\t}\n\n\t// If no custom strategy provided a valid locale, fall back to sync version\n\treturn extractLocaleFromRequestWithStrategies(\n\t\trequest,\n\t\tstrategy,\n\t\teffectiveRequestUrl\n\t);\n};\n\n/**\n * @param {Request} request\n * @param {string | URL | undefined} effectiveRequestUrl\n * @returns {URL}\n */\nfunction resolveEffectiveRequestUrlFromRequestAsync(\n\trequest,\n\teffectiveRequestUrl = request.url\n) {\n\tif (effectiveRequestUrl instanceof URL) {\n\t\treturn new URL(effectiveRequestUrl.href);\n\t}\n\n\treturn new URL(effectiveRequestUrl, request.url);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"extract-locale-from-request-async.test.d.ts","sourceRoot":"","sources":["../../../src/compiler/runtime/extract-locale-from-request-async.test.ts"],"names":[],"mappings":""}
|