summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGoraf <22941576+Goraf@users.noreply.github.com>2017-12-09 22:10:44 +0100
committerGoraf <22941576+Goraf@users.noreply.github.com>2017-12-09 22:52:52 +0100
commit3ebe1555e56f7556700961fdc36927c4293dd4cf (patch)
tree20c86ad9727ffd607b205c5b3d65fde725b90bdc
parent90674ba62902b7aaeceeb4c326469a74a32a259d (diff)
lpgen: Optimize code ...
* don't declare strings as Objects * use array literal notation * reduce activity in loops * reduce implied global variables
-rw-r--r--tools/lpgen/lpgen.js190
-rw-r--r--tools/lpgen/translate.js158
2 files changed, 214 insertions, 134 deletions
diff --git a/tools/lpgen/lpgen.js b/tools/lpgen/lpgen.js
index a10870eda3..2dbe58325c 100644
--- a/tools/lpgen/lpgen.js
+++ b/tools/lpgen/lpgen.js
@@ -33,24 +33,25 @@ var stream = new ActiveXObject("ADODB.Stream");
//stream var tune
stream.Type = 2; // text mode
stream.Charset = "utf-8";
+//plugin - variable for plugin name
+var plugin = "";
//Path variables
//lpgen.js script path
var scriptpath = FSO.GetParentFolderName(WScript.ScriptFullName);
-//crazy way to get path two layers upper "\tools\lpgen\"
-var trunk = FSO.GetFolder(FSO.GetParentFolderName(FSO.GetParentFolderName(scriptpath)));
-//text string for make path output into templates.
-var trunkPath = new String(trunk);
+//get path two layers upper "\tools\lpgen\"
+//string for make path output into templates.
+var trunkPath = FSO.GetParentFolderName(FSO.GetParentFolderName(scriptpath));
//path to sln file
-var slnfile = trunk + "\\bin15\\mir_full.sln";
+var slnfile = FSO.BuildPath(trunkPath, "bin15\\mir_full.sln");
//core path
-var core = FSO.BuildPath(trunk, "src");
+var core = FSO.BuildPath(trunkPath, "src");
//langpack folder "\langpacks\english\" in trunk folder
-var langpack_en = FSO.BuildPath(trunk, "langpacks\\english");
+var langpack_en = FSO.BuildPath(trunkPath, "langpacks\\english");
//Crap.txt will contain strings, which are removed by filtering engine as a garbage, in case if this string are not garbage :)
var crapfile = "Crap.txt";
//Crap array
-var crap = new Array();
+var crap = [];
//*********************************************************************************//
// Checking command line parameters *//
@@ -69,9 +70,9 @@ if (WScript.Arguments.Named.Item("dupes")) {
//If script run by double click, open choose folder dialog to choose plugin folder to parse. If Cancel pressed, quit script.
if (WScript.FullName.toLowerCase().charAt(WScript.FullName.length - 11) == "w") {
//Create Shell app object
- objShellApp = WScript.CreateObject("Shell.Application");
+ var objShellApp = WScript.CreateObject("Shell.Application");
//Open browse for folder dialog
- objFolder = objShellApp.BrowseForFolder(0, "Choose plugin source files folder\nto generate translation template", 512, 17);
+ var objFolder = objShellApp.BrowseForFolder(0, "Choose plugin source files folder\nto generate translation template", 512, 17);
//process generate translate for chosen folder, else quit.
if (objFolder) {
//Call GeneratePluginTranslate for chosen folder, output result to "scriptpath"
@@ -104,15 +105,15 @@ GenerateCore();
//Generate plugins\protocols, listed in mir_full.sln
//Init array with files path
-project_files = new Array();
+var project_files = [];
//open mir_full.sln
-sln_stream = FSO.GetFile(slnfile).OpenAsTextStream(ForReading, TristateUseDefault);
+var sln_stream = FSO.GetFile(slnfile).OpenAsTextStream(ForReading, TristateUseDefault);
//Reading line-by-line
while (!sln_stream.AtEndOfStream) {
//Init regexp array for our sln parse logic
- sln_project_regexp = new Array();
+ var sln_project_regexp = [];
//read one line into slnline
- slnline = sln_stream.ReadLine();
+ var slnline = sln_stream.ReadLine();
//find a project definition in sln file by RegExp
sln_project_regexp = slnline.match(/(?:Project\(\"\{[\w\d-]+\}\"\)\x20+\=\x20+\"(.+?)\",\x20*?\"\.\.)(\\(:?plugins|protocols).*vcxproj)(?=",)/i);
// if exist sln_project_regexp, add to array, adding leading path to "trunk"
@@ -122,7 +123,7 @@ while (!sln_stream.AtEndOfStream) {
// Now check for unneeded modules NOT passed (module name are in sln_project_regexp[1]
if (!unneeded_modules.test(sln_project_regexp[1])) {
//no, this is not unneeded module, put path to array. Trunk path + path to file in sln_project_regexp[2]
- project_files.push(trunk + sln_project_regexp[2]);
+ project_files.push(trunkPath + sln_project_regexp[2]);
}
}
}
@@ -130,20 +131,20 @@ while (!sln_stream.AtEndOfStream) {
sln_stream.Close();
//ok, now we have all project files in array, let's add Pascal files to this array directly.
// remove following lines comments to add Pascal plugins processing.
-// project_files.push(trunk+"\\plugins\\Actman\\actman.dpr");
-// project_files.push(trunk+"\\plugins\\HistoryPlusPlus\\historypp.dpr");
-// project_files.push(trunk+"\\plugins\\ImportTXT\\importtxt.dpr");
-// project_files.push(trunk+"\\plugins\\QuickSearch\\quicksearch.dpr");
-// project_files.push(trunk+"\\plugins\\Watrack\\watrack.dpr");
-// project_files.push(trunk+"\\plugins\\mRadio\\mradio.dpr");
+// project_files.push(trunkPath+"\\plugins\\Actman\\actman.dpr");
+// project_files.push(trunkPath+"\\plugins\\HistoryPlusPlus\\historypp.dpr");
+// project_files.push(trunkPath+"\\plugins\\ImportTXT\\importtxt.dpr");
+// project_files.push(trunkPath+"\\plugins\\QuickSearch\\quicksearch.dpr");
+// project_files.push(trunkPath+"\\plugins\\Watrack\\watrack.dpr");
+// project_files.push(trunkPath+"\\plugins\\mRadio\\mradio.dpr");
//create Enumerator with project files from sln and dpr files, sorted alphabetically
-files = new Enumerator(project_files.sort());
+var files = new Enumerator(project_files.sort());
while (!files.atEnd()) {
//get file name
- file = FSO.GetFile(files.item());
+ var file = FSO.GetFile(files.item());
//get parent folder name
- plugfolder = FSO.GetParentFolderName(file);
+ var plugfolder = FSO.GetParentFolderName(file);
//call function for plugin folder, output to plugins folder.
GeneratePluginTranslate(plugfolder, langpack_en + "\\Plugins", file);
//next project file
@@ -164,11 +165,14 @@ if (log) {
//Generate =CORE=.txt
function GenerateCore() {
+ var corefile = "",
+ ver = "";
//init arrays
- corestrings = new Array();
- corehead = new Array();
- core_src = new Array();
- core_rc = new Array();
+ var corestrings = [],
+ corehead = [],
+ core_src = [],
+ core_rc = [],
+ nodupes;
//if log parameter specified, output a log.
if (log) {
WScript.Echo("Processing CORE...");
@@ -186,8 +190,6 @@ function GenerateCore() {
corehead.push("; Module: Miranda Core");
corehead.push("; Version: " + ver);
corehead.push(";============================================================");
- //define core filename. File will be overwritten!
- corefile = FSO.BuildPath(langpack_en, "=CORE=.txt");
//find all *.rc files and list files in array
FindFiles(core, "\\.rc$", core_rc);
//find all source files and list files in array
@@ -208,20 +210,25 @@ function GenerateCore() {
}
//concatenate head and nodupes
corestrings = corehead.concat(nodupes);
+ //define core filename. File will be overwritten!
+ corefile = FSO.BuildPath(langpack_en, "=CORE=.txt");
//finally, write "nodupes" array to file
WriteToUnicodeFileNoBOM(corestrings, corefile);
}
//Make a translation template for plugin in "pluginpath", put generated file into "langpackfilepath"
function GeneratePluginTranslate(pluginpath, langpackfilepath, vcxprojfile) {
+ var langpack = "",
+ nodupes = [],
+ plugintemplate =[];
//init arrays with files to parse
- resourcefiles = new Array();
- sourcefiles = new Array();
- versionfile = new Array();
+ var resourcefiles = [],
+ sourcefiles = [],
+ versionfile = [];
//init array with muuid+"head"
- head = new Array();
+ var head = [];
//init array with strings from parsed files
- foundstrings = new Array();
+ var foundstrings = [];
//find a name of our plugin
//if vcxprojfile param given, use it
if (vcxprojfile) {
@@ -317,14 +324,17 @@ function FindFiles(path, name, filelistarray) {
//Find a name for plugin translation template file from source
function GetPluginName(folder_or_file) {
+ var plugin_project_file,
+ plugin_project_files = [],
+ project = "",
+ filename = "";
+
//check our parameter file or folder?
if (FSO.FileExists(folder_or_file)) {
//yes, it's a file, set plugin_project_file as a target
plugin_project_file = FSO.GetFile(folder_or_file);
} else {
- //Given parameter is a folder, init file list array
- plugin_project_files = new Array();
- //find project files and put to array
+ //Given parameter is a folder, find project files and put to array
FindFiles(folder_or_file, "\\.vcxproj$|\\.dpr$", plugin_project_files);
//if there is nothing found, that's mean this is not a plugin, return from function
if (!plugin_project_files[0]) return;
@@ -348,17 +358,25 @@ function GetPluginName(folder_or_file) {
function GetMUUID(folder, array) {
//first, find necessary file list, we are looking for UNICODE_AWARE function, usually this function are in *.cpp, sometimes in *.c and *.h
//init fillelist array
- muuidfilelist = new Array();
+ var curfile,
+ muuidfilelist = [],
+ muuid = "",
+ find = /()/,
+ i = 0,
+ values = [],
+ allstrings = "",
+ string = "",
+ vals = "";
//search for files in "folder" by mask, put result into muuidfilelist
FindFiles(folder, "\\.cpp$|\\.c$|\\.h$", muuidfilelist);
//now we have files, let's put them to Enumerator
- filesenum = new Enumerator(muuidfilelist);
+ var filesenum = new Enumerator(muuidfilelist);
//cycle through file list and lookup each file for UNICODE_AWARE
while (!filesenum.atEnd()) {
//curfile is our current file in files enumerator
curfile = filesenum.item();
//this is a regexp to search UNICODE_AWARE
- var find = /(?:UNICODE_AWARE(?:\s*?\|\s*?STATIC_PLUGIN)?,[\s\S]*?\{)(.+?)(?=\}\s{0,2}\})/g;
+ find = /(?:UNICODE_AWARE(?:\s*?\|\s*?STATIC_PLUGIN)?,[\s\S]*?\{)(.+?)(?=\}\s{0,2}\})/g;
//read file fully into var "allstrings"
allstrings = ReadFile(curfile);
//search regexp in "allstrings" and put results into var "string"
@@ -389,7 +407,7 @@ function GetMUUID(folder, array) {
}
}
//Push to array founded #muuid
- var muuid = "#muuid {" + values[0] + "-" + values[1] + "-" + values[2] + "-" + values[3] + values[4] + "-" + values[5] + values[6] + values[7] + values[8] + values[9] + values[10] + "}";
+ muuid = "#muuid {" + values[0] + "-" + values[1] + "-" + values[2] + "-" + values[3] + values[4] + "-" + values[5] + values[6] + values[7] + values[8] + values[9] + values[10] + "}";
}
}
//moving to next file
@@ -412,12 +430,14 @@ function ReadFile(file) {
//If file zero size, return;
if (FSO.GetFile(file).Size === 0) return;
//reading current file
- file_stream = FSO.GetFile(file).OpenAsTextStream(ForReading, TristateUseDefault);
+ var file_stream = FSO.GetFile(file).OpenAsTextStream(ForReading, TristateUseDefault);
//read file fully into var
- allstrings = file_stream.ReadAll();
- //remove all comments. The text starting with \\ (but not with ":\\" it's a links like https://miranda-ng.org/ and ")//" -there is one comment right after needed string)
+ var allstrings = file_stream.ReadAll();
+ //remove all comments. The text starting with \\
+ //(but not with ":\\" it's a link like https://miranda-ng.org/
+ //and ")//" -there is one comment right after needed string)
//and remove multi-line comments, started with /* and ended with */
- text = allstrings.replace(/(?:[^\):])(\/{2}.+?(?=$))|(\s\/\*[\S\s]+?\*\/)/mg, ".");
+ var text = allstrings.replace(/(?:[^\):])(\/{2}.+?(?=$))|(\s\/\*[\S\s]+?\*\/)/mg, ".");
//close file
file_stream.Close();
return text;
@@ -425,22 +445,27 @@ function ReadFile(file) {
//Parsing filelist into stringsarray by parsefunction (ParseSourceFile OR ParseRCFile)
function ParseFiles(filelist, stringsarray, parsefunction) {
+ var current_strings = 0,
+ crap_strings = 0,
+ curfile = {},
+ filetext = "",
+ curfilepath = "";
//create enumerator filesenum from filelist
- filesenum = new Enumerator(filelist);
+ var filesenum = new Enumerator(filelist);
//cycle through file list
while (!filesenum.atEnd()) {
//record into current_strings current length of stringsarray
- var current_strings = stringsarray.length;
+ current_strings = stringsarray.length;
//record into crap_strings current length of crap array
- var crap_strings = crap.length;
+ crap_strings = crap.length;
//curfile is our current file in files enumerator
curfile = filesenum.item();
//read file (filtering comments) into filetext
- var filetext = ReadFile(curfile);
+ filetext = ReadFile(curfile);
//now apply a parsing function to current filetext, and put result into stringsarray
parsefunction(filetext, stringsarray);
//string variable to cut out a trunkPath from absolute path
- curfilepath = new String(curfile);
+ curfilepath = curfile.Path;
//if after parsing file our stringsarray length greater then var "current_strings", so parsed file return some strings. Thus, we need add a comment with filename
if (stringsarray.length > current_strings) {
stringsarray.splice(current_strings, 0, ";file " + curfilepath.substring(trunkPath.length));
@@ -456,6 +481,8 @@ function ParseFiles(filelist, stringsarray, parsefunction) {
//*.RC files line-by-line parser for RC_File, return result into "array"
function ParseRCFile(FileTextVar, array) {
+ var string = "",
+ onestring = "";
var find = /^(?!\/{1,2})\s*(CONTROL|(?:DEF)?PUSHBUTTON|[LRC]TEXT|(?:AUTO)?RADIOBUTTON|GROUPBOX|(?:AUTO)?CHECKBOX|CAPTION|MENUITEM|POPUP)\s*"((?:(?:""[^"]+?"")*[^"]*?)*)"\s*?(,|$|\\)/mgi;
//now make a job, till end of matching regexp
while ((string = find.exec(FileTextVar)) !== null) {
@@ -469,7 +496,7 @@ function ParseRCFile(FileTextVar, array) {
onestring = onestring.replace(/\"{2}/g, "\"");
//check result. If it does not match [a-z] (no any letter in results, such as "..." or "->") it's a crap, break further actions.
if (!onestring.match(/[a-z]/i)) {
- var onestring = "";
+ onestring = "";
}
//if still something in onestring, push to array
if (onestring) {
@@ -480,6 +507,13 @@ function ParseRCFile(FileTextVar, array) {
//Source files C++ (*.h,*.c,*.cpp) and *.pas,*.dpr,*.inc (Pascal) multiline parser for translations using LPGEN() LPGENT() TranslateT() Translate() _T() TranslateW()
function ParseSourceFile(FileTextVar, array) {
+ var string = "",
+ onestring = "",
+ trimedstring = "",
+ noslashstring = "",
+ nofirstlaststring = "",
+ stringtolangpack = "",
+ clearstring = "";
//not store ?: functions LPGEN or LPGENT? or Translate(T or W) or _T, than any unnecessary space \s, than not stored ?: "(" followed by ' or " (stored and used as \1) than \S\s - magic with multiline capture, ending with not stored ?= \1 (we get " or ' after "("), than none or few spaces \x20 followed by )/m=multiline g=global
//var find= /(?:LPGENT?|Translate[TW]?|_T)(?:\s*?\(\s*?L?\s*)(['"])([\S\s]*?)(?=\1,?\x20*?(?:tmp)?\))/mg;
//comment previous line and uncomment following line to output templates without _T() function in source files. Too many garbage from _T()..
@@ -487,7 +521,6 @@ function ParseSourceFile(FileTextVar, array) {
//now make a job, till end of matching regexp
while ((string = find.exec(FileTextVar)) !== null) {
//first, init empty var
- var string;
//replace newlines and all spaces and tabs between two pairs of " or ' with the void string ("") in first [1] subregexp ([\S\s]*?), and Delphi newlines "'#13#10+" replace
onestring = string[1].replace(/["']?(?:\#13\#10)*?\\?\r*\n(?:(?:\x20|\t)*['"])?/g, "");
//trim single-line whitespaces - multi-line parsing catches whitespaces after last " in single-line case
@@ -524,10 +557,10 @@ function filter_T(string) {
//var filter5=/^[\w_:%.\\\/*-]+\.\w+$/g;
//apply filters to our string
- test1 = filter1.test(string);
- test2 = filter2.test(string);
- test3 = filter3.test(string);
- test4 = filter4.test(string);
+ var test1 = filter1.test(string);
+ var test2 = filter2.test(string);
+ var test3 = filter3.test(string);
+ var test4 = filter4.test(string);
//test5=filter5.test(string);
//if match (test1) first filter and NOT match other tests, thus string are good, return this string back.
@@ -538,29 +571,33 @@ function filter_T(string) {
} else {
//in other case, string is a garbage, put into crap array.
crap.push(string);
- return;
}
+ return;
}
function ReadWholeFile(path, codepage) {
- if (codepage === undefined) codepage = "utf-8";
+ if (codepage === undefined) {
+ codepage = "utf-8";
+ }
+ var adTypeText = 2;
var bs = WScript.CreateObject("ADODB.Stream");
- bs.Type = 2; //FileReadTypes.adTypeText;
+ bs.Type = adTypeText;
bs.CharSet = codepage;
bs.Open();
bs.LoadFromFile(path);
- var what = bs.ReadText;
+ var text = bs.ReadText;
//remove all comments. The text starting with \\ (but not with ":\\" it's a links like https://miranda-ng.org/ and ")//" -there is one comment right after needed string)
//and remove multi-line comments, started with /* and ended with */
- what = what.replace(/(?:[^\):])(\/{2}.+?(?=$))|(\s\/\*[\S\s]+?\*\/)/mg, ".");
+ text = text.replace(/(?:[^\):])(\/{2}.+?(?=$))|(\s\/\*[\S\s]+?\*\/)/mg, ".");
bs.Close();
- return what;
+ return text;
}
//Parse Version.h file to get one translated string from "Description" and make a plugin template header.
function ParseVersion_h(pluginfolder, array) {
//cleanup var
- var VersionFile;
+ var VersionFile,
+ allstrings = "";
//Let's try default locations of version.h file;
//Check pluginfolder root.
if (FSO.FileExists(FSO.BuildPath(pluginfolder, "version.h"))) {
@@ -658,10 +695,13 @@ function eliminateDuplicates(arr) {
//Output array of strings into file
function WriteToFile(array, langpack) {
+ var i = 0,
+ len = 0;
//Create file, overwrite if exists
- langpackfile = FSO.CreateTextFile(langpack, overwritefile, unicode);
+ var langpackfile = FSO.CreateTextFile(langpack, overwritefile, unicode);
//Finally, write strings from array to file
- for (i = 0; i <= array.length - 1; i++) {
+ len = array.length - 1;
+ for (i = 0; i <= len; i++) {
langpackfile.WriteLine(array[i]);
}
//Close file
@@ -670,8 +710,11 @@ function WriteToFile(array, langpack) {
//Write UTF-8 file
function WriteToUnicodeFile(array, langpack) {
+ var i = 0,
+ len = 0;
stream.Open();
- for (i = 0; i <= array.length - 1; i++) {
+ len = array.length - 1;
+ for (i = 0; i <= len; i++) {
stream.WriteText(array[i] + "\r\n");
}
stream.SaveToFile(langpack, 2);
@@ -682,11 +725,12 @@ function WriteToUnicodeFile(array, langpack) {
function WriteToUnicodeFileNoBOM(array, filename) {
var UTFStream = WScript.CreateObject("ADODB.Stream");
var BinaryStream = WScript.CreateObject("ADODB.Stream");
- var len = 0;
- var adTypeBinary = 1;
- var adTypeText = 2;
- var adModeReadWrite = 3;
- var adSaveCreateOverWrite = 2;
+ var i = 0,
+ len = 0,
+ adTypeBinary = 1,
+ adTypeText = 2,
+ adModeReadWrite = 3,
+ adSaveCreateOverWrite = 2;
UTFStream.Type = adTypeText;
UTFStream.Mode = adModeReadWrite;
@@ -694,7 +738,7 @@ function WriteToUnicodeFileNoBOM(array, filename) {
UTFStream.Open();
len = array.length - 1;
- for (var i = 0; i <= len; i++) {
+ for (i = 0; i <= len; i++) {
UTFStream.WriteText(array[i] + "\r\n");
}
diff --git a/tools/lpgen/translate.js b/tools/lpgen/translate.js
index a62c838b81..caab61ec65 100644
--- a/tools/lpgen/translate.js
+++ b/tools/lpgen/translate.js
@@ -49,8 +49,9 @@ var popuntranslated = false;
var release = false;
//Path variables
var scriptpath = FSO.GetParentFolderName(WScript.ScriptFullName);
-//crazy way to get path two layers upper "\tools\lpgen\"
-var trunk = FSO.GetFolder(FSO.GetParentFolderName(FSO.GetParentFolderName(scriptpath)));
+var UnTranslatedPath = "";
+//get path two layers upper "\tools\lpgen\"
+var trunkPath = FSO.GetParentFolderName(FSO.GetParentFolderName(scriptpath));
//path to "English" langpack
var langpackenglish = "\\langpacks\\english\\";
//stream - our variable for output UTF-8 files with BOM
@@ -59,30 +60,34 @@ var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 2; // text mode
stream.Charset = "utf-8";
//init translate dictionaries
-CoreTranslateDict = WScript.CreateObject("Scripting.Dictionary");
-DupesTranslateDict = WScript.CreateObject("Scripting.Dictionary");
-LangpackTranslateDict = WScript.CreateObject("Scripting.Dictionary");
+var CoreTranslateDict = WScript.CreateObject("Scripting.Dictionary");
+var DupesTranslateDict = WScript.CreateObject("Scripting.Dictionary");
+var LangpackTranslateDict = WScript.CreateObject("Scripting.Dictionary");
//init arrays
-Translated_Core_Array = new Array();
-UnTranslated_Core_Array = new Array();
-full_langpack_array = new Array();
-release_array = new Array();
+var Translated_Core_Array = [];
+var UnTranslated_Core_Array = [];
+var full_langpack_array = [];
+var release_array = [];
//*********************************************************************************//
// Checking command line parameters *//
//*********************************************************************************//
-// if console param /log: specified, put it to var log. To enable log, specify /log:"yes"
+// if console param /log: specified, put it to var log.
+// To enable log, specify /log:"yes"
if (WScript.Arguments.Named.Item("log")) {
log = true;
}
-// if console param /noref: specified, put it to var noref. To remove ref's to files, specify /noref:"yes"
+// if console param /noref: specified, put it to var noref.
+// To remove ref's to files, specify /noref:"yes"
if (WScript.Arguments.Named.Item("noref")) {
noref = true;
}
-// if console param /untranslated: specified, put it to var untranslated. To output untranslated_* files, specify /untranslated:"yes", or specify a path to output untranslated files folder
+// if console param /untranslated: specified, put it to var untranslated.
+// To output untranslated_* files, specify /untranslated:"yes",
+// or specify a path to output untranslated files folder
if (WScript.Arguments.Named.Item("untranslated")) {
untranslated = true;
UnTranslatedPath = WScript.Arguments.Named.Item("untranslated");
@@ -92,25 +97,25 @@ if (WScript.Arguments.Named.Item("untranslated")) {
}
//if console param /popuntranslated: specified, put it to var popuntranslated
-if (WScript.Arguments.Named.Item("popuntranslated")) {
+if (WScript.Arguments.Named.Exists("popuntranslated")) {
popuntranslated = true;
}
// if console pararm /outpfile:"\path\filename.txt" given, put it to var outfile.
-if (WScript.Arguments.Named.Item("outfile")) {
+if (WScript.Arguments.Named.Exists("outfile")) {
outfile = true;
//path to full langpack file
- full_langpack_file = WScript.Arguments.Named.Item("outfile");
+ var full_langpack_file = WScript.Arguments.Named.Item("outfile");
}
// if console pararm /release:"\path\filename.txt" given, put it to var release.
-if (WScript.Arguments.Named.Item("release")) {
+if (WScript.Arguments.Named.Exists("release")) {
release = true;
//path to full langpack file
- release_langpack_file = WScript.Arguments.Named.Item("release");
+ var release_langpack_file = WScript.Arguments.Named.Item("release");
}
// if param /out specified, build a path and put it into var.
-if (WScript.Arguments.Named.Item("out")) {
+if (WScript.Arguments.Named.Exists("out")) {
var out = WScript.Arguments.Named.Item("out");
var OutPlugins = FSO.BuildPath(out, "Plugins");
var OutWeather = FSO.BuildPath(out, "Weather");
@@ -119,17 +124,21 @@ if (WScript.Arguments.Named.Item("out")) {
CreateFldr(OutWeather);
}
-//If script run by double click, open choose folder dialog to choose plugin folder to parse. If Cancel pressed, quit script.
+//If script run by double click, open choose folder dialog to choose plugin folder to parse.
+//If Cancel pressed, quit script.
if (WScript.FullName.toLowerCase().charAt(WScript.FullName.length - 11) == "w") {
WScript.Echo("Please run from command line!");
WScript.Quit();
}
-//when /sourcelang specified, setup all source files already existed in trunk. Useful for running translate.js from trunk.
-// Currently seldom languages have same files structure, thus it is much more easier to just specify a language folder name, instead of specifying /path, /dupes, /langpack.
+//when /sourcelang specified, setup all source files already existed in trunk.
+//Useful for running translate.js from trunk.
+// Currently seldom languages have same files structure,
+//thus it is much more easier to just specify a language folder name,
+//instead of specifying /path, /dupes, /langpack.
if (WScript.Arguments.Named.Item("sourcelang")) {
var sourcelang = WScript.Arguments.Named.Item("sourcelang");
- var langpack_path = FSO.BuildPath(FSO.BuildPath(trunk, "langpacks"), sourcelang);
+ var langpack_path = FSO.BuildPath(FSO.BuildPath(trunkPath, "langpacks"), sourcelang);
var translated_plugins = FSO.BuildPath(langpack_path, "Plugins");
var translated_weather = FSO.BuildPath(langpack_path, "Weather");
var translated_core = FSO.BuildPath(langpack_path, "=CORE=.txt");
@@ -147,18 +156,19 @@ if (WScript.Arguments.Named.Item("plugin")) {
checkparams();
GenerateDictionaries();
//plugin from command line:
- var cmdline_file = new String(WScript.Arguments.Named.Item("plugin"));
+ var cmdline_file = WScript.Arguments.Named.Item("plugin");
//init array for our file translation and untranslated strings
- var cmdline_file_array = new Array();
- var cmdline_untranslated_array = new Array();
+ var cmdline_file_array = [];
+ var cmdline_untranslated_array = [];
//Output filename variable
- var traslated_cmdline_file = new String(FSO.BuildPath(scriptpath, FSO.GetFileName(cmdline_file)));
- var untranslated_cmdline_file = new String(FSO.BuildPath(scriptpath, "untranslated_" + FSO.GetFileName(cmdline_file)));
+ var traslated_cmdline_file = FSO.BuildPath(scriptpath, FSO.GetFileName(cmdline_file));
+ var untranslated_cmdline_file = FSO.BuildPath(scriptpath, "untranslated_" + FSO.GetFileName(cmdline_file));
//logging
if (log) {
WScript.Echo("translating " + cmdline_file);
}
- //Call TranslateTemplateFile for path specified in command line argument /path:"path/to/template", output result to "scriptpath"
+ //Call TranslateTemplateFile for path specified in command line argument /path:"path/to/template",
+ //output result to "scriptpath"
TranslateTemplateFile(WScript.Arguments.Named.Item("plugin"), cmdline_file_array, cmdline_untranslated_array);
//Output results to scriptpath folder.
WriteToUnicodeFileNoBOM(cmdline_file_array, traslated_cmdline_file);
@@ -205,7 +215,7 @@ if (log) {
WScript.Echo("Translating Core");
}
//Call function for translate core template
-TranslateTemplateFile(FSO.BuildPath(trunk, langpackenglish + "=CORE=.txt"), Translated_Core_Array, UnTranslated_Core_Array);
+TranslateTemplateFile(FSO.BuildPath(trunkPath, langpackenglish + "=CORE=.txt"), Translated_Core_Array, UnTranslated_Core_Array);
//output core file, if /out specified.
if (out) {
OutputFiles(Translated_Core_Array, UnTranslated_Core_Array, "", "=CORE=.txt");
@@ -213,16 +223,16 @@ if (out) {
//Init array of template files
-TemplateFilesArray = new Array();
+var TemplateFilesArray = [];
//Init array of weather.ini translation files
-WeatherFilesArray = new Array();
+var WeatherFilesArray = [];
//Find all template files and put them to array
-FindFiles(FSO.BuildPath(trunk, langpackenglish + "plugins\\"), "\\.txt$", TemplateFilesArray);
+FindFiles(FSO.BuildPath(trunkPath, langpackenglish + "plugins\\"), "\\.txt$", TemplateFilesArray);
//Find all weather.ini template files and add them into array
-FindFiles(FSO.BuildPath(trunk, langpackenglish + "Weather\\"), "\\.txt$", WeatherFilesArray);
+FindFiles(FSO.BuildPath(trunkPath, langpackenglish + "Weather\\"), "\\.txt$", WeatherFilesArray);
//Build enumerator for each file array
-TemplateFilesEnum = new Enumerator(TemplateFilesArray);
-WeatherFilesEnum = new Enumerator(WeatherFilesArray);
+var TemplateFilesEnum = new Enumerator(TemplateFilesArray);
+var WeatherFilesEnum = new Enumerator(WeatherFilesArray);
//Run processing files one-by-one;
ProcessFiles(TemplateFilesEnum);
@@ -251,11 +261,14 @@ if (log) {
//Process files one-by-one using enummerator
function ProcessFiles(FilesEnum) {
+ var TranslatedTemplate = [],
+ UnTranslatedStrings = [],
+ curfile;
//cycle through file list
while (!FilesEnum.atEnd()) {
- //intit Array with translated strings and untranslated stings
- TranslatedTemplate = new Array();
- UnTranslatedStrings = new Array();
+ //empty strings
+ TranslatedTemplate = [];
+ UnTranslatedStrings = [];
//curfile is our current file in files enumerator
curfile = FilesEnum.item();
//Log output to console
@@ -288,12 +301,14 @@ function CreateFldr(FolderPathName) {
//output to files. Checking params, and output file(s).
function OutputFiles(TranslatedArray, UntranslatedArray, FolderName, FileName) {
//clear var outpath
- var outpath;
+ var outpath = "",
+ TraslatedTemplateFile = "",
+ UnTranslatedFile = "";
//outpath is a /out:"path" + FolderName
outpath = FSO.BuildPath(out, FolderName);
//define default path to files in "langpacks\english\plugins"
- TraslatedTemplateFile = trunk + langpackenglish + "plugins\\translated_" + FileName;
- UnTranslatedFile = trunk + langpackenglish + "plugins\\untranslated_" + FileName;
+ TraslatedTemplateFile = trunkPath + langpackenglish + "plugins\\translated_" + FileName;
+ UnTranslatedFile = trunkPath + langpackenglish + "plugins\\untranslated_" + FileName;
//redefine path to files, if /out specified
if (out) {
@@ -303,10 +318,11 @@ function OutputFiles(TranslatedArray, UntranslatedArray, FolderName, FileName) {
//redefine path to files, if FileName is a =CORE=.txt
if (FileName == "=CORE=.txt") {
- TraslatedTemplateFile = trunk + langpackenglish + "translated_" + FileName;
- UnTranslatedFile = trunk + langpackenglish + "untranslated_" + FileName;
+ TraslatedTemplateFile = trunkPath + langpackenglish + "translated_" + FileName;
+ UnTranslatedFile = trunkPath + langpackenglish + "untranslated_" + FileName;
if (out) {
- // if /out:"/path/folder" specified redefine path of translated and untranslated =CORE=.txt file to parent folder of specified path
+ // if /out:"/path/folder" specified
+ // redefine path of translated and untranslated =CORE=.txt file to parent folder of specified path
TraslatedTemplateFile = FSO.BuildPath(outpath, FileName);
// if /untranslated:"yes" specified, redefine untranslated core to parent folder, same as above.
UnTranslatedFile = FSO.BuildPath(outpath, "untranslated_" + FileName);
@@ -338,7 +354,9 @@ function OutputFiles(TranslatedArray, UntranslatedArray, FolderName, FileName) {
}
}
-//when /sourcelang: and /path: are NOT specified, thus we don't have any langpack file(s) to get translated strings. Thus all other job are useless
+//when /sourcelang: and /path: are NOT specified,
+//thus we don't have any langpack file(s) to get translated strings.
+//Thus all other job are useless
function checkparams() {
if (!WScript.Arguments.Named.Exists("langpack") && !WScript.Arguments.Named.Exists("path") && !sourcelang) {
WScript.Echo("you didn't specify /langpack:\"/path/to/langpack.txt\", /path:\"/path/to/plugnis/\" or /sourcelang:\"language\" parameter, there is no files with translated strings!");
@@ -355,6 +373,8 @@ function CheckFileExist(file) {
//Generate DB with translations from Core and Dupes files
function GenerateDictionaries() {
+ var PathToCore = "",
+ PathToDupes = "";
//if /sourcelang:"language" specified, use it for generate dicitionaries
if (sourcelang) {
CheckFileExist(translated_core);
@@ -387,6 +407,10 @@ function GenerateDictionaries() {
//Generate Dictionary with english sting + translated string from file
function GenerateTransalteDict(file, dictionary) {
+ var string = [],
+ key = "",
+ item = "",
+ lowerKey = "";
//if file does not exist, it's a core, we do not need do the job again, so return.
if (!FSO.FileExists(file)) return;
//open file
@@ -394,15 +418,16 @@ function GenerateTransalteDict(file, dictionary) {
stream.LoadFromFile(file);
//read file into var
var translatefiletext = stream.ReadText();
- //"find" - RegularExpression, first string have to start with [ and end with]. Next string - translation
+ //"find" - RegularExpression, first string have to start with [ and end with].
+ //Next string - translation
var find = /(^\[.+?\](?=$))\r?\n(^(?!;file|\r|\n).+?(?=$))/mg;
//While our "find" RegExp return a results, add strings into dictionary.
while ((string = find.exec(translatefiletext)) !== null) {
//first, init empty var
- var string;
- //first match as original string [....], is a key of dictionary, second match is a translation - item of key in dictionary
- var key = string[1];
- var item = string[2];
+ //first match as original string [....], is a key of dictionary,
+ //second match is a translation - item of key in dictionary
+ key = string[1];
+ item = string[2];
//ignore "translations" (wrongly parsed untranslated strings) begining and ending with []
if (item.match(/^\[.*\]$/)) {
continue;
@@ -434,6 +459,9 @@ function GenerateTransalteDict(file, dictionary) {
//Generate array with stirngs from translation template, adding founded translation, if exist.
function TranslateTemplateFile(Template_file, translated_array, untranslated_array) {
+ var englishstring = "",
+ refline = "",
+ headerline = "";
//Init PluginTranslate Dictionary from plugins translate file
var PluginTranslateDict = WScript.CreateObject("Scripting.Dictionary");
//if /sourcelang specified, use it for search plugin translation.
@@ -456,13 +484,15 @@ function TranslateTemplateFile(Template_file, translated_array, untranslated_arr
englishstring = "";
//read on line
var line = stream.ReadText(-2);
- //If we need reference to "; file source\file\path" in template or langpack, put into array every line
+ //If we need reference to "; file source\file\path" in template or langpack,
+ //put into array every line
if (!noref) {
translated_array.push(line);
}
//RegExp matching strings, starting from ";file"
refline = line.match(/^;file.+/);
- //RegExp for match a =CORE=.txt header line "Miranda Language Pack Version 1". If /noref specified, remove this line as well.
+ //RegExp for match a =CORE=.txt header line "Miranda Language Pack Version 1".
+ //If /noref specified, remove this line as well.
headerline = line.match(/^Miranda Language Pack Version 1$/);
//if /noref enabled, check string and if not matched, add to array
if (noref && (!refline && !headerline)) {
@@ -544,7 +574,8 @@ function TranslateTemplateFile(Template_file, translated_array, untranslated_arr
}
}
-//Recourse find all files in "path" with file RegExp mask "name" and return file list into filelistarray
+//Recourse find all files in "path" with file RegExp mask "name"
+//and return file list into filelistarray
function FindFiles(path, name, filelistarray) {
//Init vars
var Folder, Folders, Files, file, filename;
@@ -579,8 +610,12 @@ function FindFiles(path, name, filelistarray) {
//Write UTF-8 file
function WriteToUnicodeFile(array, langpack) {
+ var i = 0,
+ len = 0;
+
stream.Open();
- for (i = 0; i <= array.length - 1; i++) {
+ len = array.length - 1;
+ for (i = 0; i <= len; i++) {
stream.WriteText(array[i] + "\r\n");
}
stream.SaveToFile(langpack, 2);
@@ -591,19 +626,20 @@ function WriteToUnicodeFile(array, langpack) {
function WriteToUnicodeFileNoBOM(array, filename) {
var UTFStream = WScript.CreateObject("ADODB.Stream");
var BinaryStream = WScript.CreateObject("ADODB.Stream");
- var len = 0;
- var adTypeBinary = 1;
- var adTypeText = 2;
- var adModeReadWrite = 3;
- var adSaveCreateOverWrite = 2;
+ var i = 0,
+ len = 0,
+ adTypeBinary = 1,
+ adTypeText = 2,
+ adModeReadWrite = 3,
+ adSaveCreateOverWrite = 2;
UTFStream.Type = adTypeText;
UTFStream.Mode = adModeReadWrite;
UTFStream.Charset = "utf-8";
UTFStream.Open();
-
+
len = array.length - 1;
- for (var i = 0; i <= len; i++) {
+ for (i = 0; i <= len; i++) {
UTFStream.WriteText(array[i] + "\r\n");
}