diff --git a/.changeset/lucky-eagles-guess.md b/.changeset/lucky-eagles-guess.md new file mode 100644 index 0000000000..3d4824b877 --- /dev/null +++ b/.changeset/lucky-eagles-guess.md @@ -0,0 +1,5 @@ +--- +"@inlang/paraglide-js-adapter-astro": patch +--- + +fix: `languageTag()` not being set properly on windows. This bug was caused by duplicate module instantiation. diff --git a/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/integration.ts b/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/integration.ts index 4bda251cd2..36c1e30c90 100644 --- a/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/integration.ts +++ b/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/integration.ts @@ -3,6 +3,7 @@ import { paraglide } from "@inlang/paraglide-js-adapter-vite" import path from "node:path" import { alias } from "./alias.js" import { fileURLToPath } from "node:url" +import { normaizePath } from "./utilts.js" const __filename = fileURLToPath(import.meta.url) const __dirname = path.dirname(__filename) @@ -23,6 +24,8 @@ export function integration(integrationConfig: { entrypoint: middlewarePath, }) + const runtimePath = path.resolve(process.cwd(), integrationConfig.outdir, "runtime.js") + //Register the vite plugin updateConfig({ vite: { @@ -32,11 +35,10 @@ export function integration(integrationConfig: { outdir: integrationConfig.outdir, }), alias({ - "paraglide-js-adapter-astro:runtime": path.resolve( - process.cwd(), - integrationConfig.outdir, - "runtime.js" - ), + //normalizing the path is very important! + //otherwise you get duplicate modules on windows + //learned that one the hard way (parjs-47) + "paraglide-js-adapter-astro:runtime": normaizePath(runtimePath), }), ], }, diff --git a/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/middleware.ts b/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/middleware.ts index 48299e05ba..d75de3fec0 100644 --- a/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/middleware.ts +++ b/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/middleware.ts @@ -3,18 +3,19 @@ import { setLanguageTag, sourceLanguageTag, } from "paraglide-js-adapter-astro:runtime" -import type { MiddlewareHandler } from "astro" +import { type MiddlewareHandler } from "astro" export const onRequest: MiddlewareHandler = async ({ url, locals, currentLocale }, next) => { const locale = currentLocale ?? getLangFromPath(url.pathname) const dir = guessTextDirection(locale) + setLanguageTag(locale) + locals.paraglide = { lang: locale, dir, } - setLanguageTag(locale) return await next() } diff --git a/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/utilts.ts b/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/utilts.ts new file mode 100644 index 0000000000..b2a615854e --- /dev/null +++ b/inlang/source-code/paraglide/paraglide-js-adapter-astro/src/utilts.ts @@ -0,0 +1,13 @@ +// vendored in from vite +import path from "node:path" + +const windowsSlashRE = /\\/g +function slash(p: string): string { + return p.replace(windowsSlashRE, "/") +} + +const isWindows = typeof process !== "undefined" && process.platform === "win32" + +export function normaizePath(id: string) { + return path.posix.normalize(isWindows ? slash(id) : id) +}