mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-26 22:56:23 -04:00
@@ -0,0 +1,41 @@
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
|
||||
interface LanguageResponse {
|
||||
identifier: string;
|
||||
}
|
||||
|
||||
function getLanguage() {
|
||||
return createAjaxRequest({
|
||||
global: false,
|
||||
dataType: 'json',
|
||||
url: '/localization/language',
|
||||
}).request;
|
||||
}
|
||||
|
||||
function getDisplayName(code: string) {
|
||||
return Intl.DisplayNames
|
||||
? new Intl.DisplayNames([code], { type: 'language' })
|
||||
: null;
|
||||
}
|
||||
|
||||
let languageNames = getDisplayName('en');
|
||||
|
||||
getLanguage().then((data: LanguageResponse) => {
|
||||
const names = getDisplayName(data.identifier);
|
||||
|
||||
if (names) {
|
||||
languageNames = names;
|
||||
}
|
||||
});
|
||||
|
||||
export default function getLanguageName(code: string) {
|
||||
if (!languageNames) {
|
||||
return code;
|
||||
}
|
||||
|
||||
try {
|
||||
return languageNames.of(code) ?? code;
|
||||
} catch (error) {
|
||||
return code;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user