Dawnline 0.11.0
Build packages / CI (push) Blocked by required conditions
Build packages / Version (push) Waiting to run
CI / Web (format, types, tests, bundles) (push) Blocked by required conditions
CI / ShellCheck (push) Blocked by required conditions
CI / ucode static checks (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 24.10) (push) Blocked by required conditions
CI / ucode compiles and tests pass (OpenWrt 25.12) (push) Blocked by required conditions

- Russian translation. The admin pages, the LuCI menu and the router's
  messages (errors, Health checks, update steps, the service log) come in
  Russian with the new luci-i18n-dawnline-ru package, released beside the
  app. LuCI shows it when its language is Russian, or "auto" with a Russian
  browser
- The translation installs with install.sh when LuCI is in Russian (or with
  --lang ru), follows every Dawnline update and rollback, and can be added
  or removed in Components → Dawnline → Translation
- The portal speaks the visitor's language: it opens in the system's
  language and switches between English and Russian in place, from the
  language pill beside its QR code. It carries its own translation and needs
  no package
- Set-up steps quote the apps' own menus word for word, in Russian too:
  AmneziaVPN is "+ → Insert → Continue" (it has no "Add server"), and the
  Mac and Windows menus of WireGuard and AmneziaWG have their real names
- Questions in the portal (Reconnect, Remove) read from the left edge and
  close with Cancel, without ×
- Numbers, sizes and dates follow the page's language. A server that can't
  start says why in one sentence; event details and service log lines read
  as whole sentences
- README in Russian (README_ru.md). rules/i18n.md: how strings are written
  and translated; CI checks the catalogs (npm run i18n:check)
This commit is contained in:
Aemeath committed 2026-10-20 19:33:52 +03:00
1 parent caed976e63
commit 2f2aaf6c34
173 files changed
+25645 -2823

No files matched your search

+100
View File
@@ -0,0 +1,100 @@
// The portal's languages: English (the code's) and the translations bundled
// with it (i18n/<lang>.po, turned into lookup tables at build time). The page
// opens in the visitor's own choice, kept in this browser, or else in the
// first of the browser's (the system's) languages it has; the language menu in
// the breadcrumb switches it in place. This module installs the globals _()
// and N_() that the page and the shared code call (shared/i18n.ts), so it is
// imported before anything that draws.
import type { Catalog } from '../../i18n/po';
import ru from './i18n/ru.po';
export interface Lang {
code: string;
/** In its own language: what the menu lists. */
name: string;
}
export const LANGS: Lang[] = [
{ code: 'en', name: 'English' },
{ code: 'ru', name: 'Русский' },
];
const catalogs: Record<string, Catalog[]> = { ru: [ru] };
/** Which plural form n takes (the index into the .po's msgstr[n]), by each language's gettext rule. */
const FORMS: Record<string, (n: number) => number> = {
en: (n) => (n !== 1 ? 1 : 0),
ru: (n) => (n % 10 === 1 && n % 100 !== 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2),
};
const STORE = 'dl.lang';
/** The language to open in: the visitor's kept choice, else the browser's first we have, else English. */
export function pickLang(kept: string | null, browser: readonly string[]): string {
const have = (c: string | null | undefined) => (c && LANGS.some((l) => l.code === c) ? c : null);
return have(kept) ?? browser.map((b) => have(b.toLowerCase().split(/[-_]/)[0])).find(Boolean) ?? 'en';
}
let current = 'en';
let active: Catalog[] = [];
const listeners: (() => void)[] = [];
const key = (s: string, ctx?: string) => (ctx ? `${ctx}\u0004${s}` : s);
function tr(s: string, ctx?: string): string {
const k = key(s, ctx);
for (const c of active) if (k in c.s) return c.s[k];
return s;
}
function ntr(n: number, s: string, p: string, ctx?: string): string {
const k = key(s, ctx);
const forms = active.find((c) => k in c.p)?.p[k];
return forms?.[(FORMS[current] ?? FORMS.en)(n)] ?? (n === 1 ? s : p);
}
export const lang = () => current;
/**
* A message the router sent: in English when no translation is installed on
* it, so the page translates the ones its catalog has (the backend's
* portal.uc and devices.uc are in it).
*/
export const routerText = (msg: string) => tr(msg);
/** Switch the page's language; `keep`: remember it in this browser (the visitor chose it). */
export function setLang(code: string, keep = true) {
current = LANGS.some((l) => l.code === code) ? code : 'en';
active = catalogs[current] ?? [];
document.documentElement.lang = current;
if (keep)
try {
localStorage.setItem(STORE, current);
} catch {
/* no storage: the choice lasts this visit */
}
listeners.forEach((f) => f());
}
/** Redraw on a language change (main.ts: the page; the demo: its own parts). */
export function onLang(f: () => void) {
listeners.push(f);
}
/** More strings for a language (the demo's own, from its catalog). */
export function addCatalog(code: string, c: Catalog) {
(catalogs[code] ??= []).push(c);
if (code === current) active = catalogs[code];
}
function kept(): string | null {
try {
return localStorage.getItem(STORE);
} catch {
return null;
}
}
Object.assign(globalThis, { _: tr, N_: ntr });
setLang(pickLang(kept(), navigator.languages?.length ? navigator.languages : [navigator.language]), false);