Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
test(i18n): pin the whole-value anchor of the URL exemption
Yudhi Armyndharisba0b53cf5ae8
diff --git a/dashboard/src/i18n/check-i18n-parity.test.ts b/dashboard/src/i18n/check-i18n-parity.test.tsindex a81d2e43a..15606e039 100644--- a/dashboard/src/i18n/check-i18n-parity.test.ts+++ b/dashboard/src/i18n/check-i18n-parity.test.ts@@ -6,19 +6,22 @@ import { tmpdir } from 'node:os';import { fileURLToPath } from 'node:url';import { dirname, join } from 'node:path';-// Runs the real parity script against a copy of the catalogues with one value broken, so the check-// is proven to catch the mistake rather than only to pass on the shipped files.+// Runs the real parity script against a copy of the catalogues with values broken, so the check is+// proven to catch the mistake rather than only to pass on the shipped files.const HERE = dirname(fileURLToPath(import.meta.url));const LOCALES_DIR = join(HERE, 'locales');const SCRIPT = join(HERE, '..', '..', 'scripts', 'check-i18n-parity.mjs');-function runWith<T = { chats: { channels: Record<string, string> } }>(file: string, edit: (catalogue: T) => void) {+/** Apply each file's edit to a copy of the catalogues, then run the script against the copy. */+function runWith<T = { chats: { channels: Record<string, string> } }>(edits: Record<string, (catalogue: T) => void>) {const dir = mkdtempSync(join(tmpdir(), 'i18n-parity-'));try {cpSync(LOCALES_DIR, dir, { recursive: true });- const catalogue = JSON.parse(readFileSync(join(dir, file), 'utf8'));- edit(catalogue);- writeFileSync(join(dir, file), JSON.stringify(catalogue, null, 2));+ for (const [file, edit] of Object.entries(edits)) {+ const catalogue = JSON.parse(readFileSync(join(dir, file), 'utf8'));+ edit(catalogue);+ writeFileSync(join(dir, file), JSON.stringify(catalogue, null, 2));+ }return spawnSync(process.execPath, [SCRIPT, dir], { encoding: 'utf8' });} finally {rmSync(dir, { recursive: true, force: true });@@ -33,8 +36,10 @@ test('the shipped catalogues pass the parity check', () => {});test('a renamed token in a plural form en.json does not have fails the check', () => {- const result = runWith('fr.json', c => {- c.chats.channels.subscribers_many = '{{cnt}} abonnés';+ const result = runWith({+ 'fr.json': c => {+ c.chats.channels.subscribers_many = '{{cnt}} abonnés';+ },});assert.equal(result.status, 1, result.stdout);assert.match(result.stderr, /chats\.channels\.subscribers_many: expected count/);@@ -49,9 +54,22 @@ test('placeholder-only and whole-URL values are not reported as untranslated', (test('an English sentence left in a locale is still reported, even when it contains a URL', () => {const en = JSON.parse(readFileSync(join(LOCALES_DIR, 'en.json'), 'utf8'));- const result = runWith<{ messageTester: Record<string, string> }>('de.json', c => {- c.messageTester.bulkMediaUrlInvalid = en.messageTester.bulkMediaUrlInvalid;+ const result = runWith<{ messageTester: Record<string, string> }>({+ 'de.json': c => {+ c.messageTester.bulkMediaUrlInvalid = en.messageTester.bulkMediaUrlInvalid;+ },});assert.equal(result.status, 0, result.stderr);assert.match(result.stderr, /\? messageTester\.bulkMediaUrlInvalid$/m);});++test('a value that starts with a URL and continues in prose is still reported as untranslated', () => {+ // Only the whole value may be a URL: the check compares against en.json, so both files carry it.+ const value = 'https://example.com is not reachable, check the address';+ const edit = (c: { messageTester: Record<string, string> }) => {+ c.messageTester.bulkMediaUrlInvalid = value;+ };+ const result = runWith({ 'en.json': edit, 'de.json': edit });+ assert.equal(result.status, 0, result.stderr);+ assert.match(result.stderr, /\? messageTester\.bulkMediaUrlInvalid$/m);+});