Resolve charset .idtx/.idt confusion

NMake inline files are always created using ACP. The "1252" in the .idtx
header has no effect on this. However, we must encode the .idt files
using correct charset/codepage regardless the ACP being used on the
building machine.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2021-11-19 13:22:28 +01:00
parent f68cad560a
commit 4c8ef11e9b
5 changed files with 35 additions and 29 deletions

Binary file not shown.

6
IDT.js
View File

@ -93,7 +93,7 @@ function IDT(path)
// Parse meta info // Parse meta info
var line = parseRow(dat.ReadText(adReadLine).split("\t")), i = 0; var line = parseRow(dat.ReadText(adReadLine).split("\t")), i = 0;
this.codepage = parseInt(line[i], 10); this.codepage = parseInt(line[i], 10);
if (isNaN(this.codepage)) this.codepage = 1252; else i++; if (isNaN(this.codepage)) this.codepage = 0; else i++;
this.table = line[i++]; this.table = line[i++];
this.key = line.slice(i); this.key = line.slice(i);
for (var i in this.key) { for (var i in this.key) {
@ -315,8 +315,8 @@ IDT.prototype.save = function(path)
dat.WriteText(buildRow(this.columns).join("\t"), adWriteLine); dat.WriteText(buildRow(this.columns).join("\t"), adWriteLine);
dat.WriteText(buildRow(this.types ).join("\t"), adWriteLine); dat.WriteText(buildRow(this.types ).join("\t"), adWriteLine);
var meta = new Array(); var meta = new Array();
if (WScript.Arguments.Named.Exists("CP")) if ("codepage" in this)
meta.push(WScript.Arguments.Named("CP")); meta.push(this.codepage.toString(10));
meta.push(this.table); meta.push(this.table);
for (var key in this.key) for (var key in this.key)
meta.push(this.columns[this.key[key]]); meta.push(this.columns[this.key[key]]);

23
MSI.wsf
View File

@ -568,7 +568,7 @@
<description>Translate IDT file.</description> <description>Translate IDT file.</description>
<unnamed name="&lt;destination.idt&gt;" helpstring="Translated IDT file" required="true"/> <unnamed name="&lt;destination.idt&gt;" helpstring="Translated IDT file" required="true"/>
<unnamed name="&lt;source.idt&gt;" helpstring="Original IDT file" required="true"/> <unnamed name="&lt;source.idt&gt;" helpstring="Original IDT file" required="true"/>
<unnamed name="&lt;catalogue.po&gt;" helpstring="PO catalog file with translations" required="true"/> <unnamed name="&lt;catalogue.po&gt;" helpstring="PO catalog file with translations" required="false"/>
<named name="CP" helpstring="Output code page" type="string" required="false"/> <named name="CP" helpstring="Output code page" type="string" required="false"/>
</runtime> </runtime>
<reference object="ADODB.Stream"/> <reference object="ADODB.Stream"/>
@ -577,7 +577,7 @@
<script language="JScript" src="PO.js"/> <script language="JScript" src="PO.js"/>
<script language="JScript" src="String.js"/> <script language="JScript" src="String.js"/>
<script language="JScript"><![CDATA[ <script language="JScript"><![CDATA[
if (WScript.Arguments.Unnamed.Length < 3) { if (WScript.Arguments.Unnamed.Length < 2) {
WScript.Arguments.ShowUsage(); WScript.Arguments.ShowUsage();
WScript.Quit(1); WScript.Quit(1);
} }
@ -587,16 +587,17 @@
idt_dst_path = WScript.Arguments.Unnamed(0); idt_dst_path = WScript.Arguments.Unnamed(0);
try { try {
// Open and parse source IDT file and PO catalogue. // Open and parse source IDT file.
var var idt_src = new IDT(WScript.Arguments.Unnamed(1));
idt_src = new IDT(WScript.Arguments.Unnamed(1)),
po = new POCatalog(WScript.Arguments.Unnamed(2));
// Translate records. if (WScript.Arguments.Unnamed.Length >= 3) {
for (var key in idt_src.data) { // Translate records.
for (var col in idt_src.types) { var po = new POCatalog(WScript.Arguments.Unnamed(2));
if (idt_src.isLocalizable(col) && idt_src.data[key][col] != "") for (var key in idt_src.data) {
idt_src.data[key][col] = po.translate(idt_src.data[key][col]); for (var col in idt_src.types) {
if (idt_src.isLocalizable(col) && idt_src.data[key][col] != "")
idt_src.data[key][col] = po.translate(idt_src.data[key][col]);
}
} }
} }

View File

@ -143,21 +143,26 @@ function Time2Str(date)
function CodePageToId(codepage) function CodePageToId(codepage)
{ {
switch (codepage) { switch (codepage) {
case 932 : return "shift-jis"; case 0: {
case 936 : return "gb2312"; var wsh = new ActiveXObject("WScript.Shell");
case 949 : return "euc-kr"; return CodePageToId(parseInt(wsh.RegRead("HKLM\\SYSTEM\\CurrentControlSet\\Control\\Nls\\CodePage\\ACP"), 10));
case 950 : return "big5"; }
case 874 : case 932 : return "shift-jis";
case 1250: case 936 : return "gb2312";
case 1251: case 949 : return "euc-kr";
case 1252: case 950 : return "big5";
case 1253: case 874 :
case 1254: case 1250 :
case 1255: case 1251 :
case 1256: case 1252 :
case 1257: case 1253 :
case 1258: return "windows-" + codepage; case 1254 :
default : throw new Error("Unsupported code page."); case 1255 :
case 1256 :
case 1257 :
case 1258 : return "windows-" + codepage.toString(10);
case 65001: return "utf-8";
default : throw new Error("Unsupported code page.");
} }
} }

Binary file not shown.