mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-25 18:26:35 +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) {
|
if (nativeName) {
|
||||||
const translations = this.hass.translationMetadata.translations;
|
const translations = this.hass.translationMetadata.translations;
|
||||||
options = languages.map((lang) => ({
|
options = languages.map((lang) => {
|
||||||
value: lang,
|
let label = translations[lang]?.nativeName;
|
||||||
label: translations[lang]?.nativeName ?? lang,
|
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 {
|
} else {
|
||||||
options = languages.map((lang) => ({
|
options = languages.map((lang) => ({
|
||||||
value: lang,
|
value: lang,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user