#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Load Serbian translations under the canonical sr-Latn-RS tag (#8293)
Anthony Stirling1760637d78ac
diff --git a/frontend/editor/public/locales/sr-LATN-RS/translation.toml b/frontend/editor/public/locales/sr-Latn-RS/translation.tomlsimilarity index 100%rename from frontend/editor/public/locales/sr-LATN-RS/translation.tomlrename to frontend/editor/public/locales/sr-Latn-RS/translation.tomldiff --git a/frontend/editor/src/core/i18n.ts b/frontend/editor/src/core/i18n.tsindex da8575b972..6bb5269611 100644--- a/frontend/editor/src/core/i18n.ts+++ b/frontend/editor/src/core/i18n.ts@@ -58,8 +58,8 @@ i18ncaches: [], // Don't cache auto-detected language - only cache when user manually selectsconvertDetectedLanguage: (lng: string) => {// Map bare en to en-US- if (lng === "en") return "en-US";- return lng;+ const normalized = normalizeLanguageCode(lng);+ return normalized === "en" ? "en-US" : normalized;},},diff --git a/frontend/editor/src/core/i18n/languages.test.ts b/frontend/editor/src/core/i18n/languages.test.tsnew file mode 100644index 0000000000..1056e48a90--- /dev/null+++ b/frontend/editor/src/core/i18n/languages.test.ts@@ -0,0 +1,57 @@+import fs from "node:fs";+import path from "node:path";+import { fileURLToPath } from "node:url";+import { describe, expect, it } from "vitest";+import {+ normalizeLanguageCode,+ supportedLanguages,+ toUnderscoreFormat,+} from "@app/i18n/languages";++const LOCALES_DIR = path.resolve(+ path.dirname(fileURLToPath(import.meta.url)),+ "../../../public/locales",+);++const localeFolders = fs+ .readdirSync(LOCALES_DIR, { withFileTypes: true })+ .filter((entry) => entry.isDirectory())+ .map((entry) => entry.name);++describe("locale folders", () => {+ it.each(localeFolders)("%s is a canonical BCP 47 tag", (folder) => {+ expect(Intl.getCanonicalLocales(folder)[0]).toBe(folder);+ });++ it.each(Object.keys(supportedLanguages))(+ "supported language %s is canonical and has an exact-case folder",+ (code) => {+ expect(Intl.getCanonicalLocales(code)[0]).toBe(code);+ expect(localeFolders).toContain(code);+ },+ );+});++describe("normalizeLanguageCode", () => {+ it.each(Object.keys(supportedLanguages))(+ "round-trips %s through the backend underscore form",+ (code) => {+ expect(normalizeLanguageCode(toUnderscoreFormat(code))).toBe(code);+ },+ );++ it.each(["sr-LATN-RS", "sr_LATN_RS", "sr-latn-rs", "SR_Latn_rs"])(+ "resolves legacy %s to Serbian",+ (legacy) => {+ const normalized = normalizeLanguageCode(legacy);+ expect(normalized).toBe("sr-Latn-RS");+ expect(supportedLanguages[normalized]).toBe("Srpski");+ },+ );++ it("keeps language and region casing", () => {+ expect(normalizeLanguageCode("EN")).toBe("en");+ expect(normalizeLanguageCode("en_gb")).toBe("en-GB");+ expect(normalizeLanguageCode("zh-tw")).toBe("zh-TW");+ });+});diff --git a/frontend/editor/src/core/i18n/languages.ts b/frontend/editor/src/core/i18n/languages.tsindex d1356bd21b..714d990acb 100644--- a/frontend/editor/src/core/i18n/languages.ts+++ b/frontend/editor/src/core/i18n/languages.ts@@ -3,7 +3,10 @@* setups. Pure data + string utilities — no i18next instance or app state.*/-/** Supported languages, keyed by BCP-47-ish code → native display name. */+/**+ * Supported languages by native display name. Keys and `public/locales` folder names must be+ * canonical (`Intl.getCanonicalLocales`): i18next canonicalises tags, so any other casing never matches.+ */export const supportedLanguages: Record<string, string> = {"en-US": "English (US)","en-GB": "English (UK)",@@ -37,7 +40,7 @@ export const supportedLanguages: Record<string, string> = {"ru-RU": "Русский","sk-SK": "Slovensky","sl-SI": "Slovenščina",- "sr-LATN-RS": "Srpski",+ "sr-Latn-RS": "Srpski","sv-SE": "Svenska","th-TH": "ไทย","tr-TR": "Türkçe",@@ -77,10 +80,15 @@ export function normalizeLanguageCode(languageCode: string): string {return base.toLowerCase();}- const normalizedParts = rest.map((part) =>- part.length <= 3 ? part.toUpperCase() : part,- );- return [base.toLowerCase(), ...normalizedParts].join("-");+ return [base.toLowerCase(), ...rest.map(normalizeSubtag)].join("-");+}++// BCP 47 casing: title-case script (4 letters), so legacy "sr_LATN_RS" matches "sr-Latn-RS".+function normalizeSubtag(part: string): string {+ if (part.length === 4) {+ return part.charAt(0).toUpperCase() + part.slice(1).toLowerCase();+ }+ return part.length <= 3 ? part.toUpperCase() : part;}/**diff --git a/frontend/editor/src/proprietary/components/shared/config/configSections/server/SystemCard.tsx b/frontend/editor/src/proprietary/components/shared/config/configSections/server/SystemCard.tsxindex 482c9f4da6..0c64e20af5 100644--- a/frontend/editor/src/proprietary/components/shared/config/configSections/server/SystemCard.tsx+++ b/frontend/editor/src/proprietary/components/shared/config/configSections/server/SystemCard.tsx@@ -41,7 +41,10 @@ export function SystemCard({);const selectedLanguages = useMemo(- () => toUnderscoreLanguages(settings.ui?.languages || []),+ () =>+ toUnderscoreLanguages(+ (settings.ui?.languages || []).map(normalizeLanguageCode),+ ),[settings.ui?.languages],);diff --git a/scripts/ignore_translation.toml b/scripts/ignore_translation.tomlindex 22e2f1247a..c249b69331 100644--- a/scripts/ignore_translation.toml+++ b/scripts/ignore_translation.toml@@ -417,7 +417,7 @@ ignore = ['language.direction',]-[sr_LATN_RS]+[sr_Latn_RS]ignore = ['font','language.direction',diff --git a/scripts/installFonts.sh b/scripts/installFonts.shindex d7eb7af692..f29d850161 100644--- a/scripts/installFonts.sh+++ b/scripts/installFonts.sh@@ -31,7 +31,7 @@ declare -A language_fonts=(["zh_TW"]="font-isas-misc"["ja_JP"]="font-noto font-noto-thai font-noto-tibetan font-ipa font-sony-misc font-jis-misc"["ru_RU"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"- ["sr_LATN_RS"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"+ ["sr_Latn_RS"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"["uk_UA"]="font-vollkorn font-misc-cyrillic font-mutt-misc font-screen-cyrillic font-winitzki-cyrillic font-cronyx-cyrillic"["ko_KR"]="font-noto font-noto-thai font-noto-tibetan"["el_GR"]="font-noto"@@ -40,6 +40,9 @@ declare -A language_fonts=(["GENERAL"]="font-terminus font-dejavu font-noto font-noto-cjk font-awesome font-noto-extra")+# Legacy casing, still accepted in LANGS+language_fonts["sr_LATN_RS"]="${language_fonts["sr_Latn_RS"]}"+# Install fonts for other languages which generally do not need special packages beyond 'font-noto'other_langs=("en_GB" "en_US" "de_DE" "fr_FR" "es_ES" "ca_CA" "it_IT" "pt_BR" "nl_NL" "sv_SE" "pl_PL" "ro_RO" "hu_HU" "tr_TR" "id_ID" "eu_ES")if [[ $LANGS == "ALL" ]]; then