feat(i18n): add Russian locale and enable 'ru' language; translate core keys to Russian

This commit is contained in:
Chebotov Nickolay
2026-02-06 11:26:32 +03:00
parent 26fa1ea98e
commit ad1387d076
4 changed files with 1123 additions and 5 deletions

View File

@@ -6,12 +6,14 @@ import i18n from 'i18next';
import { initReactI18next } from 'react-i18next'; import { initReactI18next } from 'react-i18next';
import zhCN from './locales/zh-CN.json'; import zhCN from './locales/zh-CN.json';
import en from './locales/en.json'; import en from './locales/en.json';
import ru from './locales/ru.json';
import { getInitialLanguage } from '@/utils/language'; import { getInitialLanguage } from '@/utils/language';
i18n.use(initReactI18next).init({ i18n.use(initReactI18next).init({
resources: { resources: {
'zh-CN': { translation: zhCN }, 'zh-CN': { translation: zhCN },
en: { translation: en } en: { translation: en },
ru: { translation: ru }
}, },
lng: getInitialLanguage(), lng: getInitialLanguage(),
fallbackLng: 'zh-CN', fallbackLng: 'zh-CN',

1113
src/i18n/locales/ru.json Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,7 @@
export type Theme = 'light' | 'dark' | 'auto'; export type Theme = 'light' | 'dark' | 'auto';
export type Language = 'zh-CN' | 'en'; export type Language = 'zh-CN' | 'en' | 'ru';
export type NotificationType = 'info' | 'success' | 'warning' | 'error'; export type NotificationType = 'info' | 'success' | 'warning' | 'error';

View File

@@ -5,11 +5,11 @@ const parseStoredLanguage = (value: string): Language | null => {
try { try {
const parsed = JSON.parse(value); const parsed = JSON.parse(value);
const candidate = parsed?.state?.language ?? parsed?.language ?? parsed; const candidate = parsed?.state?.language ?? parsed?.language ?? parsed;
if (candidate === 'zh-CN' || candidate === 'en') { if (candidate === 'zh-CN' || candidate === 'en' || candidate === 'ru') {
return candidate; return candidate;
} }
} catch { } catch {
if (value === 'zh-CN' || value === 'en') { if (value === 'zh-CN' || value === 'en' || value === 'ru') {
return value; return value;
} }
} }
@@ -36,7 +36,10 @@ const getBrowserLanguage = (): Language => {
return 'zh-CN'; return 'zh-CN';
} }
const raw = navigator.languages?.[0] || navigator.language || 'zh-CN'; const raw = navigator.languages?.[0] || navigator.language || 'zh-CN';
return raw.toLowerCase().startsWith('zh') ? 'zh-CN' : 'en'; const lower = raw.toLowerCase();
if (lower.startsWith('zh')) return 'zh-CN';
if (lower.startsWith('ru')) return 'ru';
return 'en';
}; };
export const getInitialLanguage = (): Language => getStoredLanguage() ?? getBrowserLanguage(); export const getInitialLanguage = (): Language => getStoredLanguage() ?? getBrowserLanguage();