Initial commit: fristy.net personal site
Build & Push / Build & Push Image (push) Canceled after 0s
Build & Push / Lint & Build (push) Canceled after 41s

This commit is contained in:
fristy committed 2026-09-10 04:23:21 +03:00
commit 03b00358c0
56 files changed
+6038

No files matched your search

+48
View File
@@ -0,0 +1,48 @@
export const LOCALES = ["tr", "en", "de"] as const;
export type Locale = (typeof LOCALES)[number];
export const DEFAULT_LOCALE: Locale = "tr";
export const LOCALE_COOKIE = "locale";
export const LOCALE_LABELS: Record<Locale, string> = {
tr: "TR",
en: "EN",
de: "DE",
};
export function isLocale(value: string): value is Locale {
return (LOCALES as readonly string[]).includes(value);
}
export function matchLocale(acceptLanguage: string | null): Locale {
if (!acceptLanguage) {
return DEFAULT_LOCALE;
}
const preferences = acceptLanguage
.split(",")
.map((part) => {
const [range, ...params] = part.trim().split(";");
let q = 1;
for (const param of params) {
const match = param.trim().match(/^q=([0-9.]+)$/);
if (match) {
q = Number(match[1]);
}
}
return { range: range.toLowerCase(), q };
})
.sort((a, b) => b.q - a.q);
for (const { range } of preferences) {
if (range === "*") {
return DEFAULT_LOCALE;
}
const base = range.split("-")[0];
if (isLocale(base)) {
return base;
}
}
return DEFAULT_LOCALE;
}