Fix error when language code is "startrek_it"

Srsly why…
This commit is contained in:
Lim Chee Aun 2023-06-05 11:40:30 +08:00
parent 618a0d70d2
commit 676fa6fbc9
2 changed files with 9 additions and 4 deletions

View file

@ -114,7 +114,7 @@ function TranslationBlock({
<span>
{uiState === 'loading'
? 'Translating…'
: sourceLanguage && !detectedLang
: sourceLanguage && sourceLangText && !detectedLang
? `Translate from ${sourceLangText}`
: `Translate`}
</span>

View file

@ -1,5 +1,10 @@
export default function localeCode2Text(code) {
return new Intl.DisplayNames(navigator.languages, {
type: 'language',
}).of(code);
try {
return new Intl.DisplayNames(navigator.languages, {
type: 'language',
}).of(code);
} catch (e) {
console.error(e);
return null;
}
}