From 9c79bf2198ef27f29fc8f1f84a78f2f33bd7e7be Mon Sep 17 00:00:00 2001 From: plebeius Date: Sun, 8 Mar 2026 21:09:22 +0800 Subject: [PATCH] fix(i18n): default interface language to english --- .../__tests__/interface-settings.test.tsx | 2 + .../interface-settings/interface-settings.tsx | 10 ++-- src/lib/__tests__/init-translations.test.ts | 8 +++- src/lib/constants.ts | 44 ++++++++++++++++++ src/lib/init-translations.ts | 46 ++++--------------- 5 files changed, 66 insertions(+), 44 deletions(-) diff --git a/src/components/settings-modal/interface-settings/__tests__/interface-settings.test.tsx b/src/components/settings-modal/interface-settings/__tests__/interface-settings.test.tsx index 2ce612bd..ed266f8c 100644 --- a/src/components/settings-modal/interface-settings/__tests__/interface-settings.test.tsx +++ b/src/components/settings-modal/interface-settings/__tests__/interface-settings.test.tsx @@ -6,6 +6,7 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import packageJson from '../../../../../package.json'; import InterfaceSettings from '../interface-settings'; import useFeedViewSettingsStore from '../../../../stores/use-feed-view-settings-store'; +import { INTERFACE_LANGUAGE_STORAGE_KEY } from '../../../../lib/constants'; (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true; const act = (React as { act?: (cb: () => void | Promise) => void | Promise }).act as (cb: () => void | Promise) => void | Promise; @@ -155,6 +156,7 @@ describe('InterfaceSettings', () => { }); expect(testState.changeLanguageMock).toHaveBeenCalledWith('fr'); + expect(localStorage.getItem(INTERFACE_LANGUAGE_STORAGE_KEY)).toBe('fr'); }); it('disables the update button while fetching and restores it afterward', async () => { diff --git a/src/components/settings-modal/interface-settings/interface-settings.tsx b/src/components/settings-modal/interface-settings/interface-settings.tsx index 43022e4d..d8c5393c 100644 --- a/src/components/settings-modal/interface-settings/interface-settings.tsx +++ b/src/components/settings-modal/interface-settings/interface-settings.tsx @@ -6,6 +6,7 @@ import capitalize from 'lodash/capitalize'; import useExpandedMediaStore from '../../../stores/use-expanded-media-store'; import useFeedViewSettingsStore from '../../../stores/use-feed-view-settings-store'; import Version from '../../version'; +import { INTERFACE_LANGUAGE_STORAGE_KEY, SUPPORTED_INTERFACE_LANGUAGES } from '../../../lib/constants'; const commitRef = process.env.VITE_COMMIT_REF; const isElectron = window.electronApi?.isElectron === true; @@ -67,21 +68,20 @@ const CheckForUpdates = () => { ); }; -// prettier-ignore -const availableLanguages = ['ar', 'bn', 'cs', 'da', 'de', 'el', 'en', 'es', 'fa', 'fi', 'fil', 'fr', 'he', 'hi', 'hu', 'id', 'it', 'ja', 'ko', 'mr', 'nl', 'no', 'pl', 'pt', 'ro', 'ru', 'sq', 'sv', 'te', 'th', 'tr', 'uk', 'ur', 'vi', 'zh']; - const InterfaceLanguage = () => { const { i18n } = useTranslation(); const { changeLanguage, language } = i18n; const onSelectLanguage = (e: React.ChangeEvent) => { - changeLanguage(e.target.value); + const selectedLanguage = e.target.value; + localStorage.setItem(INTERFACE_LANGUAGE_STORAGE_KEY, selectedLanguage); + changeLanguage(selectedLanguage); }; return (