Capitalize the language name in some cases (#14)

This commit is contained in:
Alessandro Jean 2023-09-03 16:56:00 -03:00 committed by GitHub
parent 87679463a4
commit 489801174e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,14 +3,19 @@ export function simpleLangName(code: string) {
return "All";
}
const namesInEnglish = new Intl.DisplayNames(["en"], { type: "language" });
return namesInEnglish.of(code)!;
return capitalize(namesInEnglish.of(code)!, "en");
}
export function langName(code: string) {
if (code === "all") {
return "All";
}
const namesInEnglish = new Intl.DisplayNames(["en"], { type: "language" });
const namesInNative = new Intl.DisplayNames([code], { type: "language" });
return `${namesInEnglish.of(code)} - ${namesInNative.of(code)}`;
return `${capitalize(namesInEnglish.of(code)!, "en")} - ${capitalize(namesInNative.of(code)!, code)}`;
}
function capitalize(string: string, locale: string) {
return string.charAt(0).toLocaleUpperCase(locale) + string.substring(1);
}