diff --git a/bin/merge-locales b/bin/merge-locales new file mode 100755 index 00000000000..fc41b53cce4 --- /dev/null +++ b/bin/merge-locales @@ -0,0 +1,31 @@ +#!/usr/bin/env node + +/* eslint-disable no-console */ +require('babel-register'); +const config = require('config'); +const glob = require('glob'); +const path = require('path'); +const shell = require('shelljs'); +const chalk = require('chalk'); + +const localeDir = path.join(__dirname, '../locale'); + +const appName = config.get('appName'); + +if (!appName) { + console.log( + chalk.red('Please specify the appName with NODE_APP_INSTANCE')); + process.exit(1); +} + +const poFiles = glob.sync(`${localeDir}/**/${appName}.po`); +const template = + path.join(localeDir, `templates/LC_MESSAGES/${appName}.pot`); + +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 -q -o ${tempFile} ${poFile} ${template}`); + shell.mv(tempFile, poFile); +});