Add Persian (fa) translation, incl. RTL toggle

- New locales/fa.ts, 618 keys, full parity with de/en/zh-CN
- document.documentElement.dir flips to rtl/ltr with the active language
- Language selector + system-locale auto-detect (fa-*) updated

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Sonnet 5 committed 2026-09-14 19:01:16 +00:00
1 parent 732a905f32
commit be946c2a5e
4 files changed
+677 -2

No files matched your search

+9 -2
View File
@@ -1,7 +1,9 @@
import { createContext, useContext, useEffect, useState, type ReactNode } from "react";
import { zhCN } from "./locales/zh-CN";
import { fa } from "./locales/fa";
export type Lang = "de" | "en" | "zh-CN";
export type Lang = "de" | "en" | "zh-CN" | "fa";
const RTL_LANGS = new Set<Lang>(["fa"]);
export type LangPref = "auto" | Lang;
const LANGUAGE_KEY = "webspeak3:language";
@@ -337,6 +339,7 @@ const translations: Record<Lang, Record<string, string>> = {
"app.language.de": "Deutsch",
"app.language.en": "English",
"app.language.zh-CN": "简体中文",
"app.language.fa": "فارسی",
"playback.title": "Wiedergabe",
"playback.subtitle": "Ändern der Wiedergabeeinstellungen",
@@ -1001,6 +1004,7 @@ const translations: Record<Lang, Record<string, string>> = {
"app.language.de": "Deutsch",
"app.language.en": "English",
"app.language.zh-CN": "简体中文",
"app.language.fa": "فارسی",
"playback.title": "Playback",
"playback.subtitle": "Change your playback settings",
@@ -1340,12 +1344,14 @@ const translations: Record<Lang, Record<string, string>> = {
"nachrichten.delete": "Delete",
},
"zh-CN": zhCN,
fa,
};
function detectSystemLang(): Lang {
const nav = typeof navigator !== "undefined" ? navigator.language : "en";
const normalized = nav?.toLowerCase() ?? "en";
if (normalized.startsWith("zh")) return "zh-CN";
if (normalized.startsWith("fa")) return "fa";
return normalized.startsWith("de") ? "de" : "en";
}
@@ -1355,7 +1361,7 @@ export function resolveLang(pref: LangPref): Lang {
export function loadLangPref(): LangPref {
const raw = localStorage.getItem(LANGUAGE_KEY);
return raw === "de" || raw === "en" || raw === "zh-CN" || raw === "auto" ? raw : "auto";
return raw === "de" || raw === "en" || raw === "zh-CN" || raw === "fa" || raw === "auto" ? raw : "auto";
}
export function saveLangPref(pref: LangPref) {
@@ -1386,6 +1392,7 @@ export function LanguageProvider({ children }: { children: ReactNode }) {
useEffect(() => {
document.documentElement.lang = lang;
document.documentElement.dir = RTL_LANGS.has(lang) ? "rtl" : "ltr";
}, [lang]);
const t: TranslateFn = (key, vars) =>