diff --git a/BuildTools/LocalizationTool/LocalizationTool/Program.cs b/BuildTools/LocalizationTool/LocalizationTool/Program.cs index 942c27799..6cbc61a61 100644 --- a/BuildTools/LocalizationTool/LocalizationTool/Program.cs +++ b/BuildTools/LocalizationTool/LocalizationTool/Program.cs @@ -22,6 +22,8 @@ using System.Windows.Forms; using System.Collections.Generic; using System.Linq; using System.Xml.Linq; +using System.IO; +using System.Net; namespace LocalizationTool { @@ -97,6 +99,12 @@ namespace LocalizationTool Report(loc); new UpdateGUI(System.IO.Path.Combine(Application.StartupPath, "report." + loc + ".xml")).ShowDialog(); break; + case "webpull": + WebPull(loc, false); + break; + case "webupdate": + WebPull(loc, true); + break; default: PrintUsage(); return; @@ -117,6 +125,8 @@ namespace LocalizationTool Console.WriteLine("LocalizationTool.exe EXPORT [locale identifier]"); Console.WriteLine("LocalizationTool.exe IMPORT "); Console.WriteLine("LocalizationTool.exe EXPORTDIFF "); + Console.WriteLine("LocalizationTool.exe WEBPULL [locale identifier]"); + Console.WriteLine("LocalizationTool.exe WEBUPDATE [locale identifier]"); } private struct CSVEntry @@ -147,6 +157,79 @@ namespace LocalizationTool } } + private static bool IsValidCulture(string c) + { + try + { + System.Globalization.CultureInfo.GetCultureInfo(c); + return true; + } + catch + { + return false; + } + } + + /// + /// Downloads updated CSV files from the web and generates diff files, and optionally updates the local CSV files + /// + /// The culture to use + /// True if the elements should be updated as well + private static void WebPull(string loc, bool update) + { + var locs = + from n in Directory.GetFiles(Application.StartupPath, "report.*.url") + where IsValidCulture(Path.GetFileNameWithoutExtension(n).Substring("report.".Length)) + select Path.GetFileNameWithoutExtension(n).Substring("report.".Length); + + if (!string.IsNullOrEmpty(loc)) + { + locs = locs.Where(c => string.Equals(c, loc, StringComparison.CurrentCultureIgnoreCase)); + if (locs.Count() == 0) + { + Console.WriteLine("No URL file found for culture {0}", loc); + return; + } + } + + if (locs.Count() == 0) + { + Console.WriteLine("No culture.url files found"); + return; + } + + foreach (var culture in locs) + { + var url = string.Format("report.{0}.url", culture); + var file = string.Format("report.{0}.new.csv", culture); + + if (File.Exists(file)) + File.Delete(file); + Console.Write("Downloading updated CSV for {0} ... ", culture); + try { new WebClient().DownloadFile(File.ReadAllText(url).Trim(), file); } + catch (Exception ex) + { + Console.WriteLine("Failed!"); + Console.WriteLine(" -> {0}", ex.Message); + continue; + } + Console.WriteLine("Done!"); + + if (update) + { + Console.Write("Updating local files for {0} .", culture); + ExportDiff(culture, file); + Console.Write("."); + Import(culture, file); + Console.Write("."); + Export(culture); + Console.WriteLine(" Done!"); + } + + } + + } + /// /// Imports a CSV file into a dictionary format, /// Outer key is filename, inner key is fieldname, inner value is translated text @@ -216,7 +299,7 @@ namespace LocalizationTool foreach (var item in sourceVals) if (targetVals.ContainsKey(item.Key)) { - if (targetVals[item.Key].Element("value").Value != item.Value.Value) + if (targetVals[item.Key].Element("value").Value.Replace("\r\n", "\n") != item.Value.Value.Replace("\r\n", "\n")) { updated = true; targetVals[item.Key].Element("value").Value = item.Value.Value; @@ -611,8 +694,8 @@ namespace LocalizationTool } //Filter the source and target before proceeding - sourceElements = sourceElements.Where(c => !ignores.ContainsKey(c.Element("value").Value.Trim().ToLower()) && !c.Element("value").Value.Trim().ToLower().StartsWith("..\\resources\\")); - targetElements = targetElements.Where(c => !ignores.ContainsKey(c.Element("value").Value.Trim().ToLower()) && !c.Element("value").Value.Trim().ToLower().StartsWith("..\\resources\\")); + sourceElements = sourceElements.Where(c => !ignores.ContainsKey(c.Element("value").Value.Trim().ToLower()) && !c.Element("value").Value.Trim().ToLower().StartsWith("..\\resources\\") && !c.Element("value").Value.Trim().ToLower().StartsWith("../resources/")); + targetElements = targetElements.Where(c => !ignores.ContainsKey(c.Element("value").Value.Trim().ToLower()) && !c.Element("value").Value.Trim().ToLower().StartsWith("..\\resources\\") && !c.Element("value").Value.Trim().ToLower().StartsWith("../resources/")); var sourceVals = sourceElements.ToSafeDictionary(c => c.Attribute("name").Value, inf.SourceFile); var targetVals = targetElements.ToSafeDictionary(c => c.Attribute("name").Value, inf.TargetFile); @@ -634,6 +717,11 @@ namespace LocalizationTool targetVals.ContainsKey(c.Key) ); + var yy = sourceVals.Values.Where(x => x.Value.Contains("System.Draw")).Concat(targetVals.Values.Where(x => x.Value.Contains("System.Draw"))); + if (yy.Count() != 0) + { + } + reportRoot.Add( new XElement("file", new XAttribute("filename", inf.TargetFile), diff --git a/Duplicati/Localization/Duplicati.Library.Utility.dll b/Duplicati/Localization/Duplicati.Library.Utility.dll index 38aa3d056..e5b21b70b 100644 Binary files a/Duplicati/Localization/Duplicati.Library.Utility.dll and b/Duplicati/Localization/Duplicati.Library.Utility.dll differ diff --git a/Duplicati/Localization/LocalizationTool.exe b/Duplicati/Localization/LocalizationTool.exe index b5c27a66c..1301b12bc 100644 Binary files a/Duplicati/Localization/LocalizationTool.exe and b/Duplicati/Localization/LocalizationTool.exe differ