From 18b3ee8c92f4b1af82496c0215995c886b2141cb Mon Sep 17 00:00:00 2001 From: Lim Chee Aun Date: Fri, 16 Aug 2024 19:17:57 +0800 Subject: [PATCH] Standardize display of common + native languages list --- src/components/compose.jsx | 8 +-- src/components/lang-selector.jsx | 36 ++++++++--- src/components/translation-block.jsx | 33 ++++++---- src/locales/en.po | 92 ++++++++++++++-------------- src/pages/settings.jsx | 15 +++-- 5 files changed, 109 insertions(+), 75 deletions(-) diff --git a/src/components/compose.jsx b/src/components/compose.jsx index ba5ad7c4..17d4c43b 100644 --- a/src/components/compose.jsx +++ b/src/components/compose.jsx @@ -1439,10 +1439,10 @@ function Compose({ code, fallback: common, }); - const same = commonText === native; + const showCommon = commonText !== native; return ( ); })} @@ -1452,10 +1452,10 @@ function Compose({ code, fallback: common, }); - const same = commonText === native; + const showCommon = commonText !== native; return ( ); })} diff --git a/src/components/lang-selector.jsx b/src/components/lang-selector.jsx index 801e4962..e0ab202a 100644 --- a/src/components/lang-selector.jsx +++ b/src/components/lang-selector.jsx @@ -1,4 +1,5 @@ import { useLingui } from '@lingui/react'; +import { useMemo } from 'preact/hooks'; import { DEFAULT_LANG, LOCALES } from '../locales'; import { activateLang } from '../utils/lang'; @@ -7,6 +8,28 @@ import localeCode2Text from '../utils/localeCode2Text'; export default function LangSelector() { const { i18n } = useLingui(); + const populatedLocales = useMemo(() => { + return LOCALES.map((lang) => { + const native = localeCode2Text({ code: lang, locale: lang }); + const common = localeCode2Text(lang); + const showCommon = !!common && common !== native; + return { + code: lang, + native, + common, + showCommon, + }; + }).sort((a, b) => { + // If pseudo-LOCALE, always put it at the bottom + if (a.code === 'pseudo-LOCALE') return 1; + if (b.code === 'pseudo-LOCALE') return -1; + // Sort by code + if (a.code < b.code) return -1; + if (a.code > b.code) return 1; + return 0; + }); + }, [i18n.locale]); + return (