migrate settings

This commit is contained in:
tresabhi committed 2026-11-22 13:58:17 -06:00
1 parent 8dd412ed32
commit 1b50f0bcdd
25 files changed
+335 -237

No files matched your search

@@ -0,0 +1,12 @@
import locales from "@blitzkit/i18n/locales.json";
export function getCurrentPathLocale() {
const pathname = window.location.pathname;
return (
locales.supported.find(
({ locale }) =>
pathname === `/${locale}` || pathname.startsWith(`/${locale}/`),
)?.locale ?? locales.default
);
}
@@ -0,0 +1,20 @@
import locales from "@blitzkit/i18n/locales.json";
import { api } from "../../api/dynamic";
export interface LocaleOption {
locale: string;
flag: string;
name: string;
}
// each locale is named in its own language; run at build time so clients never fetch every locale's strings
export async function getLocaleOptions() {
return Promise.all(
locales.supported.map(async ({ locale, flag }) => {
const strings = await api.strings(locale);
const name = (strings.common.locales as Record<string, string>)[locale];
return { locale, flag, name } satisfies LocaleOption;
}),
);
}
@@ -0,0 +1,16 @@
import locales from "@blitzkit/i18n/locales.json";
import { getCurrentPathLocale } from "./getCurrentPathLocale";
// keeps the current page, swapping only the locale prefix
export function navigateToLocale(locale: string) {
const pathname = window.location.pathname;
const currentLocale = getCurrentPathLocale();
const rawPath =
currentLocale === locales.default
? pathname
: pathname.slice(`/${currentLocale}`.length) || "/";
window.location.pathname = `${
locale === locales.default ? "" : `/${locale}`
}${rawPath}`;
}