mirror of
https://github.com/Radarr/Radarr
synced 2025-12-06 16:32:36 +01:00
Fixed: Invalid audio language leading to UI error
(cherry picked from commit 8fbbe21d814ccdeda7727b5fb83f99ea81f5b225)
This commit is contained in:
parent
e50abd276e
commit
f05f25af0c
3 changed files with 42 additions and 28 deletions
|
|
@ -9,7 +9,7 @@ function formatLanguages(languages) {
|
||||||
return null;
|
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) {
|
if (splitLanguages.length > 3) {
|
||||||
return (
|
return (
|
||||||
|
|
|
||||||
|
|
@ -1,27 +0,0 @@
|
||||||
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;
|
|
||||||
}
|
|
||||||
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 a new issue