feat(i18n): add Russian UI and harden localization

This commit is contained in:
Arthur Koba
2026-10-25 22:35:32 +03:00
parent 65a96670d5
commit b4e94076c9
115 changed files with 7767 additions and 993 deletions
@@ -1,17 +1,29 @@
import { render, screen } from '@testing-library/react';
import { useTranslations } from 'next-intl';
import { useLocale, useTranslations } from 'next-intl';
import { formatDateTime, formatNumber } from '@/i18n/format';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import enMessages from '@/messages/en.json';
import zhCNMessages from '@/messages/zh-CN.json';
import ruMessages from '@/messages/ru.json';
import { AppIntlProvider } from './intl-provider';
import { createLocaleBootstrapScript } from '@/i18n/bootstrap';
function Probe() {
const t = useTranslations('common');
return <button>{t('save')}</button>;
}
function FormattingProbe() {
const locale = useLocale();
return (
<span data-testid='formats'>
{locale}|{formatNumber(1234.5)}|{formatDateTime('2026-01-15T00:00:00Z')}
</span>
);
}
const zhSave = (zhCNMessages.common as Record<string, string>).save;
const enSave = (enMessages.common as Record<string, string>).save;
@@ -31,6 +43,7 @@ describe('AppIntlProvider (static export locale resolution)', () => {
afterEach(() => {
document.cookie = 'NEXT_LOCALE=; Max-Age=0; Path=/';
document.documentElement.removeAttribute('data-locale-pending');
});
it('flips to the NEXT_LOCALE cookie locale after mount when SSR locale is stale', async () => {
@@ -61,6 +74,51 @@ describe('AppIntlProvider (static export locale resolution)', () => {
expect(document.documentElement.lang).toBe('zh-CN');
});
it('applies Russian cookies before showing the hydrated English page', () => {
document.cookie = 'NEXT_LOCALE=ru; Path=/';
new Function(createLocaleBootstrapScript('en'))();
expect(document.documentElement.hasAttribute('data-locale-pending')).toBe(
true,
);
render(
<AppIntlProvider locale='en' messages={enMessages}>
<Probe />
</AppIntlProvider>,
);
expect(screen.getByText(ruMessages.common.save)).toBeInTheDocument();
expect(document.documentElement.lang).toBe('ru');
expect(document.documentElement.hasAttribute('data-locale-pending')).toBe(
false,
);
});
it('recognizes Russian browser variants when there is no preference', () => {
Object.defineProperty(navigator, 'languages', {
value: ['ru-RU', 'en-US'],
configurable: true,
});
render(
<AppIntlProvider locale='en' messages={enMessages}>
<Probe />
</AppIntlProvider>,
);
expect(screen.getByText(ruMessages.common.save)).toBeInTheDocument();
expect(document.documentElement.lang).toBe('ru');
});
it('formats existing data in Russian on the first localized render', () => {
document.documentElement.lang = 'en';
document.cookie = 'NEXT_LOCALE=ru; Path=/';
render(
<AppIntlProvider locale='en' messages={enMessages}>
<FormattingProbe />
</AppIntlProvider>,
);
expect(screen.getByTestId('formats').textContent).toBe(
'ru|1\u00a0234,5|15.01.2026, 08:00',
);
});
it('does not flip without a cookie preference', () => {
render(
<AppIntlProvider locale='zh-CN' messages={zhCNMessages}>