summaryrefslogtreecommitdiff
path: root/tools/lpgen/lpgen.js
diff options
context:
space:
mode:
authorGoraf <22941576+Goraf@users.noreply.github.com>2017-12-09 14:11:31 +0100
committerGoraf <22941576+Goraf@users.noreply.github.com>2017-12-09 14:24:18 +0100
commitfb22928811b911b08fee2b5af0154049195f829f (patch)
tree87b0a51fc0c8bb8f902d25699d784b3eaebcf663 /tools/lpgen/lpgen.js
parent01e579c9aad7ce9d6a6e0418830746fa8b7152d8 (diff)
lpgen: Save files as UTF-8 without BOM
Diffstat (limited to 'tools/lpgen/lpgen.js')
-rw-r--r--tools/lpgen/lpgen.js38
1 files changed, 36 insertions, 2 deletions
diff --git a/tools/lpgen/lpgen.js b/tools/lpgen/lpgen.js
index 99917c94a6..20f885961b 100644
--- a/tools/lpgen/lpgen.js
+++ b/tools/lpgen/lpgen.js
@@ -209,7 +209,7 @@ function GenerateCore() {
//concatenate head and nodupes
corestrings = corehead.concat(nodupes);
//finally, write "nodupes" array to file
- WriteToUnicodeFile(corestrings, corefile);
+ WriteToUnicodeFileNoBOM(corestrings, corefile);
}
//Make a translation template for plugin in "pluginpath", put generated file into "langpackfilepath"
@@ -279,7 +279,7 @@ function GeneratePluginTranslate(pluginpath, langpackfilepath, vcxprojfile) {
WScript.Echo("Writing " + plugintemplate.length + " strings for " + plugin);
}
//finally, write "nodupes" array to file
- WriteToUnicodeFile(plugintemplate, langpack);
+ WriteToUnicodeFileNoBOM(plugintemplate, langpack);
}
//Recourse find all files in "path" with file RegExp mask "name" and return file list into filelistarray
@@ -677,3 +677,37 @@ function WriteToUnicodeFile(array, langpack) {
stream.SaveToFile(langpack, 2);
stream.Close();
}
+
+//Write file as UTF-8 without BOM
+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;
+
+ UTFStream.Type = adTypeText;
+ UTFStream.Mode = adModeReadWrite;
+ UTFStream.Charset = "utf-8";
+ UTFStream.Open();
+
+ len = array.length - 1;
+ for (var i = 0; i <= len; i++) {
+ UTFStream.WriteText(array[i] + "\r\n");
+ }
+
+ UTFStream.Position = 3; // skip BOM
+ BinaryStream.Type = adTypeBinary;
+ BinaryStream.Mode = adModeReadWrite;
+ BinaryStream.Open();
+
+ // Strips BOM (first 3 bytes)
+ UTFStream.CopyTo(BinaryStream);
+
+ BinaryStream.SaveToFile(filename, adSaveCreateOverWrite);
+ BinaryStream.Flush();
+ BinaryStream.Close();
+ UTFStream.Close();
+}