KeyboardLayoutService: better lang/country matching

This commit is contained in:
Lemmy
2026-01-26 18:29:41 -05:00
parent 624829d721
commit b098a41e9c
+9 -1
View File
@@ -48,8 +48,16 @@ Singleton {
}
// Check for language/country names in the language map
// First, try to match at the start of the string (the primary language)
for (const [lang, code] of Object.entries(languageMap)) {
if (str.includes(lang)) {
if (str.startsWith(lang)) {
return code.toUpperCase();
}
}
// Then try word boundary matching anywhere in the string
for (const [lang, code] of Object.entries(languageMap)) {
const regex = new RegExp(`\\b${lang}\\b`);
if (regex.test(str)) {
return code.toUpperCase();
}
}