2024-05-21 03:10:59 +02:00
|
|
|
import locales from './index.js';
|
|
|
|
|
2024-06-11 16:29:25 +02:00
|
|
|
const showUntranslated = process.argv[2] == '-v';
|
|
|
|
|
2024-05-21 03:10:59 +02:00
|
|
|
let valid = true;
|
|
|
|
|
|
|
|
function writeError(type, lang, tree, data) {
|
|
|
|
process.stderr.write(JSON.stringify({ type, lang, tree, data }));
|
|
|
|
process.stderr.write('\n');
|
|
|
|
valid = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
function verify(expected, actual, lang, trace) {
|
|
|
|
for (let key in expected) {
|
|
|
|
if (!Object.prototype.hasOwnProperty.call(actual, key)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (typeof expected[key] === 'object') {
|
|
|
|
if (typeof actual[key] !== 'object') {
|
|
|
|
writeError('mismatched_type', lang, trace ? `${trace}.${key}` : key, { expected: 'object', actual: typeof actual[key] });
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
verify(expected[key], actual[key], lang, trace ? `${trace}.${key}` : key);
|
|
|
|
} else if (typeof expected[key] === 'string') {
|
|
|
|
switch (typeof actual[key]) {
|
|
|
|
case 'object':
|
|
|
|
writeError('mismatched_type', lang, trace ? `${trace}.${key}` : key, { expected: 'string', actual: 'object' });
|
|
|
|
break;
|
|
|
|
case 'undefined':
|
|
|
|
continue;
|
|
|
|
case 'string':
|
|
|
|
const expectedParameters = new Set(expected[key].match(/\{[^}]+\}/g)?.map((s) => s.slice(1, -1)));
|
|
|
|
const actualParameters = new Set(actual[key].match(/\{[^}]+\}/g)?.map((s) => s.slice(1, -1)));
|
|
|
|
for (let parameter of expectedParameters) {
|
|
|
|
if (!actualParameters.has(parameter)) {
|
|
|
|
writeError('missing_parameter', lang, trace ? `${trace}.${key}` : key, { parameter });
|
|
|
|
}
|
|
|
|
}
|
2024-06-11 16:29:25 +02:00
|
|
|
|
|
|
|
if (showUntranslated && actual[key] == expected[key]) {
|
|
|
|
writeError('untranslated', lang, trace ? `${trace}.${key}` : key, { original: expected[key] });
|
|
|
|
}
|
2024-05-21 03:10:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const { ['ja-JP']: original, ...verifiees } = locales;
|
|
|
|
|
|
|
|
for (let lang in verifiees) {
|
|
|
|
if (!Object.prototype.hasOwnProperty.call(locales, lang)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
verify(original, verifiees[lang], lang);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!valid) {
|
|
|
|
process.exit(1);
|
|
|
|
}
|