From b846962f49ddd1d793d3de58acead9b01fcac27e Mon Sep 17 00:00:00 2001 From: Takashi Sawanaka Date: Thu, 15 Feb 2024 08:25:53 +0900 Subject: [PATCH] - Rewrite the script written in VBScript in JScript - Remove support for po file encoding other than UTF-8. --- .gitattributes | 1 + FRHED/LangArray.cpp | 21 +- FRHED/LangArray.h | 1 - FRHED/PreLink.bat | 4 +- Translations/Frhed/CreateMasterPotFile.js | 329 ++++++++++++++++ Translations/Frhed/CreateMasterPotFile.vbs | 357 ------------------ .../Frhed/UpdatePoFilesFromPotFile.js | 239 ++++++++++++ .../Frhed/UpdatePoFilesFromPotFile.vbs | 291 -------------- Translations/Frhed/de.po | 6 - Translations/Frhed/en-US.pot | 15 +- Translations/Frhed/fr.po | 11 +- Translations/Frhed/gl.po | 6 - Translations/Frhed/ja.po | 6 - Translations/Frhed/nl.po | 6 - Translations/Frhed/pl.po | 6 - Translations/Frhed/sk.po | 6 - Translations/Frhed/sl.po | 6 - 17 files changed, 583 insertions(+), 728 deletions(-) create mode 100644 .gitattributes create mode 100644 Translations/Frhed/CreateMasterPotFile.js delete mode 100644 Translations/Frhed/CreateMasterPotFile.vbs create mode 100644 Translations/Frhed/UpdatePoFilesFromPotFile.js delete mode 100644 Translations/Frhed/UpdatePoFilesFromPotFile.vbs diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..8f31284 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +Translations/**/*.po text eol=lf diff --git a/FRHED/LangArray.cpp b/FRHED/LangArray.cpp index 72952cf..7c891b5 100644 --- a/FRHED/LangArray.cpp +++ b/FRHED/LangArray.cpp @@ -73,7 +73,6 @@ void LangArray::StringData::Unshare(char *data) LangArray::LangArray() : m_hLangDll(0) -, m_codepage(0) , m_langid(0) { } @@ -99,10 +98,9 @@ void LangArray::ClearAll() /** * @brief Convert C style \\nnn, \\r, \\n, \\t etc into their indicated characters. - * @param [in] codepage Codepage to use in conversion. * @param [in,out] s String to convert. */ -static size_t unslash(unsigned codepage, char *s) +static size_t unslash(char *s) { char *p = s; char *q = p; @@ -148,7 +146,7 @@ static size_t unslash(unsigned codepage, char *s) // fall through default: *p = c; - if ((c & 0x80) && IsDBCSLeadByteEx(codepage, c)) + if ((c & 0x80) && IsDBCSLeadByteEx(CP_UTF8, c)) *++p = *r++; q = r; } @@ -303,8 +301,6 @@ BOOL LangArray::Load(HINSTANCE hMainInstance, LANGID langid, LPCTSTR langdir) if (char *q = strchr(p, ':')) { int line = strtol(q + 1, &q, 10); - if (line == 367) - line = line; lines.add(line); --unresolved; } @@ -341,7 +337,7 @@ BOOL LangArray::Load(HINSTANCE hMainInstance, LANGID langid, LPCTSTR langdir) ps = 0; if (msgstr.length() == 0) msgstr.append(msgid.c_str(), msgid.length()); - msgstr.resize(unslash(m_codepage, msgstr.pointer())); + msgstr.resize(unslash(msgstr.pointer())); if (int i = lines.size()) { StringData *psd = StringData::Create(msgstr.c_str(), msgstr.length()); @@ -366,11 +362,6 @@ BOOL LangArray::Load(HINSTANCE hMainInstance, LANGID langid, LPCTSTR langdir) } while (i); } lines.clear(); - if (strcmp(directive.c_str(), "Codepage") == 0) - { - m_codepage = strtol(msgstr.c_str(), &p, 10); - directive.clear(); - } msgid.clear(); msgstr.clear(); } @@ -399,7 +390,7 @@ PTSTR LangArray::TranslateString(int line) if (UINT len = static_cast(strlen(s))) { ws = SysAllocStringLen(0, len); - len = MultiByteToWideChar(m_codepage, 0, s, -1, ws, len + 1); + len = MultiByteToWideChar(CP_UTF8, 0, s, -1, ws, len + 1); SysReAllocStringLen(&ws, ws, len - 1); } } @@ -414,11 +405,11 @@ PTSTR LangArray::TranslateString(int line) if (UINT len = static_cast(strlen(s))) { unsigned codepage = GetACP(); - if (m_codepage != codepage) + if (CP_UTF8 != codepage) { // Attempt to convert to UI codepage BSTR ws = SysAllocStringLen(0, len); - len = MultiByteToWideChar(m_codepage, 0, s, -1, ws, len + 1); + len = MultiByteToWideChar(CP_UTF8, 0, s, -1, ws, len + 1); if (len) { SysReAllocStringLen(&ws, ws, len - 1); diff --git a/FRHED/LangArray.h b/FRHED/LangArray.h index c7007ad..17611b3 100644 --- a/FRHED/LangArray.h +++ b/FRHED/LangArray.h @@ -37,7 +37,6 @@ class LangArray : protected Vector static void Unshare(char *); }; HMODULE m_hLangDll; - unsigned m_codepage; LANGID m_langid; LangArray(); ~LangArray(); diff --git a/FRHED/PreLink.bat b/FRHED/PreLink.bat index cfe6fdb..2571289 100644 --- a/FRHED/PreLink.bat +++ b/FRHED/PreLink.bat @@ -4,8 +4,8 @@ echo $(IntDir) = %1 echo $(TargetPath) = %2 echo $(PlatformTarget) = %3 cd ..\Translations\Frhed -cscript CreateMasterPotFile.vbs -cscript UpdatePoFilesFromPotFile.vbs +cscript CreateMasterPotFile.js +cscript UpdatePoFilesFromPotFile.js cd ..\..\FRHED rc "/fo%~1\lang.res" /i.. ..\Translations\Frhed\heksedit.rc mkdir "%~2\..\Languages" diff --git a/Translations/Frhed/CreateMasterPotFile.js b/Translations/Frhed/CreateMasterPotFile.js new file mode 100644 index 0000000..a7960d9 --- /dev/null +++ b/Translations/Frhed/CreateMasterPotFile.js @@ -0,0 +1,329 @@ +//// +// This script creates the master POT file (en-US.pot). +// +// Copyright (C) 2007 by Tim Gerundt +// Released under the "GNU General Public License" + +var ForReading = 1; + +var NO_BLOCK = 0; +var MENU_BLOCK = 1; +var DIALOGEX_BLOCK = 2; +var STRINGTABLE_BLOCK = 3; +var VERSIONINFO_BLOCK = 4; +var ACCELERATORS_BLOCK = 5; +var TEXTINCLUDE_BLOCK = 6; +var BITMAP_BLOCK = 7; + +var oFSO = new ActiveXObject("Scripting.FileSystemObject"); + +var bRunFromCmd = false; +if (oFSO.GetFileName(WScript.FullName).toLowerCase() === "cscript.exe") { + bRunFromCmd = true; +} + +Main(); + +//// +// ... +function Main() { + var StartTime = new Date().getTime(); + + InfoBox("Creating POT file from heksedit.rc...", 3); + + var bNecessary = true; + if (oFSO.FileExists("en-US.pot") && oFSO.FileExists("heksedit.rc")) { //If the POT and RC file exists... + bNecessary = GetArchiveBit("../../Frhed/heksedit.rc") || GetArchiveBit("en-US.pot") || GetArchiveBit("heksedit.rc"); //RCs or POT file changed? + } + + if (bNecessary) { //If update necessary... + var oStrings = GetStringsFromRcFile("../../Frhed/heksedit.rc"); + CreateMasterPotFile("en-US.pot", oStrings); + SetArchiveBit("../../Frhed/heksedit.rc", false); + SetArchiveBit("en-US.pot", false); + SetArchiveBit("heksedit.rc", false); + for (var it = new Enumerator(oFSO.GetFolder(".").Files); !it.atEnd(); it.moveNext()) { //For all files in the current folder... + var oFile = it.item(); + if (oFSO.GetExtensionName(oFile.Name).toLowerCase() === "po") { //If a PO file... + SetArchiveBit(oFile.Path, true); + } + } + + var EndTime = new Date().getTime(); + var Seconds = (EndTime - StartTime) / 1000.0; + + InfoBox("POT file created, after " + Seconds + " second(s).", 10); + } else { //If update NOT necessary... + InfoBox("POT file already up-to-date.", 10); + } +} + +function replacei(text, find, replace, ignorecase) { + if (!ignorecase) + return text.split(find).join(replace); + var textLower = text.toLowerCase(); + var findLower = find.toLowerCase(); + var pos = textLower.length; + while (pos >= 0 && (pos = textLower.lastIndexOf(findLower, pos)) >= 0) { + text = text.substr(0, pos) + replace + text.substr(pos + findLower.length); + pos--; + } + return text; +} + +//// +// ... +function GetStringsFromRcFile(sRcFilePath) { + var fContinuation = false; + var oBlacklist = GetStringBlacklist("StringBlacklist.txt"); + var oStrings = {}; + if (oFSO.FileExists(sRcFilePath)) { //If the RC file exists... + var sRcFileName = oFSO.GetFileName(sRcFilePath); + var iLine = 0; + var iBlockType = NO_BLOCK; + var oRcFile = oFSO.OpenTextFile(sRcFilePath, ForReading); + var oLcFile = oFSO.CreateTextFile("heksedit.rc", true); + while (!oRcFile.AtEndOfStream) { //For all lines... + var sLcLine = oRcFile.ReadLine(); + var sLine = sLcLine.replace(/^\s+|\s+$/g, ""); + sLine = sLine.replace(/\t/g, " "); + iLine++; + + var sReference = sRcFileName + ":" + iLine; + var sString = ""; + var sComment = ""; + var sContext = ""; + + if (fContinuation) { + // Nothing to do + } else if (sLine.substring(0, 2) === "//") { //If comment line... + sLine = ""; + //IGNORE FOR SPEEDUP! + } else if (sLine.indexOf(" TEXTINCLUDE") >= 0) { //TEXTINCLUDE... + iBlockType = TEXTINCLUDE_BLOCK + } else if (sLine.indexOf(" MENU") >= 0 && sLine.indexOf("IDR_") >= 0) { //MENU... + iBlockType = MENU_BLOCK; + } else if (sLine.indexOf(" DIALOG") >= 0) { //DIALOG(EX)... + iBlockType = DIALOGEX_BLOCK; + } else if (sLine === "STRINGTABLE") { //STRINGTABLE... + iBlockType = STRINGTABLE_BLOCK; + } else if (sLine.indexOf(" VERSIONINFO") >= 0) { //VERSIONINFO... + iBlockType = VERSIONINFO_BLOCK; + } else if (sLine.indexOf(" ACCELERATORS") >= 0) { //ACCELERATORS... + iBlockType = ACCELERATORS_BLOCK; + } else if (sLine.indexOf(" BITMAP ") >= 0) { //BITMAP... + iBlockType = BITMAP_BLOCK; + sLcLine = "//" + sLcLine; + } else if (sLine === "BEGIN") { //BEGIN... + //IGNORE FOR SPEEDUP! + } else if (sLine === "END") { //END... + if (iBlockType === STRINGTABLE_BLOCK || iBlockType === TEXTINCLUDE_BLOCK) { //If inside STRINGTABLE or TEXTINCLUDE... + iBlockType = NO_BLOCK; + } + } else if (sLine !== "") { //If NOT empty line... + switch (iBlockType) { + case NO_BLOCK: + var oMatch0 = /LANGUAGE (LANG_\w*, SUBLANG_\w*)/.exec(sLine); + if (oMatch0) { //LANGUAGE... + sString = oMatch0[1]; + sComment = "LANGUAGE, SUBLANGUAGE"; + } + break; + + case MENU_BLOCK: + case DIALOGEX_BLOCK: + case STRINGTABLE_BLOCK: + if (sLine.indexOf("\"") >= 0) { //If quote found (for speedup)... + //-------------------------------------------------------------------------------- + // Replace 1st string literal only - 2nd string literal specifies control class! + //-------------------------------------------------------------------------------- + var oMatch2 = /"((?:""|[^"])*)"/.exec(sLine); + if (oMatch2) { //String... + var sTemp = oMatch2[1]; + if (sTemp !== "" && !(sTemp in oBlacklist)) { //If NOT blacklisted... + sLcLine = replacei(sLcLine, "\"" + sTemp + "\"", "\"" + sReference + "\""); + sString = sTemp.replace(/\"\"/g, "\\\""); + var oMatch3 = /\/\/#\. (.*?)$/.exec(sLine); + var oMatch4 = /\/\/msgctxt (.*?)$/.exec(sLine); + if (oMatch3) { //If found a comment for the translators... + sComment = oMatch3[1].replace(/^\s+|\s+$/g, ""); + } else if (oMatch4) { //If found a context for the translation... + sContext = oMatch4[1].replace(/^\s+|\s+$/g, ""); + sComment = sContext; + } + } + } + } + break; + + case VERSIONINFO_BLOCK: + var oMatch5 = /BLOCK "([0-9A-F]+)"/.exec(sLine); + var oMatch6 = /VALUE "Comments", "(.*?)\\?0?"/.exec(sLine); + var oMatch7 = /VALUE "Translation", (.*?)$/.exec(sLine); + if (oMatch5) { //StringFileInfo.Block... + sString = oMatch5[1]; + sComment = "StringFileInfo.Block"; + } else if (oMatch6) { //StringFileInfo.Comments... + sString = oMatch6[1]; + sComment = "You should use a string like \"Translated by \" followed by the translator names for this string. It is ONLY VISIBLE in the StringFileInfo.Comments property from the final resource file!"; + } else if (oMatch7) { //VarFileInfo.Translation... + sString = oMatch7[1]; + sComment = "VarFileInfo.Translation"; + } + break; + } + } + + if (sString !== "") { + var sKey = sContext + sString; + var oString = { "Comment": "", "References": "", "Context": "", "Id": "", "Str": "" }; + if (sKey in oStrings) { //If the key is already used... + oString = oStrings[sKey]; + } + if (sComment !== "") { + oString.Comment = sComment; + } + if (oString.References !== "") { + oString.References = oString.References + "\t" + sReference; + } else { + oString.References = sReference; + } + oString.Context = sContext; + oString.Id = sString; + oString.Str = ""; + + if (sKey in oStrings) { //If the key is already used... + oStrings[sKey] = oString; + } else { //If the key is NOT already used... + oStrings[sContext + sString] = oString; + } + } + oLcFile.WriteLine(sLcLine); + fContinuation = (sLine !== "") && ",|".indexOf(sLine.substring(sLine.length - 1)) >= 0; + } + oLcFile.WriteLine("en-US.pot RCDATA \"en-US.pot\""); + oRcFile.Close(); + oLcFile.Close(); + } + return oStrings; +} + +//// +// ... +function GetStringBlacklist(sTxtFilePath) { + var oBlacklist = {}; + if (oFSO.FileExists(sTxtFilePath)) { //If the blacklist file exists... + var oTxtFile = oFSO.OpenTextFile(sTxtFilePath, ForReading); + while (!oTxtFile.AtEndOfStream) { //For all lines... + var sLine = oTxtFile.ReadLine().replace(/^\s+|\s+$/g, ""); + if (sLine !== "") { + if (!(sLine in oBlacklist)) { //If the key is NOT already used... + oBlacklist[sLine] = true; + } + } + } + oTxtFile.Close(); + } + return oBlacklist; +} + +//// +// ... +function CreateMasterPotFile(sPotPath, oStrings) { + var oPotFile = oFSO.CreateTextFile(sPotPath, true); + + oPotFile.WriteLine("# This file is part of Frhed "); + oPotFile.WriteLine("# Released under the \"GNU General Public License\""); + oPotFile.WriteLine("#"); + oPotFile.WriteLine("msgid \"\""); + oPotFile.WriteLine("msgstr \"\""); + oPotFile.WriteLine("\"Project-Id-Version: Frhed\\n\""); + oPotFile.WriteLine("\"Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?group_id=13216&atid=113216\\n\""); + oPotFile.WriteLine("\"POT-Creation-Date: " + GetPotCreationDate() + "\\n\""); + oPotFile.WriteLine("\"PO-Revision-Date: \\n\""); + oPotFile.WriteLine("\"Last-Translator: \\n\""); + oPotFile.WriteLine("\"Language-Team: English \\n\""); + oPotFile.WriteLine("\"MIME-Version: 1.0\\n\""); + oPotFile.WriteLine("\"Content-Type: text/plain; charset=UTF-8\\n\""); + oPotFile.WriteLine("\"Content-Transfer-Encoding: 8bit\\n\""); + oPotFile.WriteLine("\"X-Poedit-Language: English\\n\""); + oPotFile.WriteLine("\"X-Poedit-SourceCharset: UTF-8\\n\""); + oPotFile.WriteLine("\"X-Poedit-Basepath: ../../FRHED\\n\""); + //oPotFile.WriteLine("\"X-Generator: CreateMasterPotFile.js\\n\""); + oPotFile.WriteLine(""); + for (var sKey in oStrings) { //For all strings... + var oString = oStrings[sKey]; + if (oString.Comment !== "") { //If comment exists... + oPotFile.WriteLine("#. " + oString.Comment); + } + var aReferences = oString.References.split("\t"); + for (var i = 0; i < aReferences.length; i++) { //For all references... + oPotFile.WriteLine("#: " + aReferences[i]); + } + oPotFile.WriteLine("#, c-format"); + if (oString.Context !== "") { //If context exists... + oPotFile.WriteLine("msgctxt \"" + oString.Context + "\""); + } + oPotFile.WriteLine("msgid \"" + oString.Id + "\""); + oPotFile.WriteLine("msgstr \"\""); + oPotFile.WriteLine(""); + } + oPotFile.Close(); +} + +//// +// ... +function GetPotCreationDate() { + var oNow = new Date(); + var sYear = oNow.getFullYear(); + var sMonth = oNow.getMonth() + 1; + if (sMonth < 10) { sMonth = "0" + sMonth; } + var sDay = oNow.getDate(); + if (sDay < 10) { sDay = "0" + sDay; } + var sHour = oNow.getHours(); + if (sHour < 10) { sHour = "0" + sHour; } + var sMinute = oNow.getMinutes(); + if (sMinute < 10) { sMinute = "0" + sMinute; } + + return sYear + "-" + sMonth + "-" + sDay + " " + sHour + ":" + sMinute + "+0000"; +} + +//// +// ... +function InfoBox(sText, iSecondsToWait) { + if (!bRunFromCmd) { //If run from command line... + var oShell = WScript.CreateObject("WScript.Shell"); + return oShell.Popup(sText, iSecondsToWait, WScript.ScriptName, 64); + } else { //If NOT run from command line... + WScript.Echo(sText); + } +} + +//// +// ... +function GetArchiveBit(sFilePath) { + if (oFSO.FileExists(sFilePath)) { //If the file exists... + var oFile = oFSO.GetFile(sFilePath); + if (oFile.Attributes & 32) { //If archive bit set... + return true; + } + } + return false; +} + +//// +// ... +function SetArchiveBit(sFilePath, bValue) { + if (oFSO.FileExists(sFilePath)) { //If the file exists... + var oFile = oFSO.GetFile(sFilePath); + if (oFile.Attributes & 32) { //If archive bit set... + if (!bValue) { + oFile.Attributes -= 32; + } + } else { //If archive bit NOT set... + if (bValue) { + oFile.Attributes += 32; + } + } + } +} diff --git a/Translations/Frhed/CreateMasterPotFile.vbs b/Translations/Frhed/CreateMasterPotFile.vbs deleted file mode 100644 index f84e884..0000000 --- a/Translations/Frhed/CreateMasterPotFile.vbs +++ /dev/null @@ -1,357 +0,0 @@ -Option Explicit -'' -' This script creates the master POT file (en-US.pot). -' -' Copyright (C) 2007 by Tim Gerundt -' Released under the "GNU General Public License" -' -' ID line follows -- this is updated by SVN -' $Id: CreateMasterPotFile.vbs 473 2009-04-09 16:30:19Z gerundt $ - -Const ForReading = 1 - -Const NO_BLOCK = 0 -Const MENU_BLOCK = 1 -Const DIALOGEX_BLOCK = 2 -Const STRINGTABLE_BLOCK = 3 -Const VERSIONINFO_BLOCK = 4 -Const ACCELERATORS_BLOCK = 5 -Const TEXTINCLUDE_BLOCK = 6 -Const BITMAP_BLOCK = 7 - -Dim oFSO, bRunFromCmd - -Set oFSO = CreateObject("Scripting.FileSystemObject") - -bRunFromCmd = False -If LCase(oFSO.GetFileName(Wscript.FullName)) = "cscript.exe" Then - bRunFromCmd = True -End If - -Call Main - -'' -' ... -Sub Main - Dim oStrings, sCodePage - Dim StartTime, EndTime, Seconds - Dim bNecessary, oFile - - StartTime = Time - - InfoBox "Creating POT file from heksedit.rc...", 3 - - bNecessary = True - If (oFSO.FileExists("en-US.pot") = True) And (oFSO.FileExists("heksedit.rc") = True) Then 'If the POT and RC file exists... - bNecessary = GetArchiveBit("../../Frhed/heksedit.rc") Or GetArchiveBit("en-US.pot") Or GetArchiveBit("heksedit.rc") 'RCs or POT file changed? - End If - - If (bNecessary = True) Then 'If update necessary... - Set oStrings = GetStringsFromRcFile("../../Frhed/heksedit.rc", sCodePage) - CreateMasterPotFile "en-US.pot", oStrings, sCodePage - SetArchiveBit "../../Frhed/heksedit.rc", False - SetArchiveBit "en-US.pot", False - SetArchiveBit "heksedit.rc", False - For Each oFile In oFSO.GetFolder(".").Files 'For all files in the current folder... - If (LCase(oFSO.GetExtensionName(oFile.Name)) = "po") Then 'If a PO file... - SetArchiveBit oFile.Path, True - End If - Next - - EndTime = Time - Seconds = DateDiff("s", StartTime, EndTime) - - InfoBox "POT file created, after " & Seconds & " second(s).", 10 - Else 'If update NOT necessary... - InfoBox "POT file already up-to-date.", 10 - End If -End Sub - -'' -' ... -Class CString - Dim Comment, References, Context, Id, Str -End Class - -'' -' ... -Function GetStringsFromRcFile(ByVal sRcFilePath, ByRef sCodePage) - Dim oBlacklist, oStrings, oString, oRcFile, sLine, iLine - Dim sRcFileName, iBlockType, sReference, sString, sComment, sContext, oMatch, sTemp, sKey - Dim oLcFile, sLcLine, fContinuation - - Set oBlacklist = GetStringBlacklist("StringBlacklist.txt") - - Set oStrings = CreateObject("Scripting.Dictionary") - - If (oFSO.FileExists(sRcFilePath) = True) Then 'If the RC file exists... - sRcFileName = oFSO.GetFileName(sRcFilePath) - iLine = 0 - iBlockType = NO_BLOCK - sCodePage = "" - Set oRcFile = oFSO.OpenTextFile(sRcFilePath, ForReading) - Set oLcFile = oFSO.CreateTextFile("heksedit.rc", True) - Do Until oRcFile.AtEndOfStream = True 'For all lines... - sLcLine = oRcFile.ReadLine - sLine = Trim(sLcLine) - sLine = Replace(sLine, vbTab, " ") - iLine = iLine + 1 - - sReference = sRcFileName & ":" & iLine - sString = "" - sComment = "" - sContext = "" - - If fContinuation Then - ' Nothing to do - ElseIf (Left(sLine, 2) = "//") Then 'If comment line... - sLine = "" - 'IGNORE FOR SPEEDUP! - ElseIf InStr(sLine, " TEXTINCLUDE") > 0 Then 'TEXTINCLUDE... - iBlockType = TEXTINCLUDE_BLOCK - ElseIf InStr(sLine, " MENU") > 0 And InStr(sLine, "IDR_") > 0 Then 'MENU... - iBlockType = MENU_BLOCK - ElseIf InStr(sLine, " DIALOG") > 0 Then 'DIALOG(EX)... - iBlockType = DIALOGEX_BLOCK - ElseIf InStr(sLine, "STRINGTABLE") > 0 Then 'STRINGTABLE... - iBlockType = STRINGTABLE_BLOCK - ElseIf InStr(sLine, " VERSIONINFO") > 0 Then 'VERSIONINFO... - iBlockType = VERSIONINFO_BLOCK - ElseIf InStr(sLine, " ACCELERATORS") > 0 Then 'ACCELERATORS... - iBlockType = ACCELERATORS_BLOCK - ElseIf InStr(sLine, " BITMAP ") > 0 Then 'BITMAP... - iBlockType = BITMAP_BLOCK - sLcLine = "//" & sLcLine - ElseIf (sLine = "BEGIN") Then 'BEGIN... - 'IGNORE FOR SPEEDUP! - ElseIf (sLine = "END") Then 'END... - If (iBlockType = STRINGTABLE_BLOCK) Or (iBlockType = TEXTINCLUDE_BLOCK) Then 'If inside STRINGTABLE or TEXTINCLUDE... - iBlockType = NO_BLOCK - End If - ElseIf sLine <> "" Then 'If NOT empty line... - Select Case iBlockType - Case NO_BLOCK: - If FoundRegExpMatch(sLine, "LANGUAGE (LANG_\w*, SUBLANG_\w*)", oMatch) Then 'LANGUAGE... - sString = oMatch.SubMatches(0) - sComment = "LANGUAGE, SUBLANGUAGE" - ElseIf FoundRegExpMatch(sLine, "code_page\(([\d]+)\)", oMatch) Then 'code_page... - sString = oMatch.SubMatches(0) - sComment = "Codepage" - sCodePage = oMatch.SubMatches(0) - End If - - Case MENU_BLOCK, DIALOGEX_BLOCK, STRINGTABLE_BLOCK: - If InStr(sLine, """") > 0 Then 'If quote found (for speedup)... - '-------------------------------------------------------------------------------- - ' Replace 1st string literal only - 2nd string literal specifies control class! - '-------------------------------------------------------------------------------- - If FoundRegExpMatch(sLine, """((?:""""|[^""])*)""", oMatch) Then 'String... - sTemp = oMatch.SubMatches(0) - If (sTemp <> "") And (oBlacklist.Exists(sTemp) = False) Then 'If NOT blacklisted... - sLcLine = Replace(sLcLine, """" & sTemp & """", """" & sReference & """", 1, 1) - sString = Replace(sTemp, """""", "\""") - If FoundRegExpMatch(sLine, "//#\. (.*?)$", oMatch) Then 'If found a comment for the translators... - sComment = Trim(oMatch.SubMatches(0)) - ElseIf FoundRegExpMatch(sLine, "//msgctxt (.*?)$", oMatch) Then 'If found a context for the translation... - sContext = Trim(oMatch.SubMatches(0)) - sComment = sContext - End If - End If - End If - End If - - Case VERSIONINFO_BLOCK: - If FoundRegExpMatch(sLine, "BLOCK ""([0-9A-F]+)""", oMatch) Then 'StringFileInfo.Block... - sString = oMatch.SubMatches(0) - sComment = "StringFileInfo.Block" - ElseIf FoundRegExpMatch(sLine, "VALUE ""Comments"", ""(.*?)\\?0?""", oMatch) Then 'StringFileInfo.Comments... - sString = oMatch.SubMatches(0) - sComment = "You should use a string like ""Translated by "" followed by the translator names for this string. It is ONLY VISIBLE in the StringFileInfo.Comments property from the final resource file!" - ElseIf FoundRegExpMatch(sLine, "VALUE ""Translation"", (.*?)$", oMatch) Then 'VarFileInfo.Translation... - sString = oMatch.SubMatches(0) - sComment = "VarFileInfo.Translation" - End If - - End Select - End If - - If (sString <> "") Then - sKey = sContext & sString - Set oString = New CString - If (oStrings.Exists(sKey) = True) Then 'If the key is already used... - Set oString = oStrings(sKey) - End If - If (sComment <> "") Then - oString.Comment = sComment - End If - If (oString.References <> "") Then - oString.References = oString.References & vbTab & sReference - Else - oString.References = sReference - End If - oString.Context = sContext - oString.Id = sString - oString.Str = "" - - If (oStrings.Exists(sKey) = True) Then 'If the key is already used... - Set oStrings(sKey) = oString - Else 'If the key is NOT already used... - oStrings.Add sContext & sString, oString - End If - End If - oLcFile.WriteLine sLcLine - fContinuation = sLine <> "" And InStr(",|", Right(sLine, 1)) <> 0 - Loop - oLcFile.WriteLine "en-US.pot RCDATA ""en-US.pot""" - oRcFile.Close - oLcFile.Close - End If - Set GetStringsFromRcFile = oStrings -End Function - -'' -' ... -Function GetStringBlacklist(ByVal sTxtFilePath) - Dim oBlacklist, oTxtFile, sLine - - Set oBlacklist = CreateObject("Scripting.Dictionary") - - If (oFSO.FileExists(sTxtFilePath) = True) Then 'If the blacklist file exists... - Set oTxtFile = oFSO.OpenTextFile(sTxtFilePath, ForReading) - Do Until oTxtFile.AtEndOfStream = True 'For all lines... - sLine = Trim(oTxtFile.ReadLine) - - If (sLine <> "") Then - If (oBlacklist.Exists(sLine) = False) Then 'If the key is NOT already used... - oBlacklist.Add sLine, True - End If - End If - Loop - oTxtFile.Close - End If - Set GetStringBlacklist = oBlacklist -End Function - -'' -' ... -Sub CreateMasterPotFile(ByVal sPotPath, ByVal oStrings, ByVal sCodePage) - Dim oPotFile, sKey, oString, aReferences, i - - Set oPotFile = oFSO.CreateTextFile(sPotPath, True) - - oPotFile.WriteLine "# This file is part of Frhed " - oPotFile.WriteLine "# Released under the ""GNU General Public License""" - oPotFile.WriteLine "#" - oPotFile.WriteLine "# ID line follows -- this is updated by SVN" - oPotFile.WriteLine "# $" & "Id: " & "$" - oPotFile.WriteLine "#" - oPotFile.WriteLine "msgid """"" - oPotFile.WriteLine "msgstr """"" - oPotFile.WriteLine """Project-Id-Version: Frhed\n""" - oPotFile.WriteLine """Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?group_id=13216&atid=113216\n""" - oPotFile.WriteLine """POT-Creation-Date: " & GetPotCreationDate() & "\n""" - oPotFile.WriteLine """PO-Revision-Date: \n""" - oPotFile.WriteLine """Last-Translator: \n""" - oPotFile.WriteLine """Language-Team: English \n""" - oPotFile.WriteLine """MIME-Version: 1.0\n""" - oPotFile.WriteLine """Content-Type: text/plain; charset=CP" & sCodePage & "\n""" - oPotFile.WriteLine """Content-Transfer-Encoding: 8bit\n""" - oPotFile.WriteLine """X-Poedit-Language: English\n""" - oPotFile.WriteLine """X-Poedit-SourceCharset: CP" & sCodePage & "\n""" - oPotFile.WriteLine """X-Poedit-Basepath: ../../FRHED\n""" - 'oPotFile.WriteLine """X-Generator: CreateMasterPotFile.vbs\n""" - oPotFile.WriteLine - For Each sKey In oStrings.Keys 'For all strings... - Set oString = oStrings(sKey) - If (oString.Comment <> "") Then 'If comment exists... - oPotFile.WriteLine "#. " & oString.Comment - End If - aReferences = Split(oString.References, vbTab) - For i = LBound(aReferences) To UBound(aReferences) 'For all references... - oPotFile.WriteLine "#: " & aReferences(i) - Next - oPotFile.WriteLine "#, c-format" - If (oString.Context <> "") Then 'If context exists... - oPotFile.WriteLine "msgctxt """ & oString.Context & """" - End If - oPotFile.WriteLine "msgid """ & oString.Id & """" - oPotFile.WriteLine "msgstr """"" - oPotFile.WriteLine - Next - oPotFile.Close -End Sub - -'' -' ... -Function FoundRegExpMatch(ByVal sString, ByVal sPattern, ByRef oMatchReturn) - Dim oRegExp, oMatches - - Set oRegExp = New RegExp - oRegExp.Pattern = sPattern - oRegExp.IgnoreCase = True - - Set oMatchReturn = Nothing - FoundRegExpMatch = False - If oRegExp.Test(sString) Then - Set oMatches = oRegExp.Execute(sString) - Set oMatchReturn = oMatches(0) - FoundRegExpMatch = True - End If -End Function - -'' -' ... -Function GetPotCreationDate() - Dim oNow, sYear, sMonth, sDay, sHour, sMinute - - oNow = Now() - sYear = Year(oNow) - sMonth = Month(oNow) - If (sMonth < 10) Then sMonth = "0" & sMonth - sDay = Day(oNow) - If (sDay < 10) Then sDay = "0" & sDay - sHour = Hour(oNow) - If (sHour < 10) Then sHour = "0" & sHour - sMinute = Minute(oNow) - If (sMinute < 10) Then sMinute = "0" & sMinute - - GetPotCreationDate = sYear & "-" & sMonth & "-" & sDay & " " & sHour & ":" & sMinute & "+0000" -End Function - -'' -' ... -Function InfoBox(ByVal sText, ByVal iSecondsToWait) - Dim oShell - - If (bRunFromCmd = False) Then 'If run from command line... - Set oShell = Wscript.CreateObject("WScript.Shell") - InfoBox = oShell.Popup(sText, iSecondsToWait, Wscript.ScriptName, 64) - Else 'If NOT run from command line... - Wscript.Echo sText - End If -End Function - -'' -' ... -Function GetArchiveBit(ByVal sFilePath) - Dim oFile - GetArchiveBit = False - If oFSO.FileExists(sFilePath) Then 'If the file exists... - Set oFile = oFSO.GetFile(sFilePath) - If (oFile.Attributes And 32) = 32 Then 'If archive bit set... - GetArchiveBit = True - End If - End If -End Function - -'' -' ... -Sub SetArchiveBit(ByVal sFilePath, ByVal bValue) - Dim oFile - If oFSO.FileExists(sFilePath) Then 'If the file exists... - Set oFile = oFSO.GetFile(sFilePath) - If bValue Xor (oFile.Attributes And 32) = 32 Then 'If archive bit different... - oFile.Attributes = oFile.Attributes Xor 32 - End If - End If -End Sub diff --git a/Translations/Frhed/UpdatePoFilesFromPotFile.js b/Translations/Frhed/UpdatePoFilesFromPotFile.js new file mode 100644 index 0000000..d9ac39a --- /dev/null +++ b/Translations/Frhed/UpdatePoFilesFromPotFile.js @@ -0,0 +1,239 @@ +//// +// This script updates the language PO files from the master POT file. +// +// Copyright (C) 2007-2008 by Tim Gerundt +// Released under the "GNU General Public License" + +var ForReading = 1; + +var oFSO = new ActiveXObject("Scripting.FileSystemObject"); + +var bRunFromCmd = false; +if (oFSO.GetFileName(WScript.FullName).toLowerCase() === "cscript.exe") { + bRunFromCmd = true; +} + +Main(); + +//// +// ... +function Main() { + var oLanguage + + var StartTime = new Date().getTime(); + + InfoBox("Updating PO files from POT file...", 3); + + var sDir = oFSO.GetParentFolderName(WScript.ScriptFullName); + var oEnglishPotContent = GetContentFromPoFile(sDir + "\\en-US.pot"); + if (isEmpty(oEnglishPotContent)) { throw new Error(0x80040000, "Sub Main: Error reading content from en-US.pot"); } + var bPotChanged = GetArchiveBit("en-US.pot"); + var oLanguages = WScript.Arguments; + if (oLanguages.Count() === 0) { var oLanguages = oFSO.GetFolder(".").Files; } + for (var it = new Enumerator(oLanguages); !it.atEnd(); it.moveNext()) { //For all languages... + var oLanguage = it.item(); + var sLanguage = String(oLanguage); + if (oFSO.GetExtensionName(sLanguage).toLowerCase() === "po") { + if (bPotChanged || GetArchiveBit(sLanguage)) { //If update necessary... + if (bRunFromCmd) { //If run from command line... + WScript.Echo(oFSO.GetFileName(sLanguage)); + } + var oLanguagePoContent = GetContentFromPoFile(sLanguage); + if (!isEmpty(oLanguagePoContent)) { //If content exists... + CreateUpdatedPoFile(sLanguage, oEnglishPotContent, oLanguagePoContent); + } + SetArchiveBit(sLanguage, false); + } + } + } + + var EndTime = new Date().getTime(); + var Seconds = (EndTime - StartTime) / 1000.0; + + InfoBox("All PO files updated, after " + Seconds + " second(s).", 10); +} + +//// +// ... +function GetContentFromPoFile(sPoPath) { + var oMatch, sMsgId; + var reMsgCtxt = /msgctxt "(.*)"$/i; + var reMsgId = /^msgid "(.*)"$/i; + var reMsgContinued = /^"(.*)"$/i; + var oContent = {}; + var iMsgStarted = 0; + var sMsgCtxt = ""; + var oSubContent = { "sMsgCtxt2": "", "sMsgId2": "", "sMsgStr2": "", "sTranslatorComments": "", "sExtractedComments": "", "sReferences": "", "sFlags": "" }; + var oTextFile = new ActiveXObject("ADODB.Stream"); + oTextFile.Type = 2; // adTypeText + oTextFile.LineSeparator = 10; // adLF + oTextFile.Charset = "UTF-8"; + oTextFile.Open(); + oTextFile.LoadFromFile(sPoPath); + while (!oTextFile.EOS) { //For all lines... + var sLine = oTextFile.ReadText(-2); // -2 = adReadLine + if (sLine.length > 0) { + if (sLine.substring(sLine.length - 1, sLine.length) === "\r") { + sLine = sLine.substring(0, sLine.length - 1); + } + } + sLine = sLine.replace(/^\s+|\s+$/g, ""); + if (sLine !== "") { //If NOT empty line... + if (sLine.substring(0, 1) !== "#") { //If NOT comment line... + if (reMsgCtxt.test(sLine)) { //If "msgctxt"... + iMsgStarted = 1; + oMatch = reMsgCtxt.exec(sLine); + sMsgCtxt = oMatch[1]; + oSubContent.sMsgCtxt2 = sLine + "\n"; + } else if (reMsgId.test(sLine)) { //If "msgid"... + iMsgStarted = 2; + oMatch = reMsgId.exec(sLine); + sMsgId = oMatch[1]; + oSubContent.sMsgId2 = sLine + "\n"; + } else if (sLine.substring(0, 8) === "msgstr \"") { //If "msgstr"... + iMsgStarted = 3; + oSubContent.sMsgStr2 = sLine + "\n"; + } else if (reMsgContinued.test(sLine)) { //If "msgctxt", "msgid" or "msgstr" continued... + if (iMsgStarted === 1) { + sMsgCtxt += oMatch[1]; + oSubContent.sMsgCtxt2 += sLine + "\n"; + } else if (iMsgStarted === 2) { + oMatch = reMsgContinued.exec(sLine); + sMsgId += oMatch[1]; + oSubContent.sMsgId2 += sLine + "\n"; + } else if (iMsgStarted === 3) { + oSubContent.sMsgStr2 += sLine + "\n" + } + } + } else { //If comment line... + iMsgStarted = -1; + switch (sLine.substring(0, 2)) { + case "#~": //Obsolete message... + iMsgStarted = 0; + break; + case "#.": //Extracted comment... + oSubContent.sExtractedComments += sLine + "\n"; + break; + case "#:": //Reference... + oSubContent.sReferences += sLine + "\n"; + break; + case "#,": //Flag... + oSubContent.sFlags += sLine + "\n"; + break; + default: //Translator comment... + oSubContent.sTranslatorComments += sLine + "\n"; + break; + } + } + } else if (iMsgStarted !== 0) { //If empty line AND there is pending translation... + iMsgStarted = 0 //Don//t process same translation twice + if (sMsgId === "") { sMsgId = "__head__"; } + if (!((sMsgCtxt + sMsgId) in oContent)) { //If the key is NOT already used... + oContent[sMsgCtxt + sMsgId] = oSubContent; + } + sMsgCtxt = ""; + var oSubContent = { "sMsgCtxt2": "", "sMsgId2": "", "sMsgStr2": "", "sTranslatorComments": "", "sExtractedComments": "", "sReferences": "", "sFlags": "" }; + } + } + if (iMsgStarted !== 0) { //If there is pending translation... + if (!((sMsgCtxt + sMsgId) in oContent)) { //If the key is NOT already used... + oContent[sMsgCtxt + sMsgId] = oSubContent; + } + } + oTextFile.Close(); + return oContent; +} + +//// +// ... +function CreateUpdatedPoFile(sPoPath, oEnglishPotContent, oLanguagePoContent) { + //-------------------------------------------------------------------------------- + // Backup the old PO file... + //-------------------------------------------------------------------------------- + var sBakPath = sPoPath + ".bak"; + if (oFSO.FileExists(sBakPath)) { + oFSO.DeleteFile(sBakPath); + } + oFSO.MoveFile(sPoPath, sBakPath); + //-------------------------------------------------------------------------------- + + var oPoFile = new ActiveXObject("ADODB.Stream"); + oPoFile.Type = 2; // adTypeText + oPoFile.LineSeparator = 10; // adLF + oPoFile.Charset = "UTF-8"; + oPoFile.Open(); + + var oLanguage = oLanguagePoContent["__head__"]; + oPoFile.WriteText(oLanguage.sTranslatorComments); + oPoFile.WriteText(oLanguage.sMsgId2); + oPoFile.WriteText(oLanguage.sMsgStr2); + oPoFile.WriteText("\n"); + for (var sKey in oEnglishPotContent) { //For all English content... + if (sKey !== "__head__") { + var oLanguage; + var oEnglish = oEnglishPotContent[sKey]; + if (sKey in oLanguagePoContent) { //If translation exists... + oLanguage = oLanguagePoContent[sKey]; + } else { //If translation NOT exists... + oLanguage = oEnglish; + } + oPoFile.WriteText(oLanguage.sTranslatorComments); + oPoFile.WriteText(oEnglish.sExtractedComments); + oPoFile.WriteText(oEnglish.sReferences); + oPoFile.WriteText(oLanguage.sFlags); + oPoFile.WriteText(oLanguage.sMsgCtxt2); + oPoFile.WriteText(oLanguage.sMsgId2); + oPoFile.WriteText(oLanguage.sMsgStr2); + oPoFile.WriteText("\n"); + } + } + oPoFile.SaveToFile(sPoPath, 2); + oPoFile.Close(); +} + +//// +// ... +function InfoBox(sText, iSecondsToWait) { + if (!bRunFromCmd) { //If run from command line... + var oShell = WScript.CreateObject("WScript.Shell"); + return oShell.Popup(sText, iSecondsToWait, WScript.ScriptName, 64); + } else { //If NOT run from command line... + WScript.Echo(sText); + } +} + +//// +// ... +function GetArchiveBit(sFilePath) { + if (oFSO.FileExists(sFilePath)) { //If the file exists... + var oFile = oFSO.GetFile(sFilePath); + if (oFile.Attributes & 32) { //If archive bit set... + return true; + } + } + return false; +} + +//// +// ... +function SetArchiveBit(sFilePath, bValue) { + if (oFSO.FileExists(sFilePath)) { //If the file exists... + var oFile = oFSO.GetFile(sFilePath); + if (oFile.Attributes & 32) { //If archive bit set... + if (!bValue) { + oFile.Attributes -= 32; + } + } else { //If archive bit NOT set... + if (bValue) { + oFile.Attributes += 32; + } + } + } +} +function isEmpty(object) { + for (var i in object) { + return false; + } + return true; +} + diff --git a/Translations/Frhed/UpdatePoFilesFromPotFile.vbs b/Translations/Frhed/UpdatePoFilesFromPotFile.vbs deleted file mode 100644 index 1e130ab..0000000 --- a/Translations/Frhed/UpdatePoFilesFromPotFile.vbs +++ /dev/null @@ -1,291 +0,0 @@ -Option Explicit -'' -' This script updates the language PO files from the master POT file. -' -' Copyright (C) 2007-2008 by Tim Gerundt -' Released under the "GNU General Public License" -' -' ID line follows -- this is updated by SVN -' $Id: UpdatePoFilesFromPotFile.vbs 6754 2009-05-16 17:42:05Z kimmov $ - -Const ForReading = 1 - -Dim oFSO, oCharsets, bRunFromCmd - -Set oFSO = CreateObject("Scripting.FileSystemObject") - -bRunFromCmd = False -If LCase(oFSO.GetFileName(Wscript.FullName)) = "cscript.exe" Then - bRunFromCmd = True -End If - -Set oCharsets = CreateObject("Scripting.Dictionary") -oCharsets.Add "CP932", "Shift_JIS" -oCharsets.Add "CP936", "GB2312" -oCharsets.Add "CP949", "EUC-KR" -oCharsets.Add "CP950", "BIG5" -oCharsets.Add "CP1250", "Windows-1250" -oCharsets.Add "CP1251", "Windows-1251" -oCharsets.Add "CP1252", "Windows-1252" -oCharsets.Add "CP1253", "Windows-1253" -oCharsets.Add "CP1254", "Windows-1254" -oCharsets.Add "CP1256", "Windows-1256" -oCharsets.Add "CP1257", "Windows-1257" -oCharsets.Add "UTF-8", "UTF-8" - -Call Main - -'' -' ... -Sub Main - Dim oLanguages, oLanguage, sLanguage, sDir, bPotChanged - Dim oEnglishPotContent, oLanguagePoContent - Dim StartTime, EndTime, Seconds - Dim sCharset - - StartTime = Time - - InfoBox "Updating PO files from POT file...", 3 - - sDir = oFSO.GetParentFolderName(Wscript.ScriptFullName) - Set oEnglishPotContent = GetContentFromPoFile(sDir & "\en-US.pot", sCharset) - If oEnglishPotContent.Count = 0 Then Err.Raise vbObjectError, "Sub Main", "Error reading content from en-US.pot" - bPotChanged = GetArchiveBit("en-US.pot") - Set oLanguages = Wscript.Arguments - If oLanguages.Count = 0 Then Set oLanguages = oFSO.GetFolder(".").Files - For Each oLanguage In oLanguages 'For all languages... - sLanguage = CStr(oLanguage) - If LCase(oFSO.GetExtensionName(sLanguage)) = "po" Then - If bPotChanged Or GetArchiveBit(sLanguage) Then 'If update necessary... - If bRunFromCmd Then 'If run from command line... - Wscript.Echo oFSO.GetFileName(sLanguage) - End If - Set oLanguagePoContent = GetContentFromPoFile(sLanguage, sCharset) - If oLanguagePoContent.Count > 0 Then 'If content exists... - CreateUpdatedPoFile sLanguage, oEnglishPotContent, oLanguagePoContent, sCharset - End If - SetArchiveBit sLanguage, False - End If - End If - Next - - EndTime = Time - Seconds = DateDiff("s", StartTime, EndTime) - - InfoBox "All PO files updated, after " & Seconds & " second(s).", 10 -End Sub - -'' -' ... -Class CSubContent - Dim sMsgCtxt2, sMsgId2, sMsgStr2, sTranslatorComments, sExtractedComments, sReferences, sFlags -End Class - -'' -' ... -Function GetContentFromPoFile(ByVal sPoPath, sCharset) - Dim oContent, oSubContent, oTextFile, sLine - Dim oMatch, iMsgStarted, sMsgCtxt, sMsgId - Dim reMsgCtxt, reMsgId, reMsgContinued, reCharset - - Set reMsgCtxt = New RegExp - reMsgCtxt.Pattern = "^msgctxt ""(.*)""$" - reMsgCtxt.IgnoreCase = True - - Set reMsgId = New RegExp - reMsgId.Pattern = "^msgid ""(.*)""$" - reMsgId.IgnoreCase = True - - Set reMsgContinued = New RegExp - reMsgContinued.Pattern = "^""(.*)""$" - reMsgContinued.IgnoreCase = True - - ' - sCharset = "_autodetect" - Set reCharset = New RegExp - reCharset.Pattern = "harset[=:] *(.*)\\n""$" - reCharset.IgnoreCase = True - Set oTextFile = oFSO.OpenTextFile(sPoPath, ForReading) - Do Until oTextFile.AtEndOfStream 'For all lines... - sLine = Trim(oTextFile.ReadLine) - If reCharset.Test(sLine) Then - Set oMatch = reCharset.Execute(sLine)(0) - sCharset = oCharsets(oMatch.SubMatches(0)) - Exit Do - End If - Loop - oTextFile.Close - - Set oContent = CreateObject("Scripting.Dictionary") - - iMsgStarted = 0 - sMsgCtxt = "" - Set oSubContent = New CSubContent - Set oTextFile = CreateObject("ADODB.Stream") - oTextFile.Type = 2 ' adTypeText - oTextFile.LineSeparator = 10 ' adLF - oTextFile.Charset = sCharset - oTextFile.Open - oTextFile.LoadFromFile(sPoPath) - Do Until oTextFile.EOS 'For all lines... - sLine = oTextFile.ReadText(-2) ' -2 = adReadLine - If Len(sLine) > 0 Then - If Right(sLine, 1) = vbCR Then - sLine = Left(sLine, Len(sLine) - 1) - End If - End If - sLine = Trim(sLine) - If sLine <> "" Then 'If NOT empty line... - If Left(sLine, 1) <> "#" Then 'If NOT comment line... - If reMsgCtxt.Test(sLine) Then 'If "msgctxt"... - iMsgStarted = 1 - Set oMatch = reMsgCtxt.Execute(sLine)(0) - sMsgCtxt = oMatch.SubMatches(0) - oSubContent.sMsgCtxt2 = sLine & vbLf - ElseIf reMsgId.Test(sLine) Then 'If "msgid"... - iMsgStarted = 2 - Set oMatch = reMsgId.Execute(sLine)(0) - sMsgId = oMatch.SubMatches(0) - oSubContent.sMsgId2 = sLine & vbLf - ElseIf Left(sLine, 8) = "msgstr """ Then 'If "msgstr"... - iMsgStarted = 3 - oSubContent.sMsgStr2 = sLine & vbLf - ElseIf reMsgContinued.Test(sLine) Then 'If "msgctxt", "msgid" or "msgstr" continued... - If iMsgStarted = 1 Then - sMsgCtxt = sMsgCtxt & oMatch.SubMatches(0) - oSubContent.sMsgCtxt2 = oSubContent.sMsgCtxt2 & sLine & vbLf - ElseIf iMsgStarted = 2 Then - Set oMatch = reMsgContinued.Execute(sLine)(0) - sMsgId = sMsgId & oMatch.SubMatches(0) - oSubContent.sMsgId2 = oSubContent.sMsgId2 & sLine & vbLf - ElseIf iMsgStarted = 3 Then - oSubContent.sMsgStr2 = oSubContent.sMsgStr2 & sLine & vbLf - End If - End If - Else 'If comment line... - iMsgStarted = -1 - Select Case Left(sLine, 2) - Case "#~" 'Obsolete message... - iMsgStarted = 0 - Case "#." 'Extracted comment... - oSubContent.sExtractedComments = oSubContent.sExtractedComments & sLine & vbLf - Case "#:" 'Reference... - oSubContent.sReferences = oSubContent.sReferences & sLine & vbLf - Case "#," 'Flag... - oSubContent.sFlags = oSubContent.sFlags & sLine & vbLf - Case Else 'Translator comment... - oSubContent.sTranslatorComments = oSubContent.sTranslatorComments & sLine & vbLf - End Select - End If - ElseIf iMsgStarted <> 0 Then 'If empty line AND there is pending translation... - iMsgStarted = 0 'Don't process same translation twice - If sMsgId = "" Then sMsgId = "__head__" - If (oContent.Exists(sMsgCtxt & sMsgId) = False) Then 'If the key is NOT already used... - oContent.Add sMsgCtxt & sMsgId, oSubContent - End If - sMsgCtxt = "" - Set oSubContent = New CSubContent - End If - Loop - If iMsgStarted <> 0 Then 'If there is pending translation... - If (oContent.Exists(sMsgCtxt & sMsgId) = False) Then 'If the key is NOT already used... - oContent.Add sMsgCtxt & sMsgId, oSubContent - End If - End If - oTextFile.Close - Set GetContentFromPoFile = oContent -End Function - -'' -' ... -Sub CreateUpdatedPoFile(ByVal sPoPath, ByVal oEnglishPotContent, ByVal oLanguagePoContent, ByVal sCharset) - Dim sBakPath, oPoFile, sKey, oEnglish, oLanguage - - '-------------------------------------------------------------------------------- - ' Backup the old PO file... - '-------------------------------------------------------------------------------- - sBakPath = sPoPath & ".bak" - If oFSO.FileExists(sBakPath) Then - oFSO.DeleteFile sBakPath - End If - oFSO.MoveFile sPoPath, sBakPath - '-------------------------------------------------------------------------------- - - Set oPoFile = CreateObject("ADODB.Stream") - oPoFile.Type = 2 ' adTypeText - oPoFile.LineSeparator = 10 ' adLF - oPoFile.Charset = sCharset - oPoFile.Open - - Set oLanguage = oLanguagePoContent("__head__") - oPoFile.WriteText oLanguage.sTranslatorComments - oPoFile.WriteText oLanguage.sMsgId2 - oPoFile.WriteText oLanguage.sMsgStr2 - oPoFile.WriteText vbLf - For Each sKey In oEnglishPotContent.Keys 'For all English content... - If sKey <> "__head__" Then - Set oEnglish = oEnglishPotContent(sKey) - If oLanguagePoContent.Exists(sKey) Then 'If translation exists... - Set oLanguage = oLanguagePoContent(sKey) - Else 'If translation NOT exists... - Set oLanguage = oEnglish - End If - oPoFile.WriteText oLanguage.sTranslatorComments - oPoFile.WriteText oEnglish.sExtractedComments - oPoFile.WriteText oEnglish.sReferences - oPoFile.WriteText oLanguage.sFlags - oPoFile.WriteText oLanguage.sMsgCtxt2 - oPoFile.WriteText oLanguage.sMsgId2 - oPoFile.WriteText oLanguage.sMsgStr2 - oPoFile.WriteText vbLf - End If - Next - oPoFile.SaveToFile sPoPath, 2 - oPoFile.Close -End Sub - -'' -' ... -Function InfoBox(ByVal sText, ByVal iSecondsToWait) - Dim oShell - - If (bRunFromCmd = False) Then 'If run from command line... - Set oShell = Wscript.CreateObject("WScript.Shell") - InfoBox = oShell.Popup(sText, iSecondsToWait, Wscript.ScriptName, 64) - Else 'If NOT run from command line... - Wscript.Echo sText - End If -End Function - -'' -' ... -Function GetArchiveBit(ByVal sFilePath) - Dim oFile - - GetArchiveBit = False - If (oFSO.FileExists(sFilePath) = True) Then 'If the file exists... - Set oFile = oFSO.GetFile(sFilePath) - If (oFile.Attributes AND 32) Then 'If archive bit set... - GetArchiveBit = True - End If - End If -End Function - -'' -' ... -Sub SetArchiveBit(ByVal sFilePath, ByVal bValue) - Dim oFile - - If (oFSO.FileExists(sFilePath) = True) Then 'If the file exists... - Set oFile = oFSO.GetFile(sFilePath) - If (oFile.Attributes AND 32) Then 'If archive bit set... - If (bValue = False) Then - oFile.Attributes = oFile.Attributes - 32 - End If - Else 'If archive bit NOT set... - If (bValue = True) Then - oFile.Attributes = oFile.Attributes + 32 - End If - End If - End If -End Sub diff --git a/Translations/Frhed/de.po b/Translations/Frhed/de.po index 5d37f1c..0114457 100644 --- a/Translations/Frhed/de.po +++ b/Translations/Frhed/de.po @@ -28,12 +28,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_GERMAN, SUBLANG_GERMAN" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/en-US.pot b/Translations/Frhed/en-US.pot index a99583c..1c765b3 100644 --- a/Translations/Frhed/en-US.pot +++ b/Translations/Frhed/en-US.pot @@ -1,22 +1,19 @@ # This file is part of Frhed # Released under the "GNU General Public License" # -# ID line follows -- this is updated by SVN -# $Id: $ -# msgid "" msgstr "" "Project-Id-Version: Frhed\n" "Report-Msgid-Bugs-To: http://sourceforge.net/tracker/?group_id=13216&atid=113216\n" -"POT-Creation-Date: 2022-11-06 12:47+0000\n" +"POT-Creation-Date: 2024-02-14 06:39+0000\n" "PO-Revision-Date: \n" "Last-Translator: \n" "Language-Team: English \n" "MIME-Version: 1.0\n" -"Content-Type: text/plain; charset=CP1252\n" +"Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "X-Poedit-Language: English\n" -"X-Poedit-SourceCharset: CP1252\n" +"X-Poedit-SourceCharset: UTF-8\n" "X-Poedit-Basepath: ../../FRHED\n" #. LANGUAGE, SUBLANGUAGE @@ -25,12 +22,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/fr.po b/Translations/Frhed/fr.po index 000a720..6071e26 100644 --- a/Translations/Frhed/fr.po +++ b/Translations/Frhed/fr.po @@ -1,4 +1,4 @@ -# This file is part of Frhed +# This file is part of Frhed # Released under the "GNU General Public License" # # Translators: @@ -29,12 +29,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_FRENCH, SUBLANG_FRENCH_FR" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" @@ -919,8 +913,8 @@ msgstr "" msgid "Display length of offset in how many characters:" msgstr "Nombre de caractères d'affichage de la longueur du décalage :" -#: heksedit.rc:467 # Texte court (manque d'espace) ! +#: heksedit.rc:467 #, c-format msgid "Adjust offset length to that of the max offset" msgstr "Ajuster la longueur du décalage avec le décalage max" @@ -2834,3 +2828,4 @@ msgstr "Impossible de copier la décharge_hexa (Hexdump) vers le presse-papier." #, c-format msgid "Hex Dump files(*.txt,*.hex)|*.txt;*.hex|All Files (*.*)|*.*|" msgstr "Fichiers HexDump (*.txt,*.hex)|*.txt;*.hex|Tous fichiers (*.*)|*.*|" + diff --git a/Translations/Frhed/gl.po b/Translations/Frhed/gl.po index c92dde5..5a148cc 100644 --- a/Translations/Frhed/gl.po +++ b/Translations/Frhed/gl.po @@ -27,12 +27,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_GALICIAN, SUBLANG_DEFAULT" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/ja.po b/Translations/Frhed/ja.po index 7f23d5b..e05e5cb 100644 --- a/Translations/Frhed/ja.po +++ b/Translations/Frhed/ja.po @@ -30,12 +30,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_JAPANESE, SUBLANG_JAPANESE" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/nl.po b/Translations/Frhed/nl.po index d6076ed..f52d957 100644 --- a/Translations/Frhed/nl.po +++ b/Translations/Frhed/nl.po @@ -29,12 +29,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_DUTCH, SUBLANG_DUTCH" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/pl.po b/Translations/Frhed/pl.po index 5135c2d..b96e6e3 100644 --- a/Translations/Frhed/pl.po +++ b/Translations/Frhed/pl.po @@ -28,12 +28,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_POLISH, SUBLANG_DEFAULT" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/sk.po b/Translations/Frhed/sk.po index e4fb52b..76b3ab8 100644 --- a/Translations/Frhed/sk.po +++ b/Translations/Frhed/sk.po @@ -31,12 +31,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_SLOVAK, SUBLANG_SLOVAK" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File" diff --git a/Translations/Frhed/sl.po b/Translations/Frhed/sl.po index 0e2328f..6671bb8 100644 --- a/Translations/Frhed/sl.po +++ b/Translations/Frhed/sl.po @@ -27,12 +27,6 @@ msgstr "" msgid "LANG_ENGLISH, SUBLANG_ENGLISH_US" msgstr "LANG_SLOVENIAN, SUBLANG_SLOVENIAN" -#. Codepage -#: heksedit.rc:6 -#, c-format -msgid "1252" -msgstr "65001" - #: heksedit.rc:12 #, c-format msgid "&File"