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
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:
1 parent
caed976e63
commit
2f2aaf6c34
173 files changed
+25645
-2823
No files matched your search
@@ -1,7 +1,18 @@
|
||||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import { installFakeDom, text } from './fakedom';
|
||||
import { csvCell, toCsv } from '../src/admin/events/csv';
|
||||
import { categoryOf, eventBy, isProblem } from '../src/admin/events/model';
|
||||
import {
|
||||
adminName,
|
||||
adminSentence,
|
||||
categoryOf,
|
||||
changedText,
|
||||
daysOf,
|
||||
eventBy,
|
||||
isProblem,
|
||||
logText,
|
||||
noteText,
|
||||
reasonText,
|
||||
} from '../src/admin/events/model';
|
||||
import { eventText } from '../src/admin/events/render';
|
||||
import type { LogEvent, Person } from '../src/shared/types';
|
||||
|
||||
@@ -62,3 +73,49 @@ describe('events', () => {
|
||||
).toBe('Device Myata · Phone changed network nas (10.0.0.2) → 5.6.7.8');
|
||||
});
|
||||
});
|
||||
|
||||
describe('the router’s words', () => {
|
||||
it('puts the admin’s own changes into sentences', () => {
|
||||
expect(adminSentence('changed', 'server', 'Home')).toEqual({ text: 'You changed server %s', named: true });
|
||||
expect(adminSentence('cleared', null, 'the service log')).toEqual({ text: 'You cleared the service log', named: false });
|
||||
expect(adminSentence('reset traffic history', null, 'for Anna')).toEqual({ text: 'You reset traffic history for %s', named: true });
|
||||
expect(adminName('reset traffic history', 'for Anna')).toBe('Anna');
|
||||
expect(adminSentence('frobnicated', 'gizmo', 'x')).toBeNull();
|
||||
});
|
||||
it('reads the notes, the reasons and the days', () => {
|
||||
expect(noteText('port 8443, certificate')).toBe('port 8443, certificate');
|
||||
expect(noteText('3 events · people · older than 7 days')).toBe('3 events · People · older than 7 days');
|
||||
expect(noteText('12 entries older than 30 days')).toBe('12 entries, older than 30 days');
|
||||
expect(noteText('something new')).toBe('something new');
|
||||
expect(reasonText('data limit reached')).toBe('data limit reached');
|
||||
expect(daysOf('3 days')).toBe(3);
|
||||
expect(daysOf('1 day')).toBe(1);
|
||||
expect(daysOf('soon')).toBeNull();
|
||||
expect(changedText('device_limit, moved to Home')).toBe('device limit, moved to Home');
|
||||
});
|
||||
});
|
||||
|
||||
describe('service log lines', () => {
|
||||
it('match their templates, values and older dashes kept', () => {
|
||||
const g = globalThis as unknown as { _: (s: string) => string };
|
||||
const was = g._;
|
||||
// A catalog that brackets what it knows.
|
||||
g._ = (s: string) => `[${s}]`;
|
||||
try {
|
||||
expect(logText('stopped unexpectedly')).toBe('[stopped unexpectedly]');
|
||||
expect(logText('updated · 0.9.0 → 0.10.0')).toBe('[updated · %s → %s]'.replace('%s', '0.9.0').replace('%s', '0.10.0'));
|
||||
expect(logText('are missing — loading them again')).toBe(
|
||||
'[%s - %s]'.replace('%s', '[are missing]').replace('%s', '[loading them again]'),
|
||||
);
|
||||
expect(logText("are missing - not repaired again (3 repairs didn't help)")).toBe(
|
||||
"[%s - not repaired again (%d repairs didn't help)]".replace('%s', '[are missing]').replace('%d', '3'),
|
||||
);
|
||||
expect(logText('updates available · Dawnline 0.11.0, 2 system packages')).toBe(
|
||||
'[updates available · %s]'.replace('%s', 'Dawnline 0.11.0, [%d system packages]'.replace('%d', '2')),
|
||||
);
|
||||
expect(logText('something the page never saw')).toBe('something the page never saw');
|
||||
} finally {
|
||||
g._ = was;
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,18 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
addDays,
|
||||
addMonthsClamped,
|
||||
date,
|
||||
dayDiff,
|
||||
daysLeft,
|
||||
endsIn,
|
||||
endsSoon,
|
||||
fmtDay,
|
||||
kb,
|
||||
plural,
|
||||
shiftDay,
|
||||
todayOf,
|
||||
} from '../src/shared/format';
|
||||
import { addDays, addMonthsClamped, date, dayDiff, daysLeft, endsIn, endsSoon, fmtDay, kb, shiftDay, todayOf } from '../src/shared/format';
|
||||
import { plural } from '../src/shared/i18n';
|
||||
|
||||
describe('months', () => {
|
||||
it('clamps the day to the end of the month', () => {
|
||||
@@ -69,8 +57,8 @@ describe('router days', () => {
|
||||
|
||||
describe('numbers', () => {
|
||||
it('pluralises and sizes', () => {
|
||||
expect(plural(1, 'event')).toBe('1 event');
|
||||
expect(plural(2000, 'address', 'addresses')).toBe('2,000 addresses');
|
||||
expect(plural(1, '%s event', '%s events')).toBe('1 event');
|
||||
expect(plural(2000, '%s address', '%s addresses')).toBe('2,000 addresses');
|
||||
expect(kb(512)).toBe('512 B');
|
||||
expect(kb(1536)).toBe('1.5 KB');
|
||||
expect(kb(3 * 1048576)).toBe('3.0 MB');
|
||||
|
||||
@@ -0,0 +1,147 @@
|
||||
import { beforeAll, describe, expect, it } from 'vitest';
|
||||
import fs from 'node:fs';
|
||||
import { catalogOf, parsePo, pluralForms, writePo, type Po } from '../i18n/po';
|
||||
import { badTranslation, badText } from '../i18n/extract';
|
||||
import { lmo, sfh } from '../i18n/lmo';
|
||||
import { fill, fmt, lang, num, plural } from '../src/shared/i18n';
|
||||
|
||||
describe('po files', () => {
|
||||
const po: Po = {
|
||||
header: [
|
||||
['Language', 'ru'],
|
||||
['Plural-Forms', 'nplurals=3; plural=(n != 1);'],
|
||||
],
|
||||
entries: [
|
||||
{ id: 'Say "hi" \\ there', str: ['Скажи «привет»'], refs: ['web/src/a.ts', 'web/src/b.ts'] },
|
||||
{ ctx: 'state', id: 'Off', str: ['Выкл.'], refs: [] },
|
||||
{ id: '%s day', plural: '%s days', str: ['%s день', '%s дня', '%s дней'], refs: ['web/src/c.ts'] },
|
||||
{ id: 'Untranslated', str: [''], refs: [] },
|
||||
],
|
||||
};
|
||||
|
||||
it('reads back what it writes', () => {
|
||||
const text = writePo(po);
|
||||
expect(text).toContain('msgid "Say \\"hi\\" \\\\ there"');
|
||||
expect(text).toContain('"Plural-Forms: nplurals=3; plural=(n != 1);\\n"');
|
||||
expect(parsePo(text)).toEqual(po);
|
||||
expect(pluralForms(po)).toBe(3);
|
||||
});
|
||||
|
||||
it('joins continued strings and keeps unknown escapes as written', () => {
|
||||
const p = parsePo('msgid ""\nmsgstr ""\n"Language: ru\\n"\n\nmsgid "Long "\n"line"\nmsgstr "Длинная "\n"строка\\n"\n');
|
||||
expect(p.header).toEqual([['Language', 'ru']]);
|
||||
expect(p.entries[0]).toMatchObject({ id: 'Long line', str: ['Длинная строка\\n'] });
|
||||
});
|
||||
|
||||
it('makes a lookup table of the translated entries only', () => {
|
||||
const c = catalogOf(po);
|
||||
expect(c.s).toEqual({ 'Say "hi" \\ there': 'Скажи «привет»', 'state\u0004Off': 'Выкл.' });
|
||||
expect(c.p).toEqual({ '%s day': ['%s день', '%s дня', '%s дней'] });
|
||||
});
|
||||
});
|
||||
|
||||
describe('LMO catalogs', () => {
|
||||
it('match what LuCI’s po2lmo makes, byte for byte', () => {
|
||||
// po2lmo.lmo: the SDK's po2lmo run on po2lmo.po (context, plural forms, Cyrillic, a string left as it is).
|
||||
const po = parsePo(fs.readFileSync(new URL('./i18n/po2lmo.po', import.meta.url), 'utf8'));
|
||||
const want = fs.readFileSync(new URL('./i18n/po2lmo.lmo', import.meta.url));
|
||||
expect(Buffer.from(lmo(po)).equals(want)).toBe(true);
|
||||
});
|
||||
it('hash keys as LuCI looks them up', () => {
|
||||
// cbi.js: sfh("Save") is what the translations endpoint names "Save" by.
|
||||
expect(sfh(new TextEncoder().encode('Save')).toString(16).padStart(8, '0')).toBe('219966c7');
|
||||
});
|
||||
});
|
||||
|
||||
describe('string checks', () => {
|
||||
it('refuses what LuCI could not look up again', () => {
|
||||
expect(badText('Fine text')).toBeNull();
|
||||
expect(badText(' lead')).toMatch(/starts or ends/);
|
||||
expect(badText('two spaces')).toMatch(/two spaces/);
|
||||
expect(badText('a\nb')).toMatch(/newline/);
|
||||
expect(badText('')).toMatch(/empty/);
|
||||
});
|
||||
it('wants the placeholders of the English', () => {
|
||||
expect(badTranslation({ id: '%s of %s', str: ['%s из %s'], refs: [] })).toBeNull();
|
||||
expect(badTranslation({ id: '%s of %s', str: ['%s из'], refs: [] })).toMatch(/placeholders/);
|
||||
expect(badTranslation({ id: '%s day', plural: '%s days', str: ['%s день', '%s дня', 'дней'], refs: [] })).toMatch(/placeholders/);
|
||||
expect(badTranslation({ id: 'Line', str: ['Строка\\n'], refs: [] })).toMatch(/backslash/);
|
||||
expect(badTranslation({ id: 'A — b', str: ['А — б'], refs: [] })).toMatch(/em dash/);
|
||||
expect(badTranslation({ id: 'A — b', str: ['А - б'], refs: [] })).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('formatting', () => {
|
||||
it('fills placeholders in order', () => {
|
||||
expect(fmt('%s of %d', 'a', 3)).toBe('a of 3');
|
||||
expect(fmt('100%% of %s', 'x')).toBe('100% of x');
|
||||
expect(fmt('%s and %s', 'one')).toBe('one and ');
|
||||
});
|
||||
it('puts elements into a sentence', () => {
|
||||
const link = { el: 'a' };
|
||||
expect(fill<unknown>('Install it in %s, then %s.', link, 'come back')).toEqual(['Install it in ', link, ', then ', 'come back', '.']);
|
||||
expect(fill('%s%% done', 5)).toEqual([5, '%', ' done']);
|
||||
});
|
||||
it('speaks English without a page language', () => {
|
||||
expect(lang()).toBe('en');
|
||||
expect(num(2000)).toBe('2,000');
|
||||
expect(num(1.5, 1)).toBe('1.5');
|
||||
expect(plural(1, '%s event', '%s events')).toBe('1 event');
|
||||
});
|
||||
});
|
||||
|
||||
describe('the portal’s languages', () => {
|
||||
let i18n: typeof import('../src/portal/i18n');
|
||||
const store: Record<string, string> = {};
|
||||
|
||||
beforeAll(async () => {
|
||||
Object.assign(globalThis, {
|
||||
document: { documentElement: { lang: '' } },
|
||||
localStorage: { getItem: (k: string) => store[k] ?? null, setItem: (k: string, v: string) => (store[k] = v) },
|
||||
});
|
||||
i18n = await import('../src/portal/i18n');
|
||||
});
|
||||
|
||||
it('opens in the kept choice, else the browser’s first language it has', () => {
|
||||
expect(i18n.pickLang(null, ['ru-RU', 'en-US'])).toBe('ru');
|
||||
expect(i18n.pickLang(null, ['de-DE', 'ru'])).toBe('ru');
|
||||
expect(i18n.pickLang(null, ['de-DE', 'fr'])).toBe('en');
|
||||
expect(i18n.pickLang('en', ['ru-RU'])).toBe('en');
|
||||
expect(i18n.pickLang('xx', ['ru-RU'])).toBe('ru');
|
||||
});
|
||||
|
||||
it('switches the page and keeps the choice', () => {
|
||||
i18n.addCatalog('ru', { s: { Hello: 'Привет' }, p: { '%s device': ['%s устройство', '%s устройства', '%s устройств'] } });
|
||||
i18n.setLang('ru');
|
||||
expect(lang()).toBe('ru');
|
||||
expect(store['dl.lang']).toBe('ru');
|
||||
expect(_('Hello')).toBe('Привет');
|
||||
expect(_('Not in the catalog')).toBe('Not in the catalog');
|
||||
expect([1, 2, 5, 11, 21, 22, 25, 111].map((n) => plural(n, '%s device', '%s devices'))).toEqual([
|
||||
'1 устройство',
|
||||
'2 устройства',
|
||||
'5 устройств',
|
||||
'11 устройств',
|
||||
'21 устройство',
|
||||
'22 устройства',
|
||||
'25 устройств',
|
||||
'111 устройств',
|
||||
]);
|
||||
expect(num(2000)).toBe('2 000');
|
||||
i18n.setLang('en');
|
||||
expect(_('Hello')).toBe('Hello');
|
||||
expect(plural(2, '%s device', '%s devices')).toBe('2 devices');
|
||||
});
|
||||
|
||||
it('picks plural forms by the formula its catalog declares', () => {
|
||||
const header = parsePo(fs.readFileSync(new URL('../src/portal/i18n/ru.po', import.meta.url), 'utf8')).header;
|
||||
const formula = header
|
||||
.find(([k]) => k === 'Plural-Forms')![1]
|
||||
.replace(/^.*plural=/, '')
|
||||
.replace(/;$/, '');
|
||||
const index = new Function('n', `return +(${formula});`) as (n: number) => number;
|
||||
i18n.addCatalog('ru', { s: {}, p: { probe: ['0', '1', '2'] } });
|
||||
i18n.setLang('ru', false);
|
||||
for (let n = 0; n <= 250; n++) expect(N_(n, 'probe', 'probes')).toBe(String(index(n)));
|
||||
});
|
||||
});
|
||||
Binary file not shown.
@@ -0,0 +1,30 @@
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Content-Type: text/plain; charset=UTF-8\n"
|
||||
"Language: ru\n"
|
||||
"Plural-Forms: nplurals=3; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 || n%100>=20) ? 1 : 2);\n"
|
||||
|
||||
msgid "Save"
|
||||
msgstr "Сохранить"
|
||||
|
||||
msgctxt "state"
|
||||
msgid "Off"
|
||||
msgstr "Выкл."
|
||||
|
||||
msgid "%s device"
|
||||
msgid_plural "%s devices"
|
||||
msgstr[0] "%s устройство"
|
||||
msgstr[1] "%s устройства"
|
||||
msgstr[2] "%s устройств"
|
||||
|
||||
msgid "Dawnline"
|
||||
msgstr "Dawnline"
|
||||
|
||||
msgid "Untranslated"
|
||||
msgstr ""
|
||||
|
||||
msgid "Say \"hi\" \\ there"
|
||||
msgstr "Скажи «привет» \\ там"
|
||||
|
||||
msgid "abc"
|
||||
msgstr "abcde"
|
||||
@@ -94,13 +94,15 @@ describe('setup', () => {
|
||||
it('words the import as each platform’s app does', () => {
|
||||
expect(importPath('awg', 'ios')).toBe('+ → Create from file or archive');
|
||||
expect(importPath('awg', 'android')).toBe('+ → Import from file or archive');
|
||||
expect(importPath('wg', 'windows')).toBe('Add Tunnel → Import tunnel(s) from file');
|
||||
expect(importPath('vpn', 'ios')).toBe('Add server → Insert key');
|
||||
expect(importPath('wg', 'windows')).toBe('Add Tunnel → Import tunnel(s) from file…');
|
||||
expect(importPath('vpn', 'ios')).toBe('+ → Insert');
|
||||
expect(scanPath('vpn')).toBe('+ → QR code');
|
||||
expect(importPath('awg', 'unknown')).toBe('+ → Import from file or archive');
|
||||
expect(scanPath('awg', 'android')).toBe('+ → Scan from QR code');
|
||||
expect(scanPath('awg')).toBe('+ → Create from QR code (Android: Scan from QR code)');
|
||||
expect(importSteps('awg', 'mac', 'Outline-Home.conf', false)).toEqual([
|
||||
['Open AmneziaWG', ''],
|
||||
['+ → ', 'Import tunnel(s) from file'],
|
||||
['+ → ', 'Import Tunnel(s) from File…'],
|
||||
['Pick the file and connect', ''],
|
||||
]);
|
||||
expect(importSteps('awg', 'linux', 'Outline-Home.conf', false)[1]).toEqual(['Run ', 'sudo awg-quick up ./Outline-Home.conf']);
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
// Tests read English: _() and N_() as LuCI has them with no catalog loaded.
|
||||
// The portal's own (portal/i18n.ts) replace these where a test imports it.
|
||||
Object.assign(globalThis, {
|
||||
_: (s: string) => s,
|
||||
N_: (n: number, s: string, p: string) => (n === 1 ? s : p),
|
||||
});
|
||||
Reference in new issue
Block a user