This commit is contained in:
Yuri Kuznetsov
2023-05-02 18:06:33 +03:00
parent 81ac053818
commit 9a6cfd4228
2 changed files with 23 additions and 20 deletions

24
lang.js
View File

@@ -25,14 +25,14 @@
* In accordance with Section 7(b) of the GNU General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************************************/

/**
* Builds language files from a PO file.
*
* Command example: `node lang de_DE`.
*
* A PO file should be located in `build` directory: `build/espocrm-lang_CODE.po`.
* Langugae files will be created in `build` directory.
* Language files will be created in `build` directory.
*
* You specify a module with `--module=` parameter. It will build only for the specified module.
*/
@@ -45,30 +45,32 @@ if (process.argv.length < 3) {
throw new Error('You need to pass a language code as a second parameter.');
}
var espoPath = path.dirname(fs.realpathSync(__filename)) + '';
var language = process.argv[2];
let espoPath = path.dirname(fs.realpathSync(__filename)) + '';
let language = process.argv[2];
var poPath = null;
let poPath = null;
let onlyModuleName = null;
var onlyModuleName = null;
if (process.argv.length > 2) {
for (var i in process.argv) {
for (let i in process.argv) {
if (~process.argv[i].indexOf('--module=')) {
onlyModuleName = process.argv[i].substr(('--module=').length);
onlyModuleName = process.argv[i].substring(('--module=').length);
}
if (~process.argv[i].indexOf('--path=')) {
poPath = process.argv[i].substr(('--path=').length);
poPath = process.argv[i].substring(('--path=').length);
}
}
}
if (!poPath) {
poPath = espoPath + '/build/' + 'espocrm-' + language;
if (onlyModuleName) {
poPath += '-' + onlyModuleName;
}
poPath += '.po';
}
var lang = new Lang(language, poPath, espoPath, onlyModuleName);
lang.run();
new Lang(language, poPath, espoPath, onlyModuleName).run();

19
po.js
View File

@@ -41,26 +41,27 @@ const PO = require('./js/po');
const path = require('path');
const fs = require('fs');
var language = process.argv[2] || null;
let language = process.argv[2] || null;
let onlyModuleName = null;
var onlyModuleName = null;
if (process.argv.length > 2) {
for (var i in process.argv) {
for (let i in process.argv) {
if (~process.argv[i].indexOf('--module=')) {
onlyModuleName = process.argv[i].substr(('--module=').length);
}
if (~process.argv[i].indexOf('--all')) {
language = '--all';
}
}
}
var espoPath = path.dirname(fs.realpathSync(__filename)) + '';
let espoPath = path.dirname(fs.realpathSync(__filename)) + '';
var po = new PO(espoPath, language, onlyModuleName);
let po = new PO(espoPath, language, onlyModuleName);
if (language === '--all') {
po.runAll();
} else {
language === '--all' ?
po.runAll() :
po.run();
}