From 7105dcf75bdd939ca52ba045bc29c536c3f7ba49 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Wed, 28 Nov 2012 14:15:01 +0000 Subject: - lpgen.js updated to relative pathes, langpacks/en: re-generated git-svn-id: http://svn.miranda-ng.org/main/trunk@2539 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- tools/lpgen/lpgen.js | 260 ++++++++++++++++++++++++++------------------------- 1 file changed, 132 insertions(+), 128 deletions(-) (limited to 'tools/lpgen') diff --git a/tools/lpgen/lpgen.js b/tools/lpgen/lpgen.js index 6efcd4e7b6..e7d587d50d 100644 --- a/tools/lpgen/lpgen.js +++ b/tools/lpgen/lpgen.js @@ -26,6 +26,8 @@ var log="no" 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); //core path var core=FSO.BuildPath(trunk,"src"); //protocols path @@ -44,24 +46,24 @@ if (WScript.Arguments.Named.Item("log")) log=WScript.Arguments.Named.Item("log") //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"); - //Open browse for folder dialog - 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" - GeneratePluginTranslate(objFolder.Self.Path,scriptpath); - //if choosing folder canceled, quit immediately - } else WScript.Quit(); + //Create Shell app object + 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); + //process generate translate for chosen folder, else quit. + if (objFolder) { + //Call GeneratePluginTranslate for chosen folder, output result to "scriptpath" + GeneratePluginTranslate(objFolder.Self.Path,scriptpath); + //if choosing folder canceled, quit immediately + } else WScript.Quit(); } //when /plugin: specified, parse only this path and quit if (WScript.Arguments.Named.Item("path")) { - //Call GeneratePluginTranslate for path specified in command line argument /path:"path/to/plugin", output result to "scriptpath" - GeneratePluginTranslate(WScript.Arguments.Named.Item("path"),scriptpath); - //We are done, quit. - WScript.Quit(); + //Call GeneratePluginTranslate for path specified in command line argument /path:"path/to/plugin", output result to "scriptpath" + GeneratePluginTranslate(WScript.Arguments.Named.Item("path"),scriptpath); + //We are done, quit. + WScript.Quit(); } //*********************************************************************************// @@ -85,8 +87,8 @@ sln_stream=FSO.GetFile(trunk+"\\bin10\\mir_full.sln").OpenAsTextStream(ForReadin //find string to translate in rcline by regexp regexpstring=slnline.match(/(?:Project\(\"\{.*?,\x20*?\"\.\.)(\\(:?plugins|protocols).*vcxproj)(?=",)/i); // if exist regexpstring, add to array, adding "trunk" - if (regexpstring) {project_files.push(trunk+regexpstring[1])}; - }; + if (regexpstring) {project_files.push(trunk+regexpstring[1])}; + }; //closing file sln_stream.Close(); //ok, now we have all project files in array, let's add Pascal files to this array. @@ -102,18 +104,18 @@ project_files.push(trunk+"\\plugins\\ShlExt\\shlext.dpr"); project_files.push(trunk+"\\plugins\\Watrack\\watrack.dpr"); project_files.push(trunk+"\\protocols\\mRadio\\mradio.dpr"); -//crete Enumerator with project files from sln and dpr file find results, sorted alphabetically +//create Enumerator with project files from sln and dpr file find results, sorted alphabetically files=new Enumerator(project_files.sort()); while (!files.atEnd()) { - //get file name - file=FSO.GetFile(files.item()); - //get parent folder name - plugfolder=FSO.GetParentFolderName(file); - //call function for plugin folder, output to plugins folder. - GeneratePluginTranslate(plugfolder,langpack_en+"\\Plugins",file); - //WScript.Echo(file); - //next project file - files.moveNext(); + //get file name + file=FSO.GetFile(files.item()); + //get parent folder name + plugfolder=FSO.GetParentFolderName(file); + //call function for plugin folder, output to plugins folder. + GeneratePluginTranslate(plugfolder,langpack_en+"\\Plugins",file); + //WScript.Echo(file); + //next project file + files.moveNext(); }; //*********************************************************************************// @@ -150,50 +152,50 @@ function GenerateCore() { //Make a translation template for plugin in "pluginpath", put generated file into "langpackfilepath" function GeneratePluginTranslate (pluginpath,langpackfilepath,vcxprojfile) { - //init arrays with files to parse - resourcefiles=new Array(); - sourcefiles=new Array(); - //init array with strings from parsed files - foundstrings=new Array(); - //find a name of our plugin - //if vcxprojfile param given, use it - if (vcxprojfile) { - //get plugin name from vcxprojfile - plugin=GetPluginName(vcxprojfile); - } else { - //if vcxprojfile ommited, try to find plugin name from folder files. - plugin=GetPluginName(pluginpath); - }; - //if we didn't find plugin name, return. - if (!plugin) return; - //if log parameter specified, output a log. - if (log=="yes") WScript.Echo("Processing... "+plugin); - //define langpack filename. File will be overwritten! - langpack=langpackfilepath+"\\"+plugin+".txt"; - //get MUUID of plugin and put into array as a first string. - GetMUUID(pluginpath,foundstrings); - //put a name of plugin into array as second string - foundstrings.push(";langpack template for "+plugin); - //find all *.rc files and list files in array - FindFiles(pluginpath,"\\.rc$",resourcefiles); - //find all source files and list files in array - FindFiles(pluginpath,"\\.h$|\\.cpp$|\\.c$|\\.pas$|\\.dpr$|\\.inc$",sourcefiles); - //Parse files "resourcefiles", put result into "foundstrings" using "ParseRCFile" function - ParseFiles(resourcefiles,foundstrings,ParseRCFile); - //Parse files "sourcefiles", put result into "foundstrings" using "ParseSourceFile" function - ParseFiles(sourcefiles,foundstrings,ParseSourceFile); - //Parsing all sources done. If we still have only two strings in array [0] is muuid, [1] - plugin name, so we didn't find any string and generating file is useless, return from function and out log - if (!foundstrings[2]) { - if (log=="yes") WScript.Echo("Nothing to translate in "+plugin); - return; - } - //Now we have all strings in "foundstrings", next we remove duplicate strings from array and put results into "nodupes" - nodupes=eliminateDuplicates(foundstrings); - //logging results - if (log=="yes") WScript.Echo("Writing "+nodupes.length+" strings for "+plugin); - //finally, write "nodupes" array to file - WriteToFile(nodupes,langpack); -}; + //init arrays with files to parse + resourcefiles=new Array(); + sourcefiles=new Array(); + //init array with strings from parsed files + foundstrings=new Array(); + //find a name of our plugin + //if vcxprojfile param given, use it + if (vcxprojfile) { + //get plugin name from vcxprojfile + plugin=GetPluginName(vcxprojfile); + } else { + //if vcxprojfile ommited, try to find plugin name from folder files. + plugin=GetPluginName(pluginpath); + }; + //if we didn't find plugin name, return. + if (!plugin) return; + //if log parameter specified, output a log. + if (log=="yes") WScript.Echo("Processing... "+plugin); + //define langpack filename. File will be overwritten! + langpack=langpackfilepath+"\\"+plugin+".txt"; + //get MUUID of plugin and put into array as a first string. + GetMUUID(pluginpath,foundstrings); + //put a name of plugin into array as second string + foundstrings.push(";langpack template for "+plugin); + //find all *.rc files and list files in array + FindFiles(pluginpath,"\\.rc$",resourcefiles); + //find all source files and list files in array + FindFiles(pluginpath,"\\.h$|\\.cpp$|\\.c$|\\.pas$|\\.dpr$|\\.inc$",sourcefiles); + //Parse files "resourcefiles", put result into "foundstrings" using "ParseRCFile" function + ParseFiles(resourcefiles,foundstrings,ParseRCFile); + //Parse files "sourcefiles", put result into "foundstrings" using "ParseSourceFile" function + ParseFiles(sourcefiles,foundstrings,ParseSourceFile); + //Parsing all sources done. If we still have only two strings in array [0] is muuid, [1] - plugin name, so we didn't find any string and generating file is useless, return from function and out log + if (!foundstrings[2]) { + if (log=="yes") WScript.Echo("Nothing to translate in "+plugin); + return; + } + //Now we have all strings in "foundstrings", next we remove duplicate strings from array and put results into "nodupes" + nodupes=eliminateDuplicates(foundstrings); + //logging results + if (log=="yes") WScript.Echo("Writing "+nodupes.length+" strings for "+plugin); + //finally, write "nodupes" array to file + WriteToFile(nodupes,langpack); +}; //Recourse find all files in "path" with file RegExp mask "name" and return file list into filelistarray function FindFiles (path,name,filelistarray) { @@ -230,18 +232,18 @@ function FindFiles (path,name,filelistarray) { function GetPluginName (folder_or_file) { //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 - 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; - //hope, that project file is first file - plugin_project_file=plugin_project_files[0] - } + //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 + 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; + //hope, that project file is first file + plugin_project_file=plugin_project_files[0] + } //open as text stream plugin_project=plugin_project_file.OpenAsTextStream(ForReading, TristateUseDefault); //read all file into var project @@ -252,9 +254,9 @@ function GetPluginName (folder_or_file) { //return only first item of regexp return filename[1]; } else { - //There is no specified ProjectName, thus use filename without extension as our langpack name - return FSO.GetBaseName(plugin_project_file); - } + //There is no specified ProjectName, thus use filename without extension as our langpack name + return FSO.GetBaseName(plugin_project_file); + } } //Get MUUID of plugin from source file. @@ -271,45 +273,45 @@ function GetMUUID (folder,array) { //curfile is our current file in files enumerator curfile=filesenum.item(); //If file not zero size, read it and do the job - if (FSO.GetFile(curfile).Size!=0) { - //open file as text stream - file_stream=FSO.GetFile(curfile).OpenAsTextStream(ForReading, TristateUseDefault); - //this is a regexp to search UNICODE_AWARE - var find=/(?:UNICODE_AWARE,[\s\S]*?\{)(.+?)(?=\}\s{0,2}\})/g; - //read file fully into var "allstrings" - allstrings=file_stream.ReadAll(); - //search regexp in "allstrings" and put results into var "string" - string=find.exec(allstrings); - //if current file have found UNICODE_AWARE, var "string" exists, so parse it. - if (string) { - //remove spaces, "0x" and "{", in second [1] item of array "string". RegExp "find" have subregexp (.+?), which are our MUUID in "string[1]" - vals=string[1].replace(/0x|\{|\x20/g,""); - //now split values of muuid in "vals" by "," into array "values" - values=vals.split(","); - //we get array of values, if length of this array not equal to 12 values (starting from zero, thus length is 11), that's mean we found something else, not MUUID. Log it and quit, if length is 12, so check it and generate MUUID - if (values.length==11) { - //now check, is there some values, which have omitted zero after 0x, like in alarms: " 0x4dd7762b, 0xd612, 0x4f84, { 0xaa, 0x86, 0x(no_zero_here_)6, 0x8f, 0x17, 0x85, 0x9b, 0x6d}" - //first value in values have to be 8 bytes, while length less than 8, add leading "0" to values[0], - while (values[0].length<8) {values[0]="0"+values[0]}; - //next two values have to be 4 bytes, adding leading zeroes, while length less than 4. - for (i=1;i<=2;i++) { - while (values[i].length<4) { - values[i]="0"+values[i]; - } - } - //other values have to be 2 bytes, same as above, adding zeroes - for (i=3;i<=10;i++) { - while (values[i].length<2) { - values[i]="0"+values[i]; - } - } - //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]+"}"; - }; - }; - //close file - file_stream.Close(); - } + if (FSO.GetFile(curfile).Size!=0) { + //open file as text stream + file_stream=FSO.GetFile(curfile).OpenAsTextStream(ForReading, TristateUseDefault); + //this is a regexp to search UNICODE_AWARE + var find=/(?:UNICODE_AWARE,[\s\S]*?\{)(.+?)(?=\}\s{0,2}\})/g; + //read file fully into var "allstrings" + allstrings=file_stream.ReadAll(); + //search regexp in "allstrings" and put results into var "string" + string=find.exec(allstrings); + //if current file have found UNICODE_AWARE, var "string" exists, so parse it. + if (string) { + //remove spaces, "0x" and "{", in second [1] item of array "string". RegExp "find" have subregexp (.+?), which are our MUUID in "string[1]" + vals=string[1].replace(/0x|\{|\x20/g,""); + //now split values of muuid in "vals" by "," into array "values" + values=vals.split(","); + //we get array of values, if length of this array not equal to 12 values (starting from zero, thus length is 11), that's mean we found something else, not MUUID. Log it and quit, if length is 12, so check it and generate MUUID + if (values.length==11) { + //now check, is there some values, which have omitted zero after 0x, like in alarms: " 0x4dd7762b, 0xd612, 0x4f84, { 0xaa, 0x86, 0x(no_zero_here_)6, 0x8f, 0x17, 0x85, 0x9b, 0x6d}" + //first value in values have to be 8 bytes, while length less than 8, add leading "0" to values[0], + while (values[0].length<8) {values[0]="0"+values[0]}; + //next two values have to be 4 bytes, adding leading zeroes, while length less than 4. + for (i=1;i<=2;i++) { + while (values[i].length<4) { + values[i]="0"+values[i]; + } + } + //other values have to be 2 bytes, same as above, adding zeroes + for (i=3;i<=10;i++) { + while (values[i].length<2) { + values[i]="0"+values[i]; + } + } + //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]+"}"; + }; + }; + //close file + file_stream.Close(); + } //move to next file filesenum.moveNext(); }; @@ -333,8 +335,10 @@ function ParseFiles (filelist,stringsarray, parsefunction) { curfile=filesenum.item(); //now apply a parsing function to current file, and put result into stringsarray parsefunction(curfile,stringsarray); + //string variable to cut out a trunkPath from absolute path + curfilepath=new String(curfile); //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 "+curfile); + if (stringsarray.length>current_strings) stringsarray.splice(current_strings,0,";file "+curfilepath.substring(trunkPath.length)); //move to next file filesenum.moveNext(); }; @@ -394,7 +398,7 @@ function ParseSourceFile (SourceFile,array) { //this is final great regexp ever /(?:LPGENT?|Translate[TW]?|_T)(?:[\s])*?(?:\(['"])([\S\s]*?)(?=["']\x20*?\))/mg //not store ?: functions LPGEN or LPGENT? or Translate(T or W) or _T, than any unnecessary space \s, than not stored ?: "(" followed by ' or " than \S\s - magic with multiline capture, ending with not stored ?= " or ', than none or few spaces \x20 followed by )/m=multiline g=global var find= /(?:LPGENT?|Translate[TW]?|_T)(?:[\s])*?(?:\(['"])([\S\s]*?)(?=["'],?\x20*?(?:tmp)?\))/mg; - //read file fully into var + //read file fully into var allstrings=sourcefile_stream.ReadAll(); //now make a job, till end of matching regexp while ((string = find.exec(allstrings)) != null) { @@ -402,8 +406,8 @@ function ParseSourceFile (SourceFile,array) { var string; //replace newlines with \r\n in second [1] subregexp ([\S\s]*?), Delphi newlines "'#13#10+" also replace onestring=string[1].replace(/'?(\#13\#10)*?\+?\r\n(\x20*?\')?/g,"\\r\\n"); - //remove escape slashes before ' and " - stringtolangpack=onestring.replace(/\\(['"])/g,"$1"); + //remove escape slashes before ' and " + stringtolangpack=onestring.replace(/\\(['"])/g,"$1"); //if our string still exist, and length more than 2 symbol (nothing to translate if only two symbols, well, except No and OK, but they are in core. But dozens crap with variables are filtered) if (stringtolangpack.length>2) { //finally put string into array including cover [] -- cgit v1.2.3