Skip to content

Commit

Permalink
[pollock] add comment preservation
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
pbatard committed Jul 11, 2018
1 parent 5ac9ee6 commit 092ea93
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 1,660 deletions.
1 change: 1 addition & 0 deletions _chver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sed -i -e "s/^AC_INIT(\[\([^ ]*\)\], \[[^ ]*\]\(.*\)/AC_INIT([\1], [$MAJOR.$MINO
cat > cmd.sed <<\_EOF
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]*\)"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/^\([ \t]*\)Version="[0-9]*\.[0-9]*\.\(.*\)"\(.*\)/\1Version="@@MAJOR@@.@@MINOR@@.\2"\3/
s/^set VERSION=[0-9]*\.[0-9]*/set VERSION=@@MAJOR@@.@@MINOR@@/
Expand Down
89 changes: 52 additions & 37 deletions res/localization/Pollock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ static List<Language> ParseLocFile(string path)
switch (data[0])
{
case '#':
comment += data.Substring(1).Trim() + " ";
comment += data.Substring(1).Trim() + "\n";
break;
case 'l':
comment = null;
Expand Down Expand Up @@ -204,7 +204,7 @@ static List<Language> ParseLocFile(string path)
last_key = parts[1];
if (comment != null)
{
lang.comments[last_key] = comment.Trim().Replace(" below", "").Replace("The following", "This");
lang.comments[last_key] = comment.Trim();
comment = null;
}
break;
Expand Down Expand Up @@ -276,18 +276,18 @@ static bool CreatePoFiles(string path, List<Language> langs)
{
foreach (var msg in section.Value)
{
// Not very efficient but hey
if (msg.id == "SECTION")
continue;
writer.WriteLine();
if (section.Key == "MSG")
writer.WriteLine($"#. • {msg.id}");
else
writer.WriteLine($"#. • {section.Key}{msg.id}");
if (lang.comments.ContainsKey(msg.id))
{
writer.WriteLine($"#.");
writer.WriteLine($"#. {lang.comments[msg.id]}");
if (is_pot)
writer.WriteLine("#.");
foreach (var comment in lang.comments[msg.id].Split('\n'))
if (comment.Trim() != "")
writer.WriteLine((is_pot ? "#. " : "# ") + comment);
}
if (is_pot)
{
Expand Down Expand Up @@ -329,7 +329,7 @@ static Language ParsePoFile(string file)
string[] msg_data = new string[2] { null, null };
Language lang = new Language();
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>();
int msg_type = 0;
foreach (var line in lines)
Expand Down Expand Up @@ -365,24 +365,7 @@ static Language ParsePoFile(string file)
lang.lcid = options[LANG_LCID];
}
}
// 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)
{
// 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.StartsWith("\""))
{
if (data[data.Length - 1] != '"')
{
Expand Down Expand Up @@ -426,8 +409,41 @@ static Language ParsePoFile(string file)
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();
Console.WriteLine($"{(cancel_requested ? "CANCELLED after" : "DONE in")}" +
$" {watch.ElapsedMilliseconds / 1000.0}s.");
Expand All @@ -454,23 +470,20 @@ static void WriteLoc(StreamWriter writer, Language lang)
var sections = lang.sections.Keys.ToList();
foreach (var section in sections)
{
if (section == "MSG")
continue;
writer.WriteLine();
writer.WriteLine($"g {section}");
if (section != "MSG")
writer.WriteLine($"g {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}\"");
}
}
// 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>
Expand Down Expand Up @@ -564,6 +577,8 @@ static void Main(string[] args)

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"));

var en_US = ParsePoFile(path + @"\rufus.pot");
Expand Down
Loading

0 comments on commit 092ea93

Please sign in to comment.