mirror of
https://github.com/arsvendg/Stirling-PDF.git
synced 2026-07-16 19:33:11 +02:00
Change default language to en-US and add US language (#6621)
This commit is contained in:
@@ -5,7 +5,8 @@ import TomlBackend from "@app/i18n/tomlBackend";
|
||||
|
||||
// Define supported languages (based on your existing translations)
|
||||
export const supportedLanguages = {
|
||||
"en-GB": "English",
|
||||
"en-US": "English (US)",
|
||||
"en-GB": "English (UK)",
|
||||
"ar-AR": "العربية",
|
||||
"az-AZ": "Azərbaycan Dili",
|
||||
"bg-BG": "Български",
|
||||
@@ -72,7 +73,7 @@ i18n
|
||||
.use(LanguageDetector)
|
||||
.use(initReactI18next)
|
||||
.init({
|
||||
fallbackLng: "en-GB",
|
||||
fallbackLng: "en-US",
|
||||
supportedLngs: Object.keys(supportedLanguages),
|
||||
load: "currentOnly",
|
||||
nonExplicitSupportedLngs: false,
|
||||
@@ -100,8 +101,8 @@ i18n
|
||||
order: ["localStorage", "navigator", "htmlTag"],
|
||||
caches: [], // Don't cache auto-detected language - only cache when user manually selects
|
||||
convertDetectedLanguage: (lng: string) => {
|
||||
// Map en and en-US to en-GB
|
||||
if (lng === "en" || lng === "en-US") return "en-GB";
|
||||
// Map bare en to en-US
|
||||
if (lng === "en") return "en-US";
|
||||
return lng;
|
||||
},
|
||||
},
|
||||
@@ -154,7 +155,7 @@ export function normalizeLanguageCode(languageCode: string): string {
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert language codes to underscore format (e.g., en-GB → en_GB)
|
||||
* Convert language codes to underscore format (e.g., en-US → en_US)
|
||||
* Used for backend API communication which expects underscore format
|
||||
*/
|
||||
export function toUnderscoreFormat(languageCode: string): string {
|
||||
@@ -212,7 +213,7 @@ export function setUserLanguage(language: string): void {
|
||||
* Updates the supported languages list dynamically based on config
|
||||
* If configLanguages is null/empty, all languages remain available
|
||||
* Otherwise, only the specified languages are enabled with the first valid
|
||||
* option (preferring en-GB when present) used as the fallback language.
|
||||
* option (preferring en-US when present) used as the fallback language.
|
||||
*
|
||||
* @param configLanguages - Optional array of language codes from server config (ui.languages)
|
||||
* @param defaultLocale - Optional default language for new users (system.defaultLocale)
|
||||
@@ -248,12 +249,12 @@ export function updateSupportedLanguages(
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine fallback: prefer validDefault if in the list, then en-GB, then first valid language
|
||||
// Determine fallback: prefer validDefault if in the list, then en-US, then first valid language
|
||||
const fallback =
|
||||
validDefault && validLanguages.includes(validDefault)
|
||||
? validDefault
|
||||
: validLanguages.includes("en-GB")
|
||||
? "en-GB"
|
||||
: validLanguages.includes("en-US")
|
||||
? "en-US"
|
||||
: validLanguages[0];
|
||||
|
||||
i18n.options.supportedLngs = validLanguages;
|
||||
|
||||
Reference in New Issue
Block a user