this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Try/catch match because it throws when there's invalid language code

+19 -8
+2 -2
src/components/compose.jsx
··· 1 1 import './compose.css'; 2 2 3 - import { match } from '@formatjs/intl-localematcher'; 4 3 import '@github/text-expander-element'; 5 4 import equal from 'fast-deep-equal'; 6 5 import { forwardRef } from 'preact/compat'; ··· 16 15 import { api } from '../utils/api'; 17 16 import db from '../utils/db'; 18 17 import emojifyText from '../utils/emojify-text'; 18 + import localeMatch from '../utils/locale-match'; 19 19 import openCompose from '../utils/open-compose'; 20 20 import states, { saveStatus } from '../utils/states'; 21 21 import store from '../utils/store'; ··· 85 85 }); 86 86 observer.observe(menu); 87 87 88 - const DEFAULT_LANG = match( 88 + const DEFAULT_LANG = localeMatch( 89 89 [new Intl.DateTimeFormat().resolvedOptions().locale, ...navigator.languages], 90 90 supportedLanguages.map((l) => l[0]), 91 91 'en',
+3 -3
src/components/status.jsx
··· 1 1 import './status.css'; 2 2 3 - import { match } from '@formatjs/intl-localematcher'; 4 3 import '@justinribeiro/lite-youtube'; 5 4 import { 6 5 ControlledMenu, ··· 33 32 import handleContentLinks from '../utils/handle-content-links'; 34 33 import htmlContentLength from '../utils/html-content-length'; 35 34 import isMastodonLinkMaybe from '../utils/isMastodonLinkMaybe'; 35 + import localeMatch from '../utils/locale-match'; 36 36 import niceDateTime from '../utils/nice-date-time'; 37 37 import shortenNumber from '../utils/shorten-number'; 38 38 import showToast from '../utils/show-toast'; ··· 409 409 const differentLanguage = 410 410 language && 411 411 language !== targetLanguage && 412 - !match([language], [targetLanguage]) && 412 + !localeMatch([language], [targetLanguage]) && 413 413 !contentTranslationHideLanguages.find( 414 - (l) => language === l || match([language], [l]), 414 + (l) => language === l || localeMatch([language], [l]), 415 415 ); 416 416 417 417 const menuInstanceRef = useRef();
+2 -3
src/utils/get-translate-target-language.jsx
··· 1 - import { match } from '@formatjs/intl-localematcher'; 2 - 3 1 import translationTargetLanguages from '../data/lingva-target-languages'; 4 2 3 + import localeMatch from './locale-match'; 5 4 import states from './states'; 6 5 7 6 function getTranslateTargetLanguage(fromSettings = false) { ··· 11 10 return contentTranslationTargetLanguage; 12 11 } 13 12 } 14 - return match( 13 + return localeMatch( 15 14 [ 16 15 new Intl.DateTimeFormat().resolvedOptions().locale, 17 16 ...navigator.languages,
+12
src/utils/locale-match.jsx
··· 1 + import { match } from '@formatjs/intl-localematcher'; 2 + 3 + function localeMatch(...args) { 4 + // Wrap in try/catch because localeMatcher throws on invalid locales 5 + try { 6 + return match(...args); 7 + } catch (e) { 8 + return false; 9 + } 10 + } 11 + 12 + export default localeMatch;