Various fixes for generating the localization files
This commit is contained in:
@@ -16,6 +16,10 @@ namespace LocalizationTool2
|
||||
|
||||
sourcefolder = Path.GetFullPath(sourcefolder.Replace("~", Environment.GetEnvironmentVariable("HOME")));
|
||||
|
||||
var targetfolder = sourcefolder;
|
||||
if (args == null || args.Length > 1)
|
||||
targetfolder = Path.GetFullPath(args[1].Replace("~", Environment.GetEnvironmentVariable("HOME")));
|
||||
|
||||
|
||||
if (!Directory.Exists(sourcefolder))
|
||||
{
|
||||
@@ -30,7 +34,7 @@ namespace LocalizationTool2
|
||||
var searchlist = new Dictionary<string, Regex>();
|
||||
searchlist.Add("html", new Regex("((\\{\\{)|(ng-bind-html\\s*=\\s*\"))\\s*\\'(?<sourcestring>(\\\\\\'|[^\\'])+)\\'\\s*\\|\\s*localize(\\s|\\:|\\})", RegexOptions.Multiline | RegexOptions.IgnoreCase));
|
||||
searchlist.Add("js", new Regex("Localization\\.localize\\(\\s*((\\'(?<sourcestring>(\\\\\\'|[^\\'])+)\\')|(\\\"(?<sourcestring>(\\\\\\\"|[^\\\"])+)\\\"))", RegexOptions.Multiline | RegexOptions.IgnoreCase));
|
||||
searchlist.Add("cs", new Regex("LC.L\\s*\\(((@\\s*\"(?<sourcestring>(\"\"|[^\"])+))|(\"(?<sourcestring>(\\\\\"|[^\"])+)))\"\\s*\\)", RegexOptions.Multiline | RegexOptions.IgnoreCase));
|
||||
searchlist.Add("cs", new Regex("LC.L\\s*\\(((@\\s*\"(?<sourcestring>(\"\"|[^\"])+))|(\"(?<sourcestring>(\\\\\"|[^\"])+)))\"\\s*(\\)|,)", RegexOptions.Multiline | RegexOptions.IgnoreCase));
|
||||
|
||||
var map = new Dictionary<string, LocalizationEntry>();
|
||||
|
||||
@@ -46,7 +50,7 @@ namespace LocalizationTool2
|
||||
foreach (Match match in re.Matches(txt))
|
||||
{
|
||||
var linepos = txt.Substring(match.Index).Count(x => x == '\n');
|
||||
var str = match.Groups["sourcestring"].Value;
|
||||
var str = match.Groups["sourcestring"].Value.Replace("\n", "\\n").Replace("\r", "\\r");
|
||||
LocalizationEntry le;
|
||||
if (!map.TryGetValue(str, out le))
|
||||
map[str] = new LocalizationEntry(str, f.Substring(sourcefolder.Length), linepos);
|
||||
@@ -56,30 +60,32 @@ namespace LocalizationTool2
|
||||
}
|
||||
}
|
||||
|
||||
File.WriteAllText(Path.Combine(sourcefolder, "translations.json"), Newtonsoft.Json.JsonConvert.SerializeObject(map.Values.OrderBy(x => x.SourceLocations.FirstOrDefault()).ToArray(), Newtonsoft.Json.Formatting.Indented));
|
||||
File.WriteAllText(Path.Combine(sourcefolder, "translations-list.json"), Newtonsoft.Json.JsonConvert.SerializeObject(map.Select(x => x.Key).OrderBy(x => x).ToArray(), Newtonsoft.Json.Formatting.Indented));
|
||||
//File.WriteAllText(Path.Combine(sourcefolder, "translations.json"), Newtonsoft.Json.JsonConvert.SerializeObject(map.Values.OrderBy(x => x.SourceLocations.FirstOrDefault()).ToArray(), Newtonsoft.Json.Formatting.Indented));
|
||||
//File.WriteAllText(Path.Combine(sourcefolder, "translations-list.json"), Newtonsoft.Json.JsonConvert.SerializeObject(map.Select(x => x.Key).OrderBy(x => x).ToArray(), Newtonsoft.Json.Formatting.Indented));
|
||||
|
||||
File.WriteAllLines(
|
||||
Path.Combine(sourcefolder, "translations.po"),
|
||||
Path.Combine(targetfolder, "localization.po"),
|
||||
map.OrderBy(x => x.Key).Select(x => x.Value).SelectMany(x => new string[] {
|
||||
"#: " + x.SourceLocations.FirstOrDefault(),
|
||||
string.Format("msgid: \"{0}\"", (x.SourceString ?? "")),
|
||||
string.Format("msgstr: \"{0}\"", (x.SourceString ?? "")),
|
||||
string.Format("msgid \"{0}\"", (x.SourceString ?? "")),
|
||||
string.Format("msgstr \"{0}\"", (x.SourceString ?? "")),
|
||||
""
|
||||
}),
|
||||
System.Text.Encoding.UTF8
|
||||
);
|
||||
|
||||
File.WriteAllLines(
|
||||
Path.Combine(sourcefolder, "translations-by-file.po"),
|
||||
Console.WriteLine("Wrote {0} strings to {1}", map.Count, Path.Combine(targetfolder, "localization.po"));
|
||||
|
||||
/*File.WriteAllLines(
|
||||
Path.Combine(sourcefolder, "localization-by-file.po"),
|
||||
map.OrderBy(x => x.Value.SourceLocations.FirstOrDefault()).Select(x => x.Value).SelectMany(x => new string[] {
|
||||
"#: " + x.SourceLocations.FirstOrDefault(),
|
||||
string.Format("msgid: \"{0}\"", (x.SourceString ?? "")),
|
||||
string.Format("msgstr: \"{0}\"", (x.SourceString ?? "")),
|
||||
string.Format("msgid \"{0}\"", (x.SourceString ?? "")),
|
||||
string.Format("msgstr \"{0}\"", (x.SourceString ?? "")),
|
||||
""
|
||||
}),
|
||||
System.Text.Encoding.UTF8
|
||||
);
|
||||
);*/
|
||||
|
||||
return 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user