mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Added portuguese, translate.js merge command.
This commit is contained in:
parent
fa53e19f86
commit
cedb058a4b
31 changed files with 28206 additions and 1385 deletions
|
@ -53,7 +53,7 @@ function start() {
|
|||
|
||||
var command = null;
|
||||
if (process.argv.length > 2) { command = process.argv[2].toLowerCase(); }
|
||||
if (['check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall'].indexOf(command) == -1) { command = null; }
|
||||
if (['check', 'extract', 'extractall', 'translate', 'translateall', 'minifyall', 'merge'].indexOf(command) == -1) { command = null; }
|
||||
|
||||
console.log('MeshCentral web site translator');
|
||||
if (command == null) {
|
||||
|
@ -77,6 +77,9 @@ function start() {
|
|||
console.log('');
|
||||
console.log(' MINIFYALL');
|
||||
console.log(' Minify the main MeshCentral english web pages.');
|
||||
console.log('');
|
||||
console.log(' MERGE [sourcefile] [tartgetfile] [language code]');
|
||||
console.log(' Merge a language from a translation file into another translation file.');
|
||||
process.exit();
|
||||
return;
|
||||
}
|
||||
|
@ -105,6 +108,18 @@ function start() {
|
|||
extract(process.argv[3], sources);
|
||||
}
|
||||
|
||||
// Merge one language from a language file into another language file.
|
||||
if (command == 'merge') {
|
||||
if ((process.argv.length == 6)) {
|
||||
if (fs.existsSync(process.argv[3]) == false) { console.log('Unable to find: ' + process.argv[3]); return; }
|
||||
if (fs.existsSync(process.argv[4]) == false) { console.log('Unable to find: ' + process.argv[4]); return; }
|
||||
merge(process.argv[3], process.argv[4], process.argv[5]);
|
||||
} else {
|
||||
console.log('Usage: MERGE [sourcefile] [tartgetfile] [language code]');
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Extract or translate all MeshCentral strings
|
||||
if (command == 'extractall') { extract("translate.json", meshCentralSourceFiles); }
|
||||
if (command == 'translateall') {
|
||||
|
@ -180,6 +195,39 @@ function start() {
|
|||
}
|
||||
}
|
||||
|
||||
function merge(source, target, lang) {
|
||||
// Load the source language file
|
||||
var sourceLangFileData = null;
|
||||
try { sourceLangFileData = JSON.parse(fs.readFileSync(source)); } catch (ex) { }
|
||||
if ((sourceLangFileData == null) || (sourceLangFileData.strings == null)) { console.log("Invalid source language file."); process.exit(); return; }
|
||||
|
||||
// Load the target language file
|
||||
var targetLangFileData = null;
|
||||
try { targetLangFileData = JSON.parse(fs.readFileSync(target)); } catch (ex) { }
|
||||
if ((targetLangFileData == null) || (targetLangFileData.strings == null)) { console.log("Invalid target language file."); process.exit(); return; }
|
||||
|
||||
console.log('Merging ' + lang + '...');
|
||||
|
||||
// Index the target file
|
||||
var index = {};
|
||||
for (var i in targetLangFileData.strings) { if (targetLangFileData.strings[i].en != null) { index[targetLangFileData.strings[i].en] = targetLangFileData.strings[i]; } }
|
||||
|
||||
// Merge the translation
|
||||
for (var i in sourceLangFileData.strings) {
|
||||
if ((sourceLangFileData.strings[i].en != null) && (sourceLangFileData.strings[i][lang] != null) && (index[sourceLangFileData.strings[i].en] != null)) {
|
||||
index[sourceLangFileData.strings[i].en][lang] = sourceLangFileData.strings[i][lang];
|
||||
}
|
||||
}
|
||||
|
||||
// Deindex the new target file
|
||||
var targetData = { strings: [] };
|
||||
for (var i in index) { targetData.strings.push(index[i]); }
|
||||
|
||||
// Save the target back
|
||||
fs.writeFileSync(target, JSON.stringify(targetData, null, ' '), { flag: 'w+' });
|
||||
console.log('Done.');
|
||||
}
|
||||
|
||||
function translate(lang, langFile, sources, createSubDir) {
|
||||
// Load the language file
|
||||
var langFileData = null;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue