From 676fa6fbc94764aefed59f8ef96c51516b80e918 Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Mon, 5 Jun 2023 11:40:30 +0800 Subject: [PATCH] Fix error when language code is "startrek_it" MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Srsly why… --- src/components/translation-block.jsx | 2 +- src/utils/localeCode2Text.jsx | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/components/translation-block.jsx b/src/components/translation-block.jsx index 5183af03..4512b689 100644 --- a/src/components/translation-block.jsx +++ b/src/components/translation-block.jsx @@ -114,7 +114,7 @@ function TranslationBlock({ {uiState === 'loading' ? 'Translating…' - : sourceLanguage && !detectedLang + : sourceLanguage && sourceLangText && !detectedLang ? `Translate from ${sourceLangText}` : `Translate`} diff --git a/src/utils/localeCode2Text.jsx b/src/utils/localeCode2Text.jsx index d3a1b970..e9843ace 100644 --- a/src/utils/localeCode2Text.jsx +++ b/src/utils/localeCode2Text.jsx @@ -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; + } }