Skip to content

Free, Open Source, Self-Hosted WhatsApp API Gateway

test(i18n): cover the untranslated-warning exemptions

Yudhi Armyndharisaa3dd68303c0
diff --git a/dashboard/scripts/check-i18n-parity.mjs b/dashboard/scripts/check-i18n-parity.mjs
index 904ba4ba4..6ec2b0b37 100644
--- a/dashboard/scripts/check-i18n-parity.mjs
+++ b/dashboard/scripts/check-i18n-parity.mjs
@@ -71,7 +71,7 @@ function setsEqual(a, b) {
* A value made up only of {{placeholder}} tokens plus short separator punctuation (spaces, ·, /, :, etc. — no actual alphabetic prose outside the tokens), or a value matching a URL shape (scheme://...) should not be flagged.
*/
function hasTranslatableProse(str) {
- if (/^[a-zA-Z]+:\/\//.test(str)) return false;
+ if (/^[a-z][a-z0-9+.-]*:\/\/\S+$/i.test(str)) return false;
const noTokens = str.replace(/\{\{.*?\}\}/g, '');
return /\p{L}{2,}/u.test(noTokens);
}
diff --git a/dashboard/src/i18n/check-i18n-parity.test.ts b/dashboard/src/i18n/check-i18n-parity.test.ts
index fab1ffafb..e1ad80e53 100644
--- a/dashboard/src/i18n/check-i18n-parity.test.ts
+++ b/dashboard/src/i18n/check-i18n-parity.test.ts
@@ -12,7 +12,7 @@ const HERE = dirname(fileURLToPath(import.meta.url));
const LOCALES_DIR = join(HERE, 'locales');
const SCRIPT = join(HERE, '..', '..', 'scripts', 'check-i18n-parity.mjs');
-function runWith(file: string, edit: (catalogue: { chats: { channels: Record<string, string> } }) => void) {
+function runWith<T = { chats: { channels: Record<string, string> } }>(file: string, edit: (catalogue: T) => void) {
const dir = mkdtempSync(join(tmpdir(), 'i18n-parity-'));
try {
cpSync(LOCALES_DIR, dir, { recursive: true });
@@ -37,3 +37,19 @@ test('a renamed token in a plural form en.json does not have fails the check', (
assert.equal(result.status, 1, result.stdout);
assert.match(result.stderr, /chats\.channels\.subscribers_many: expected count/);
});
+
+test('placeholder-only and whole-URL values are not reported as untranslated', () => {
+ const result = spawnSync(process.execPath, [SCRIPT], { encoding: 'utf8' });
+ assert.equal(result.status, 0, result.stderr);
+ assert.doesNotMatch(result.stderr, /\? login\.version$/m);
+ assert.doesNotMatch(result.stderr, /\? sessions\.proxy\.urlPlaceholder$/m);
+});
+
+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;
+ });
+ assert.equal(result.status, 0, result.stderr);
+ assert.match(result.stderr, /\? messageTester\.bulkMediaUrlInvalid$/m);
+});