addons-linter/scripts/merge-locales

28 строки
741 B
JavaScript
Executable File

#!/usr/bin/env node
/* eslint-disable global-require */
const path = require('path');
const { globSync } = require('glob');
const shell = require('shelljs');
const localeDir = path.join(__dirname, '../locale');
const poFiles = globSync(`${localeDir}/**/messages.po`);
const template = path.join(localeDir, `templates/LC_MESSAGES/messages.pot`);
if (!shell.which('msgmerge')) {
shell.echo('This script requires msgmerge');
shell.exit(1);
}
poFiles.forEach((poFile) => {
const dir = path.dirname(poFile);
const stem = path.basename(poFile, '.po');
const tempFile = path.join(dir, `${stem}.po.tmp`);
shell.exec(
`msgmerge --no-fuzzy-matching -q -o ${tempFile} ${poFile} ${template}`
);
shell.mv(tempFile, poFile);
});