Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(setup): hide the development-only locales from the language list
Elian Doran79d7f3247e1f
diff --git a/apps/client/src/setup.tsx b/apps/client/src/setup.tsxindex e9b5b27625..50edeff939 100644--- a/apps/client/src/setup.tsx+++ b/apps/client/src/setup.tsx@@ -203,7 +203,11 @@ function afterExistingData(glob: SetupGlob): State {function SelectLanguage({ setState }: { setState: (state: State) => void }) {const { t, i18n } = useTranslation();const [ currentLocale, setCurrentLocale ] = useState(i18n.language);- const filteredLocales = useMemo(() => LOCALES.filter(l => !l.contentOnly), []);+ const filteredLocales = useMemo(() => LOCALES.filter(l => {+ if (l.contentOnly) return false;+ if (l.devOnly && !window.glob.isDev) return false;+ return true;+ }), []);// The row the user chose last, which is not the last bundle to arrive: each language is a// 160-290 KB fetch, so two taps in a row are answered in whichever order the two loads finish.const chosen = useRef(currentLocale);diff --git a/apps/client/src/setup_language.spec.tsx b/apps/client/src/setup_language.spec.tsxindex ac9078b1e4..fec3199262 100644--- a/apps/client/src/setup_language.spec.tsx+++ b/apps/client/src/setup_language.spec.tsx@@ -109,6 +109,43 @@ async function tap(name: string) {await flushEffects();}+describe("which languages the list offers", () => {+ function names() {+ return [ ...container.querySelectorAll<HTMLElement>("li.dropdown-item") ]+ .map((element) => element.textContent?.trim());+ }++ async function renderAt(isDev: boolean) {+ (window as any).glob.isDev = isDev;+ render(renderState("selectLanguage", vi.fn()), container);+ await flushEffects();+ }++ afterEach(() => {+ delete (window as any).glob.isDev;+ });++ it("hides the development-only locales outside dev mode", async () => {+ await renderAt(false);++ expect(names()).toContain("English (United States)");+ expect(names()).not.toContain("English RTL");+ });++ it("offers them in dev mode", async () => {+ await renderAt(true);++ expect(names()).toContain("English RTL");+ });++ it("never offers the content-only locales", async () => {+ await renderAt(true);++ // Hebrew is selectable as a note's language but the app is not translated into it.+ expect(names()).not.toContain("עברית");+ });+});+describe("choosing a language while the bundle is still loading", () => {beforeEach(async () => {render(renderState("selectLanguage", vi.fn()), container);