You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Sonarr/frontend/src/Utilities/String/getLanguageName.js

28 lines
590 B

import createAjaxRequest from 'Utilities/createAjaxRequest';
function getTranslations() {
return createAjaxRequest({
global: false,
dataType: 'json',
url: '/localization/language'
}).request;
}
let languageNames = new Intl.DisplayNames(['en'], { type: 'language' });
getTranslations().then((data) => {
const names = new Intl.DisplayNames([data.identifier], { type: 'language' });
if (names) {
languageNames = names;
}
});
export default function getLanguageName(code) {
if (!languageNames) {
return code;
}
return languageNames.of(code) ?? code;
}