mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-10-30 07:22:35 +01:00
parent
0274778679
commit
8fbbe21d81
@ -9,7 +9,7 @@ function formatLanguages(languages) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const splitLanguages = _.uniq(languages.split('/')).map((l) => getLanguageName(l));
|
||||
const splitLanguages = _.uniq(languages.split('/')).map((l) => getLanguageName(l.split('_')[0]));
|
||||
|
||||
if (splitLanguages.length > 3) {
|
||||
return (
|
||||
|
@ -1,33 +0,0 @@
|
||||
import createAjaxRequest from 'Utilities/createAjaxRequest';
|
||||
|
||||
function getLanguage() {
|
||||
return createAjaxRequest({
|
||||
global: false,
|
||||
dataType: 'json',
|
||||
url: '/localization/language'
|
||||
}).request;
|
||||
}
|
||||
|
||||
function getDisplayName(code) {
|
||||
return Intl.DisplayNames ?
|
||||
new Intl.DisplayNames([code], { type: 'language' }) :
|
||||
null;
|
||||
}
|
||||
|
||||
let languageNames = getDisplayName('en');
|
||||
|
||||
getLanguage().then((data) => {
|
||||
const names = getDisplayName(data.identifier);
|
||||
|
||||
if (names) {
|
||||
languageNames = names;
|
||||
}
|
||||
});
|
||||
|
||||
export default function getLanguageName(code) {
|
||||
if (!languageNames) {
|
||||
return code;
|
||||
}
|
||||
|
||||
return languageNames.of(code) ?? code;
|
||||
}
|
41
frontend/src/Utilities/String/getLanguageName.ts
Normal file
41
frontend/src/Utilities/String/getLanguageName.ts
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user