mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-24 09:46:36 +00:00
Add support for native names for other languages than HA has (#16393)
* Add support for native names for other languages than HA has * catch unsupported locales
This commit is contained in:
parent
4a0d84d2f6
commit
fc97ca324c
@ -68,10 +68,24 @@ export class HaLanguagePicker extends LitElement {
|
||||
|
||||
if (nativeName) {
|
||||
const translations = this.hass.translationMetadata.translations;
|
||||
options = languages.map((lang) => ({
|
||||
value: lang,
|
||||
label: translations[lang]?.nativeName ?? lang,
|
||||
}));
|
||||
options = languages.map((lang) => {
|
||||
let label = translations[lang]?.nativeName;
|
||||
if (!label) {
|
||||
try {
|
||||
// this will not work if Intl.DisplayNames is polyfilled, it will return in the language of the user
|
||||
label = new Intl.DisplayNames(lang, {
|
||||
type: "language",
|
||||
fallback: "code",
|
||||
}).of(lang)!;
|
||||
} catch (err) {
|
||||
label = lang;
|
||||
}
|
||||
}
|
||||
return {
|
||||
value: lang,
|
||||
label,
|
||||
};
|
||||
});
|
||||
} else {
|
||||
options = languages.map((lang) => ({
|
||||
value: lang,
|
||||
|
Loading…
x
Reference in New Issue
Block a user