Локализовать интерфейс SHiNE на русский и английский

This commit is contained in:
AidarKC
2026-11-09 16:45:21 +03:00
parent 526941eb33
commit 405b9a91a7
133 changed files with 12464 additions and 3296 deletions
@@ -0,0 +1,60 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
const ui = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const ru = JSON.parse(fs.readFileSync(path.join(ui, 'js/i18n/locales/ru.json'), 'utf8'));
const source = (name) => fs.readFileSync(path.join(ui, `js/${name}`), 'utf8');
const key = (name) => name.split('.').reduce((value, part) => value?.[part], ru);
test('русский словарь содержит новые блоки аудита диалогов', () => {
const required = [
'dialogs.final.consent.remember_public_history',
'dialogs.final.consent.public_history_warning',
'dialogs.final.chat.delete_contact_confirm',
'dialogs.final.chat.delete_protected_confirm',
'dialogs.final.chat.confirm_clear_history_text',
'dialogs.final.profile.char_limit',
'dialogs.remaining.components.share_sheet.markup.skopirovat_ssylku',
];
for (const name of required) {
assert.ok(typeof key(name) === 'string' && key(name).length, name);
}
assert.match(key('dialogs.final.chat.delete_contact_confirm'), /\{name\}/);
});
test('окно «Поделиться»: функция t не перекрыта локальной переменной', () => {
const share = source('components/share-sheet.js');
assert.match(share, /import \{ t \} from '\.\.\/i18n\/index\.js'/);
assert.doesNotMatch(share, /\b(?:const|let|var)\s+t\s*=/);
assert.match(share, /previewText\.textContent\s*=\s*text/);
assert.match(share, /t\('dialogs\.remaining\.components\.share_sheet\.markup\.skopirovat_ssylku'\)/);
});
test('подпись редактирования канала подставляется, а не показывается как ${t(...)}', () => {
const channel = source('pages/channel-view.js');
assert.match(channel, /title="\$\{t\('dialogs\.modals\.channel_view\.label_001'\)\}"/);
assert.doesNotMatch(channel, /title="\\\$\{t\(/);
});
test('переводы согласий вычисляются при открытии окна, а не при загрузке модуля', () => {
const consent = source('services/public-history-consent.js');
const likes = source('components/like-action-sheet.js');
const profile = source('pages/profile-edit-view.js');
assert.match(consent, /export function getPublicHistoryRememberLabel\(\)/);
assert.match(consent, /label:\s*getPublicHistoryRememberLabel\(\)/);
assert.match(likes, /getPublicHistoryRememberLabel\(\)/);
assert.doesNotMatch(likes, /PUBLIC_HISTORY_REMEMBER_LABEL/);
assert.match(profile, /function shiningSteps\(\)/);
assert.match(profile, /steps:\s*shiningSteps\(\)/);
assert.doesNotMatch(profile, /const SHINING_STEPS/);
});
test('динамические имена в подтверждениях чата экранируются для HTML', () => {
const chat = source('pages/chat-view.js');
assert.equal((chat.match(/function escapeDialogHtml\(/g) || []).length, 1);
assert.match(chat, /escapeDialogHtml\(t\('dialogs\.final\.chat\.delete_contact_confirm'/);
assert.match(chat, /escapeDialogHtml\(t\('dialogs\.final\.chat\.delete_protected_confirm'/);
});