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> <span>
{uiState === 'loading' {uiState === 'loading'
? 'Translating…' ? 'Translating…'
: sourceLanguage && !detectedLang : sourceLanguage && sourceLangText && !detectedLang
? `Translate from ${sourceLangText}` ? `Translate from ${sourceLangText}`
: `Translate`} : `Translate`}
</span> </span>

View file

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