[pollock] add comment preservation

* Also fix last lang message not being properly processed
* Also update loc file comments in preparation for the new framework
* Also update Rufus version data
This commit is contained in:
Pete Batard 2018-07-11 18:02:03 +01:00
parent 5ac9ee68af
commit 092ea937c6
4 changed files with 159 additions and 1660 deletions

View file

@ -24,6 +24,7 @@ sed -i -e "s/^AC_INIT(\[\([^ ]*\)\], \[[^ ]*\]\(.*\)/AC_INIT([\1], [$MAJOR.$MINO
cat > cmd.sed <<\_EOF cat > cmd.sed <<\_EOF
s/^\([ \t]*\)\(FILE\|PRODUCT\)VERSION\([ \t]*\)[0-9]*,[0-9]*\(.*\)/\1\2VERSION\3@@MAJOR@@,@@MINOR@@\4/ s/^\([ \t]*\)\(FILE\|PRODUCT\)VERSION\([ \t]*\)[0-9]*,[0-9]*\(.*\)/\1\2VERSION\3@@MAJOR@@,@@MINOR@@\4/
s/^\([ \t]*\)VALUE\([ \t]*\)"\(File\|Product\)Version",\([ \t]*\)"[0-9]*\.[0-9]*\.\(.*\)/\1VALUE\2"\3Version",\4"@@MAJOR@@.@@MINOR@@.\5/ s/^\([ \t]*\)VALUE\([ \t]*\)"\(File\|Product\)Version",\([ \t]*\)"[0-9]*\.[0-9]*\.\(.*\)/\1VALUE\2"\3Version",\4"@@MAJOR@@.@@MINOR@@.\5/
s/^\([ \t]*\)VALUE\([ \t]*\)"OriginalFilename",\([ \t]*\)"rufus-[0-9]*\.[0-9]*\.exe\(.*\)/\1VALUE\2"OriginalFilename",\3"rufus-@@MAJOR@@.@@MINOR@@.exe\4/
s/^\(.*\)"Rufus [0-9]*\.[0-9]*\.\(.*\)"\(.*\)/\1"Rufus @@MAJOR@@.@@MINOR@@.\2"\3/ s/^\(.*\)"Rufus [0-9]*\.[0-9]*\.\(.*\)"\(.*\)/\1"Rufus @@MAJOR@@.@@MINOR@@.\2"\3/
s/^\([ \t]*\)Version="[0-9]*\.[0-9]*\.\(.*\)"\(.*\)/\1Version="@@MAJOR@@.@@MINOR@@.\2"\3/ s/^\([ \t]*\)Version="[0-9]*\.[0-9]*\.\(.*\)"\(.*\)/\1Version="@@MAJOR@@.@@MINOR@@.\2"\3/
s/^set VERSION=[0-9]*\.[0-9]*/set VERSION=@@MAJOR@@.@@MINOR@@/ s/^set VERSION=[0-9]*\.[0-9]*/set VERSION=@@MAJOR@@.@@MINOR@@/

View file

@ -146,7 +146,7 @@ namespace pollock
switch (data[0]) switch (data[0])
{ {
case '#': case '#':
comment += data.Substring(1).Trim() + " "; comment += data.Substring(1).Trim() + "\n";
break; break;
case 'l': case 'l':
comment = null; comment = null;
@ -204,7 +204,7 @@ namespace pollock
last_key = parts[1]; last_key = parts[1];
if (comment != null) if (comment != null)
{ {
lang.comments[last_key] = comment.Trim().Replace(" below", "").Replace("The following", "This"); lang.comments[last_key] = comment.Trim();
comment = null; comment = null;
} }
break; break;
@ -276,9 +276,6 @@ namespace pollock
{ {
foreach (var msg in section.Value) foreach (var msg in section.Value)
{ {
// Not very efficient but hey
if (msg.id == "SECTION")
continue;
writer.WriteLine(); writer.WriteLine();
if (section.Key == "MSG") if (section.Key == "MSG")
writer.WriteLine($"#. • {msg.id}"); writer.WriteLine($"#. • {msg.id}");
@ -286,8 +283,11 @@ namespace pollock
writer.WriteLine($"#. • {section.Key} → {msg.id}"); writer.WriteLine($"#. • {section.Key} → {msg.id}");
if (lang.comments.ContainsKey(msg.id)) if (lang.comments.ContainsKey(msg.id))
{ {
writer.WriteLine($"#."); if (is_pot)
writer.WriteLine($"#. {lang.comments[msg.id]}"); writer.WriteLine("#.");
foreach (var comment in lang.comments[msg.id].Split('\n'))
if (comment.Trim() != "")
writer.WriteLine((is_pot ? "#. " : "# ") + comment);
} }
if (is_pot) if (is_pot)
{ {
@ -329,7 +329,7 @@ namespace pollock
string[] msg_data = new string[2] { null, null }; string[] msg_data = new string[2] { null, null };
Language lang = new Language(); Language lang = new Language();
List<Id> ids = new List<Id>(); List<Id> ids = new List<Id>();
Dictionary<string, Dictionary<string, string>> comments = new Dictionary<string, Dictionary<string, string>>(); List<string> comments = new List<string>();
List<string> codes = new List<string>(); List<string> codes = new List<string>();
int msg_type = 0; int msg_type = 0;
foreach (var line in lines) foreach (var line in lines)
@ -365,24 +365,7 @@ namespace pollock
lang.lcid = options[LANG_LCID]; lang.lcid = options[LANG_LCID];
} }
} }
// Break or EOF => Process the previous section if (data.StartsWith("\""))
if (string.IsNullOrEmpty(data) || (line_nr == lines.Count()))
{
if ((!string.IsNullOrEmpty(msg_data[0])) && (ids.Count() != 0))
{
foreach (var id in ids)
{
// Ignore messages that have the same translation as en-US
if (msg_data[0] == msg_data[1])
continue;
if (!lang.sections.ContainsKey(id.group))
lang.sections.Add(id.group, new List<Message>());
lang.sections[id.group].Add(new Message(id.id, msg_data[is_pot?0:1]));
}
}
ids = new List<Id>();
}
else if (data.StartsWith("\""))
{ {
if (data[data.Length - 1] != '"') if (data[data.Length - 1] != '"')
{ {
@ -426,8 +409,41 @@ namespace pollock
ids.Add(new Id(str[0].Trim(), str[1].Trim())); ids.Add(new Id(str[0].Trim(), str[1].Trim()));
} }
} }
else if (data.StartsWith("#. "))
{
if (comments == null)
comments = new List<string>();
comments.Add(data.Substring(2).Trim());
}
// Break or EOF => Process the previous section
if (string.IsNullOrEmpty(data) || (line_nr == lines.Count()))
{
if ((!string.IsNullOrEmpty(msg_data[0])) && (ids.Count() != 0))
{
foreach (var id in ids)
{
if (comments != null)
{
lang.comments.Add(id.id, "");
foreach (var comment in comments)
lang.comments[id.id] += comment + "\n";
}
// Ignore messages that have the same translation as en-US
if (msg_data[0] == msg_data[1])
continue;
if (!lang.sections.ContainsKey(id.group))
lang.sections.Add(id.group, new List<Message>());
lang.sections[id.group].Add(new Message(id.id, msg_data[is_pot ? 0 : 1]));
}
}
ids = new List<Id>();
comments = null;
}
} }
// Sort the MSG section alphabetically
lang.sections["MSG"] = lang.sections["MSG"].OrderBy(x => x.id).ToList();
watch.Stop(); watch.Stop();
Console.WriteLine($"{(cancel_requested ? "CANCELLED after" : "DONE in")}" + Console.WriteLine($"{(cancel_requested ? "CANCELLED after" : "DONE in")}" +
$" {watch.ElapsedMilliseconds / 1000.0}s."); $" {watch.ElapsedMilliseconds / 1000.0}s.");
@ -454,23 +470,20 @@ namespace pollock
var sections = lang.sections.Keys.ToList(); var sections = lang.sections.Keys.ToList();
foreach (var section in sections) foreach (var section in sections)
{ {
if (section == "MSG")
continue;
writer.WriteLine(); writer.WriteLine();
writer.WriteLine($"g {section}"); if (section != "MSG")
writer.WriteLine($"g {section}");
foreach (var msg in lang.sections[section]) foreach (var msg in lang.sections[section])
{ {
if (lang.comments.ContainsKey(msg.id))
{
foreach (var l in lang.comments[msg.id].Split('\n'))
if (l.Trim() != "")
writer.WriteLine($"# {l}");
}
writer.WriteLine($"t {msg.id} \"{msg.str}\""); writer.WriteLine($"t {msg.id} \"{msg.str}\"");
} }
} }
// Sort the MSG_### entries as they may out of order
SortedDictionary<string, string> messages =
new SortedDictionary<string, string>(lang.sections["MSG"].ToDictionary(x => x.id, x => x.str));
writer.WriteLine();
foreach (var msg in messages)
{
writer.WriteLine($"t {msg.Key} \"{msg.Value}\"");
}
} }
/// <summary> /// <summary>
@ -564,6 +577,8 @@ namespace pollock
var path = @"C:\pollock"; var path = @"C:\pollock";
// NB: Can find PoEdit from Computer\HKEY_CURRENT_USER\Software\Classes\Local Settings\Software\Microsoft\Windows\Shell\MuiCache
//CreatePoFiles(path, ParseLocFile(@"C:\rufus\res\localization")); //CreatePoFiles(path, ParseLocFile(@"C:\rufus\res\localization"));
var en_US = ParsePoFile(path + @"\rufus.pot"); var en_US = ParsePoFile(path + @"\rufus.pot");

File diff suppressed because it is too large Load diff

View file

@ -33,7 +33,7 @@ LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
IDD_DIALOG DIALOGEX 12, 12, 232, 326 IDD_DIALOG DIALOGEX 12, 12, 232, 326
STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_MODALFRAME | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_ACCEPTFILES EXSTYLE WS_EX_ACCEPTFILES
CAPTION "Rufus 3.2.1333" CAPTION "Rufus 3.2.1334"
FONT 9, "Segoe UI Symbol", 400, 0, 0x0 FONT 9, "Segoe UI Symbol", 400, 0, 0x0
BEGIN BEGIN
LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP LTEXT "Drive Properties",IDS_DRIVE_PROPERTIES_TXT,8,6,53,12,NOT WS_GROUP
@ -392,8 +392,8 @@ END
// //
VS_VERSION_INFO VERSIONINFO VS_VERSION_INFO VERSIONINFO
FILEVERSION 3,2,1333,0 FILEVERSION 3,2,1334,0
PRODUCTVERSION 3,2,1333,0 PRODUCTVERSION 3,2,1334,0
FILEFLAGSMASK 0x3fL FILEFLAGSMASK 0x3fL
#ifdef _DEBUG #ifdef _DEBUG
FILEFLAGS 0x1L FILEFLAGS 0x1L
@ -408,15 +408,16 @@ BEGIN
BEGIN BEGIN
BLOCK "000004b0" BLOCK "000004b0"
BEGIN BEGIN
VALUE "CompanyName", "Akeo Consulting (http://akeo.ie)" VALUE "Comments", "https://akeo.ie"
VALUE "CompanyName", "Akeo Consulting"
VALUE "FileDescription", "Rufus" VALUE "FileDescription", "Rufus"
VALUE "FileVersion", "3.2.1333" VALUE "FileVersion", "3.2.1334"
VALUE "InternalName", "Rufus" VALUE "InternalName", "Rufus"
VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)" VALUE "LegalCopyright", "© 2011-2018 Pete Batard (GPL v3)"
VALUE "LegalTrademarks", "http://www.gnu.org/copyleft/gpl.html" VALUE "LegalTrademarks", "https://www.gnu.org/copyleft/gpl.html"
VALUE "OriginalFilename", "rufus.exe" VALUE "OriginalFilename", "rufus-3.2.exe"
VALUE "ProductName", "Rufus" VALUE "ProductName", "Rufus"
VALUE "ProductVersion", "3.2.1333" VALUE "ProductVersion", "3.2.1334"
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"