i18n / locale routing

The loader inspects ?locale=… first, then accept-language, and looks up matching strings server-side. Every render is a fresh server pick — no client-side switch, no flash-of-wrong-language.

Detected locale: fr

Bonjour

Cette page a détecté votre locale depuis la requête et a choisi des chaînes françaises côté serveur.

Choisir une autre langue :

Source

// Manual locale detection — reads ?locale=… first, then accept-language.
         // (Set [i18n] strategy = "prefix" + locales in bext.config.toml for
    // automatic /en/... routing site-wide; this demo keeps it scoped.)
    function pickLocale(req: Request): string {
                const url = new URL(req.url);
                const q = url.searchParams.get("locale");
                if (q && STRINGS[q]) return q;
                const al = req.headers.get("accept-language") ?? "";
                for (const part of al.split(",")) {
                                const tag = part.split(";")[0].trim().toLowerCase();
                                const short = tag.split("-")[0];
                                if (STRINGS[short]) return short;
                    }
                return "en";
    }
    export async function loader({ request }: LoaderArgs) {
                const locale = pickLocale(request);
                return { locale, strings: STRINGS[locale] };
    }