fix(i18n): default interface language to english

This commit is contained in:
plebeius
2026-03-08 21:09:22 +08:00
parent fabdd0efe5
commit 9c79bf2198
5 changed files with 66 additions and 44 deletions
+7 -1
View File
@@ -1,4 +1,5 @@
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { DEFAULT_INTERFACE_LANGUAGE, INTERFACE_LANGUAGE_STORAGE_KEY } from '../constants';
const testState = vi.hoisted(() => {
const i18next = {
@@ -47,10 +48,15 @@ describe('init-translations', () => {
expect(testState.i18next.use).toHaveBeenNthCalledWith(3, testState.reactPlugin);
expect(testState.i18next.init).toHaveBeenCalledWith(
expect.objectContaining({
fallbackLng: 'en',
fallbackLng: DEFAULT_INTERFACE_LANGUAGE,
ns: ['default'],
defaultNS: 'default',
backend: { loadPath: './translations/{{lng}}/{{ns}}.json' },
detection: {
order: ['localStorage'],
caches: ['localStorage'],
lookupLocalStorage: INTERFACE_LANGUAGE_STORAGE_KEY,
},
}),
);
expect(testState.i18next.init.mock.calls[0]?.[0]?.supportedLngs).toContain('en');
+44
View File
@@ -6,3 +6,47 @@ export const BOARD_REPLIES_PREVIEW_VISIBLE_COUNT = 5;
/** Number of replies fetched for preview mode on board/listing views. */
export const BOARD_REPLIES_PREVIEW_FETCH_SIZE = 25;
/** 5chan ships in English by default; users must opt into other languages manually. */
export const DEFAULT_INTERFACE_LANGUAGE = 'en';
/** Persist only deliberate in-app language selections, never OS/browser auto-detection. */
export const INTERFACE_LANGUAGE_STORAGE_KEY = '5chan-interface-language';
export const SUPPORTED_INTERFACE_LANGUAGES = [
'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',
] as const;
+8 -38
View File
@@ -2,6 +2,7 @@ import i18next from 'i18next';
import HttpBackend from 'i18next-http-backend';
import LanguageDetector from 'i18next-browser-languagedetector';
import { initReactI18next } from 'react-i18next';
import { DEFAULT_INTERFACE_LANGUAGE, INTERFACE_LANGUAGE_STORAGE_KEY, SUPPORTED_INTERFACE_LANGUAGES } from './constants';
const loadPath = `./translations/{{lng}}/{{ns}}.json`;
@@ -10,44 +11,13 @@ i18next
.use(LanguageDetector)
.use(initReactI18next)
.init({
fallbackLng: 'en',
supportedLngs: [
'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',
],
fallbackLng: DEFAULT_INTERFACE_LANGUAGE,
supportedLngs: [...SUPPORTED_INTERFACE_LANGUAGES],
detection: {
order: ['localStorage'],
caches: ['localStorage'],
lookupLocalStorage: INTERFACE_LANGUAGE_STORAGE_KEY,
},
ns: ['default'],
defaultNS: 'default',