Fixed: Invalid audio language leading to UI error

Closes #5702
This commit is contained in:
Mark McDowall 2023-08-19 23:48:05 -07:00
parent 0274778679
commit 8fbbe21d81
3 changed files with 42 additions and 34 deletions

View File

@ -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 (

View File

@ -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;
}

View 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;
}
}