Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,493 changes: 1,490 additions & 3 deletions web/public/locales/ar.json

Large diffs are not rendered by default.

1,503 changes: 1,495 additions & 8 deletions web/public/locales/de.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/es.json

Large diffs are not rendered by default.

1,525 changes: 1,524 additions & 1 deletion web/public/locales/fil.json

Large diffs are not rendered by default.

1,503 changes: 1,495 additions & 8 deletions web/public/locales/fr.json

Large diffs are not rendered by default.

1,501 changes: 1,494 additions & 7 deletions web/public/locales/it.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/ja.json

Large diffs are not rendered by default.

1,493 changes: 1,489 additions & 4 deletions web/public/locales/ko.json

Large diffs are not rendered by default.

1,493 changes: 1,490 additions & 3 deletions web/public/locales/nl.json

Large diffs are not rendered by default.

1,499 changes: 1,493 additions & 6 deletions web/public/locales/pl.json

Large diffs are not rendered by default.

1,298 changes: 1,291 additions & 7 deletions web/public/locales/pt-BR.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/pt-PT.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/ru.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/tr.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/uk.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/zh-TW.json

Large diffs are not rendered by default.

1,497 changes: 1,492 additions & 5 deletions web/public/locales/zh.json

Large diffs are not rendered by default.

52 changes: 52 additions & 0 deletions web/tests/locale-coverage.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import fs from 'node:fs';
import path from 'node:path';

const localeDir = path.resolve(__dirname, '../public/locales');
const readCatalog = (code) => JSON.parse(fs.readFileSync(path.join(localeDir, `${code}.json`), 'utf8'));
const manifest = JSON.parse(fs.readFileSync(path.join(localeDir, 'manifest.json'), 'utf8'));
const english = readCatalog('en');
const englishKeys = Object.keys(english);
const englishKeySet = new Set(englishKeys);
const placeholders = (value) => [...value.matchAll(/\{[^{}]+\}/g)].map(([token]) => token).sort();
const markup = (value) => [...value.matchAll(/<[^>]+>/g)].map(([token]) => token).sort();
const exampleUrls = (value) => [...value.matchAll(/(?:https?|rtsps?|rtmps?|s3):\/\/[A-Za-z0-9_@.:/…-]+/g)].map(([url]) => url.replace(/\.$/, ''));
const protocolNames = ['LightNVR', 'lightNVR', 'go2rtc', 'ONVIF', 'RTSP', 'WebRTC', 'HLS', 'MSE', 'MQTT', 'S3', 'PTZ', 'ePTZ', 'TOTP'];
const shortcutNames = ['Alt', 'Ctrl/Cmd', 'Shift', 'Enter', 'Escape'];
const shortcutKeys = new Set([
'live.plan.sketch.hint.select',
'live.plan.sketch.hint.wall',
'live.plan.sketch.hint.area',
'timeline.help.zoomControls',
'timeline.help.panControls',
'timeline.inlineHint',
]);

describe('locale catalog coverage', () => {
for (const { code } of manifest.locales) {
if (code === 'en') continue;

test(`${code} has valid keys and preserved literals`, () => {
const catalog = readCatalog(code);
const missing = englishKeys.filter((key) => !(key in catalog));
const orphans = Object.keys(catalog).filter((key) => !englishKeySet.has(key));
const invalid = Object.entries(catalog).flatMap(([key, value]) => {
if (typeof value !== 'string' || !value.trim()) return [key];
if (/__\s*P\d+\s*__/i.test(value)) return [key];
if (!englishKeySet.has(key)) return [];
if (JSON.stringify(placeholders(value)) !== JSON.stringify(placeholders(english[key]))) return [key];
if (JSON.stringify(markup(value)) !== JSON.stringify(markup(english[key]))) return [key];
if (exampleUrls(english[key]).some((url) => !value.includes(url))) return [key];
if (shortcutKeys.has(key) && shortcutNames.some((name) => english[key].includes(name) && !value.includes(name))) return [key];
return protocolNames.some((name) => english[key].includes(name)
&& !value.includes(name)
&& !(name === 'lightNVR' && value.includes('LightNVR'))) ? [key] : [];
});

const coverage = ((englishKeys.length - missing.length) / englishKeys.length * 100).toFixed(1);
console.info(`${code}: ${coverage}% coverage (${missing.length} missing keys)`);
if (missing.length) console.warn(`${code} missing ${missing.length} English keys`);
expect(orphans).toEqual([]);
expect(invalid).toEqual([]);
});
}
});
Loading