i18n: final sweep, i18n smoke and evidence, docs/i18n.md
This commit is contained in:
1 parent
0fffb27166
commit
5f5d30d3ed
28 files changed
+247
-5
No files matched your search
@@ -0,0 +1,62 @@
|
||||
# Localization
|
||||
|
||||
TeamsPeach defaults to **English**, independently of the operating-system language. Settings → Appearance → Language switches between English and Russian immediately. Only the `language` preference changes; the identity, nickname, theme, bookmarks, connection, push-to-talk state, and audio/video sessions are not replaced or restarted. The preference is validated and persisted by the existing main-process preferences service.
|
||||
|
||||
## Files and boundaries
|
||||
|
||||
- `app/renderer/shared/en.js`: English source catalog.
|
||||
- `app/renderer/shared/ru.js`: Russian catalog; the only authored source file containing Russian wording.
|
||||
- `app/renderer/shared/i18n.js`: browser/CommonJS formatter, explicit language normalization, cached `Intl.PluralRules` and `Intl.NumberFormat` instances.
|
||||
- `app/renderer/js/i18n.js`: renderer adapter, active language, static DOM translation, and change subscriptions.
|
||||
- `app/main/prefs.js`: persistence and the `en | ru` preference contract.
|
||||
|
||||
The main process requires the shared formatter directly. Renderer modules import the same catalogs and formatter from the existing `app://teamspeach` renderer directory. There is no translation service, runtime fetch, dependency, framework, IPC translation endpoint, protocol path expansion, or CSP exception.
|
||||
|
||||
The application stays plain JavaScript/HTML/CSS. React-specific composition and performance guidance was reviewed as requested; it does not justify adding React to this application. Locale presentation is separated from the core, capture engine, stream session, and persisted application state.
|
||||
|
||||
## Using messages
|
||||
|
||||
Main process:
|
||||
|
||||
```js
|
||||
const { t } = require('../renderer/shared/i18n.js');
|
||||
const title = t('native.identityImport.title', {}, prefs.get().language);
|
||||
```
|
||||
|
||||
Renderer:
|
||||
|
||||
```js
|
||||
import { t, onLanguageChange } from './i18n.js';
|
||||
setText(status, () => t('members.count', { count }));
|
||||
toast(() => t('ui.uid.copied'));
|
||||
```
|
||||
|
||||
Use complete messages with named placeholders rather than interpolating translated fragments where grammar differs. Numbers use the selected language's number formatter; plural messages supply language-specific categories plus `other`. Values such as version strings, UIDs, device IDs, URLs, and user text remain strings and are not reformatted.
|
||||
|
||||
Unknown keys and missing placeholder parameters throw programming errors rather than silently showing untranslated keys or substituting invented fallback wording. Optional technical parameters must be supplied explicitly, for example `detail: ''` or `file: null`. Both catalogs must have identical keys and placeholder sets; their plural categories may differ.
|
||||
|
||||
Static markup uses `data-i18n`, `data-i18n-title`, `data-i18n-aria-label`, and `data-i18n-placeholder`. Its initial English text permits an English first frame before preferences load. Do not put `data-i18n` on a container containing icons or input controls: key the text span instead. Translate through `textContent`/attributes only, never HTML.
|
||||
|
||||
`setText(element, render)` and `toast(render)` retain a presentation callback. The DOM helper stores callbacks in a `WeakMap` and only revisits attached marked nodes on a language change. A dynamic text binding supersedes an initial static text key. Device enumeration, tree labels, chat tabs/timestamps, settings diagnostics, and the update UI refresh their presentation without issuing connection or capture commands. Saved-server edit forms are not rebuilt by a locale change, preserving unsaved input.
|
||||
|
||||
Language changes never translate server names, channel names, nicknames, device-provided names, chat content, media, or server descriptions. App-created chat notices are callbacks; incoming messages remain plain text. Error explanations are selected by machine code. Server, operating-system, and backend diagnostic details remain visible verbatim after the localized explanation; unknown codes are not disguised as a successful or empty result. Main-process logs and technical error messages stay English. Native file and confirmation dialog titles, file filters, descriptions, and custom buttons use the current saved preference; operating-system-owned dialog controls follow the OS.
|
||||
|
||||
## Adding a language
|
||||
|
||||
1. Create a dedicated catalog beside `en.js`, preserving every key and placeholder.
|
||||
2. Add its locale to the shared language list, formatter instances, renderer imports, validated preference enum, and Appearance selector.
|
||||
3. Supply appropriate plural categories using `Intl.PluralRules`; do not copy English plural suffix rules.
|
||||
4. Keep application-owned source, comments, tests, logs, and documentation English. Localized wording belongs only in catalogs. Preserve genuine external Unicode data exactly.
|
||||
5. Add behavioral coverage and exercise a disposable profile in the real Electron app, including persistence, all categories, device context menus, tooltips, error presentation, and minimum-window screenshots.
|
||||
|
||||
## Verification
|
||||
|
||||
`node --test test/i18n.test.mjs test/devices.test.mjs test/prefs.test.js` checks catalog parity/formatting, missing-key and missing-parameter failures, English default, English/Russian plural categories (including 1/2/5/11/21 and fractions), raw-content preservation, dynamic error/key labels, device IDs, and persisted preferences.
|
||||
|
||||
`node scripts/smoke-i18n.mjs --out <evidence-directory>` launches the actual Electron executable without a forced locale. It creates and deletes a disposable profile, remains disconnected, enumerates actual devices without requesting microphone capture, visits all settings categories and input/output context menus, switches languages live, restarts to prove persistence, and switches back to English. Screenshots cover the same Appearance, Audio, and Information surfaces at 1280×800 and 880×560, plus onboarding, connection, and device menus. The script checks catalog-backed DOM labels and attributes rather than brittle full-wording snapshots. It compares UID/nickname, connection/audio state, unchanged preferences, and the connection-form draft across the switch.
|
||||
|
||||
The isolated smoke does not establish live-server call or active-stream continuity; it proves the disconnected lifecycle and presentation changes without touching an owner's running client. Session and capture code paths are deliberately not called by locale selection.
|
||||
|
||||
### Recorded development run, 2026-10-24
|
||||
|
||||
The targeted command above passed **14/14 tests**. The real Electron smoke passed with no renderer page errors on Electron 44.9.3 / Windows x64: fresh-profile English, all seven categories and both actual-device context menus in both languages, live notification translation, Russian persistence after restart, and switching back to English. Capture remained off, the UID/nickname and unrelated preferences stayed unchanged, and the connection-form draft survived. No horizontal document overflow was detected at 880×560. The generated result and matching English/Russian screenshots are under `docs/evidence/runtime/i18n-2026-10-24/`; the temporary profile was deleted. Screenshots show disposable smoke identity data and real OS-provided device labels, not an owner's identity or server data.
|
||||
Reference in new issue
Block a user