i18n: final sweep, i18n smoke and evidence, docs/i18n.md
ci / linux-arm64-cross (push) Successful in 3m51s
ci / linux-x64 (push) Successful in 4m22s

This commit is contained in:
omar committed 2026-10-24 06:40:15 +03:00
1 parent 0fffb27166
commit 5f5d30d3ed
28 files changed
+247 -5

No files matched your search

+156
View File
@@ -0,0 +1,156 @@
// Real Electron localization smoke. Uses only a disposable disconnected profile; never captures audio.
// No locale emulation, fake devices, server connections, or changes to the owner's profile.
import { _electron as electron } from 'playwright-core';
import assert from 'node:assert/strict';
import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
import { tmpdir } from 'node:os';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { createRequire } from 'node:module';
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const executablePath = createRequire(import.meta.url)('electron');
const outArg = process.argv.indexOf('--out');
const out = path.resolve(root, outArg >= 0 ? process.argv[outArg + 1] : 'smoke-out/i18n');
const profile = mkdtempSync(path.join(tmpdir(), 'teamspeach-i18n-'));
mkdirSync(out, { recursive: true });
const errors = [];
const steps = [];
let app;
let page;
let failed;
const record = (name, details = {}) => { steps.push({ name, ...details }); console.log(`[i18n] ${name}`, JSON.stringify(details)); };
const prefs = () => JSON.parse(readFileSync(path.join(profile, 'prefs.json'), 'utf8'));
const withoutLanguage = ({ language, ...rest }) => rest;
const state = () => page.evaluate(() => window.teamspeachDiagnostics.snapshot());
async function launch() {
app = await electron.launch({ executablePath, args: [root], env: { ...process.env, TEAMSPEACH_PROFILE_DIR: profile }, colorScheme: null });
page = await app.firstWindow();
page.on('pageerror', (error) => errors.push(error.message));
await page.setViewportSize({ width: 1280, height: 800 });
await page.waitForFunction(() => window.teamspeachDiagnostics);
}
async function checkBindings(language) {
const problems = await page.evaluate(async (locale) => {
const { t, getLanguage } = await import('./js/i18n.js');
const issues = [];
if (document.documentElement.lang !== locale || getLanguage() !== locale) issues.push('wrong active locale');
for (const el of document.querySelectorAll('[data-i18n]')) if (el.textContent !== t(el.dataset.i18n)) issues.push(el.id || el.dataset.i18n);
for (const attr of ['title', 'aria-label', 'placeholder']) {
for (const el of document.querySelectorAll(`[data-i18n-${attr}]`)) {
// Dynamic mute/stream controls intentionally override their initial label.
if (['btn-mute', 'btn-deafen', 'stream-mute', 'chat-input'].includes(el.id)) continue;
if (el.getAttribute(attr) !== t(el.getAttribute(`data-i18n-${attr}`))) issues.push(`${el.id}:${attr}`);
}
}
return issues;
}, language);
assert.deepEqual(problems, []);
}
async function categories(language) {
await page.evaluate(() => document.querySelectorAll('.toast .icon-btn').forEach((button) => button.click()));
for (const panel of ['identity', 'servers', 'appearance', 'audio', 'video', 'keys', 'about']) {
await page.click(`#settings-nav [data-panel="${panel}"]`);
await page.waitForFunction(() => !document.querySelector('#language-select').disabled);
if (panel === 'audio') await page.waitForFunction(() => document.querySelector('#input-device').options.length > 0);
if (panel === 'about') await page.waitForFunction(() => document.querySelector('#diag-list').children.length > 0);
await checkBindings(language);
if (['appearance', 'audio', 'about'].includes(panel)) {
await page.screenshot({ path: path.join(out, `${language}-${panel}-1280.png`) });
await page.setViewportSize({ width: 880, height: 560 });
await page.screenshot({ path: path.join(out, `${language}-${panel}-880.png`) });
const overflow = await page.evaluate(() => document.documentElement.scrollWidth > innerWidth || document.body.scrollWidth > innerWidth);
assert.equal(overflow, false, `${language}/${panel} horizontal overflow`);
if (panel === 'about') {
await page.locator('#update-status').scrollIntoViewIfNeeded();
await page.screenshot({ path: path.join(out, `${language}-updates-880.png`) });
}
await page.setViewportSize({ width: 1280, height: 800 });
}
}
for (const control of ['btn-mute', 'btn-deafen']) {
await page.click(`#${control}`, { button: 'right' });
await page.waitForSelector('.device-menu:not([aria-busy])');
const actual = await page.locator('.device-menu [role="menuitemradio"]').count();
assert.ok(actual > 0);
await page.evaluate(async (kind) => {
const { t } = await import('./js/i18n.js');
const menu = document.querySelector('.device-menu');
if (menu.getAttribute('aria-label') !== t(kind === 'btn-mute' ? 'ui.microphone' : 'ui.output.device')) throw new Error('Device menu title not localized');
if (menu.querySelector('.menu-item-secondary .menu-label').textContent !== t('ui.audio.settings')) throw new Error('Device menu action not localized');
}, control);
await page.screenshot({ path: path.join(out, `${language}-${control}-menu.png`) });
await page.keyboard.press('Escape');
}
record('all categories and device menus', { language });
}
async function switchTo(language) {
await page.click('#settings-nav [data-panel="appearance"]');
await page.selectOption('#language-select', language);
await page.waitForFunction((value) => document.documentElement.lang === value && !document.querySelector('#language-select').disabled, language);
assert.equal(prefs().language, language);
}
try {
await launch();
await page.waitForSelector('#view-onboarding', { state: 'visible', timeout: 20000 });
assert.equal(await page.locator('html').getAttribute('lang'), 'en');
await checkBindings('en');
await page.screenshot({ path: path.join(out, 'en-onboarding.png') });
await page.fill('#onboarding-nick', 'LocaleSmoke');
await page.click('#onboarding-submit');
await page.waitForSelector('#view-app', { state: 'visible' });
await page.screenshot({ path: path.join(out, 'en-connect.png') });
const before = await state();
assert.equal(before.conn, 'disconnected');
assert.equal(before.voice.capturing, false);
const originalPrefs = await page.evaluate(() => window.teamspeach.getPrefs());
await page.fill('#connect-address', 'example.invalid:9987');
await page.click('#btn-settings');
await categories('en');
// A visible application-owned toast must reformat without being re-created.
await page.evaluate(async () => {
const { toast } = await import('./js/toast.js');
const { t } = await import('./js/i18n.js');
toast(() => t('ui.uid.copied'));
});
await switchTo('ru');
const after = await state();
assert.deepEqual(after.profile, before.profile);
assert.equal(after.conn, before.conn);
assert.equal(after.voice.capturing, false);
assert.deepEqual(after.audio, before.audio);
assert.deepEqual(withoutLanguage(await page.evaluate(() => window.teamspeach.getPrefs())), withoutLanguage(originalPrefs));
assert.equal(await page.inputValue('#connect-address'), 'example.invalid:9987');
await page.evaluate(async () => {
const { t } = await import('./js/i18n.js');
const message = [...document.querySelectorAll('.toast-text')].at(-1);
if (!message || message.textContent !== t('ui.uid.copied')) throw new Error('Existing toast did not switch language');
});
await categories('ru');
await page.click('#settings-back');
await page.screenshot({ path: path.join(out, 'ru-connect.png') });
await app.close();
app = null;
await launch();
await page.waitForSelector('#view-app', { state: 'visible', timeout: 20000 });
assert.equal(await page.locator('html').getAttribute('lang'), 'ru');
assert.deepEqual((await state()).profile, before.profile);
record('restart retains Russian and identity');
await page.click('#btn-settings');
await switchTo('en');
await checkBindings('en');
assert.equal((await state()).voice.capturing, false);
assert.deepEqual((await state()).profile, before.profile);
assert.deepEqual(errors, []);
record('switch back to English preserves disconnected state');
} catch (error) {
failed = error;
record('FAILED', { error: error.stack || String(error), pageErrors: errors });
} finally {
if (app) await app.close().catch(() => {});
rmSync(profile, { recursive: true, force: true });
writeFileSync(path.join(out, 'result.json'), JSON.stringify({ ok: !failed, steps, pageErrors: errors }, null, 2));
}
process.exitCode = failed ? 1 : 0;