feat(metadata): add original-language preferences (#526)
* feat(metadata): add original-language preferences * fix(settings): show metadata exceptions immediately * docs(settings): add metadata language screenshot * fix(settings): make language exceptions responsive * fix(settings): standardize language display names
This commit is contained in:
@@ -1,34 +1 @@
|
||||
// Catalog filter values for `original_language` are ISO 639-1 codes ("en",
|
||||
// "fr", "ja"). Surfaces show friendly names ("English", "French", "Japanese")
|
||||
// while keeping the underlying value untouched so query rules stay valid.
|
||||
|
||||
let cachedDisplayNames: Intl.DisplayNames | null | undefined;
|
||||
|
||||
function getDisplayNames(): Intl.DisplayNames | null {
|
||||
if (cachedDisplayNames !== undefined) {
|
||||
return cachedDisplayNames;
|
||||
}
|
||||
try {
|
||||
cachedDisplayNames = new Intl.DisplayNames(["en"], { type: "language" });
|
||||
} catch {
|
||||
cachedDisplayNames = null;
|
||||
}
|
||||
return cachedDisplayNames;
|
||||
}
|
||||
|
||||
export function formatLanguage(code: string): string {
|
||||
const trimmed = code.trim();
|
||||
if (!trimmed) return "";
|
||||
const dn = getDisplayNames();
|
||||
if (!dn) return trimmed.toUpperCase();
|
||||
try {
|
||||
const name = dn.of(trimmed);
|
||||
if (name && name !== trimmed) {
|
||||
// Intl.DisplayNames returns lowercase for some locales — capitalize.
|
||||
return name.charAt(0).toUpperCase() + name.slice(1);
|
||||
}
|
||||
} catch {
|
||||
// Fall through to fallback.
|
||||
}
|
||||
return trimmed.toUpperCase();
|
||||
}
|
||||
export { formatLanguage } from "@/lib/languageNames";
|
||||
|
||||
Reference in New Issue
Block a user