Added test to check for mismatched brackets in translations

refs https://github.com/TryGhost/Toolbox/issues/603

- this will loop over all locales and translations files to check for
  a mismatched bracket count
This commit is contained in:
Daniel Lockyer 2023-06-27 08:45:42 +02:00
parent bebf85f84a
commit a8801be82a
No known key found for this signature in database

View File

@ -1,8 +1,36 @@
const assert = require('assert/strict');
const fs = require('fs/promises');
const path = require('path');
const i18n = require('../');
describe('i18n', function () {
it('does not have mismatched brackets in variables', async function () {
for (const locale of i18n.SUPPORTED_LOCALES) {
const translationFiles = await fs.readdir(path.join(`./locales/`, locale));
for (const file of translationFiles) {
const translationFile = require(path.join(`../locales/`, locale, file));
for (const key of Object.keys(translationFile)) {
const keyStartCount = key.match(/{{/g)?.length;
assert.equal(keyStartCount, key.match(/}}/g)?.length, `[${locale}/${file}] mismatched brackets in ${key}`);
const value = translationFile[key];
if (typeof value === 'string') {
const valueStartCount = value.match(/{{/g)?.length;
assert.equal(valueStartCount, value.match(/}}/g)?.length, `[${locale}/${file}] mismatched brackets in ${value}`);
// Maybe enable in the future if we want to enforce this
//if (value !== '') {
// assert.equal(keyStartCount, valueStartCount, `[${locale}/${file}] mismatched brackets between ${key} and ${value}`);
//}
}
}
}
}
});
describe('Can use Portal resources', function () {
describe('Dutch', function () {
let t;