53 строки
1.3 KiB
JavaScript
Executable File
53 строки
1.3 KiB
JavaScript
Executable File
#!/usr/bin/env node --use_strict
|
|
/* eslint-disable no-console */
|
|
|
|
/*
|
|
* If a locale doesn't exist create it under locale and generate
|
|
* the relevant po files from the .pot
|
|
*/
|
|
|
|
require('@babel/register');
|
|
|
|
|
|
const chalk = require('chalk');
|
|
const config = require('config');
|
|
const fs = require('fs');
|
|
const path = require('path');
|
|
const shell = require('shelljs');
|
|
|
|
const supportedLangs = config.get('langs');
|
|
const localeDir = path.join(__dirname, '../locale');
|
|
const templateDir = path.join(localeDir, 'templates/LC_MESSAGES');
|
|
const langToLocale = require('../src/core/i18n/utils').langToLocale;
|
|
|
|
const appName = config.get('appName');
|
|
|
|
if (!appName) {
|
|
console.log(
|
|
chalk.red('appName not set in config'));
|
|
process.exit(1);
|
|
}
|
|
|
|
|
|
let lang;
|
|
let locale;
|
|
let outputFile;
|
|
|
|
for (lang of supportedLangs) {
|
|
locale = langToLocale(lang);
|
|
shell.exec(`mkdir -p ${localeDir}/${locale}/LC_MESSAGES/`);
|
|
outputFile = path.join(localeDir, locale, 'LC_MESSAGES', `${appName}.po`);
|
|
try {
|
|
fs.statSync(outputFile);
|
|
// eslint-disable-next-line no-console
|
|
console.log(`${outputFile} already exists skipping`);
|
|
} catch (e) {
|
|
if (e.code === 'ENOENT') {
|
|
shell.exec(`msginit --no-translator --input=${templateDir}/${appName}.pot
|
|
--output-file=${outputFile} -l ${locale}`.replace('\n', ' '));
|
|
} else {
|
|
throw e;
|
|
}
|
|
}
|
|
}
|