diff --git a/MainWindow.resx b/MainWindow.resx index f322926..1116ddf 100644 --- a/MainWindow.resx +++ b/MainWindow.resx @@ -981,7 +981,7 @@ 2 - Analyze + Find Duplicates analyzeTab diff --git a/Panels/AnalyzeControlPanel.cs b/Panels/AnalyzeControlPanel.cs index 8d9a2ac..552049a 100644 --- a/Panels/AnalyzeControlPanel.cs +++ b/Panels/AnalyzeControlPanel.cs @@ -64,7 +64,7 @@ private void AnalyzeOnClick(object sender, EventArgs e) Comment = d.Element("comment")?.Value }) .Where(a => string.IsNullOrWhiteSpace(a.Comment) || - !(a.Comment.Contains("SKIP") || a.Comment.Contains("NODUP"))) + !(a.Comment.ContainsICIC("SKIP") || a.Comment.ContainsICIC("NODUP"))) .Select(d => d.Data); Log($"Resx contains {data.Count()} strings" + NL); diff --git a/ResxProvider.cs b/ResxProvider.cs index 72a5ba6..36727f2 100644 --- a/ResxProvider.cs +++ b/ResxProvider.cs @@ -35,7 +35,7 @@ public static List CollectStrings(XElement root) // TODO: what is this for? e.Attribute("name")?.Value.StartsWith(">>") != true && // SKIP is a special flag indicating this entry should not be translated - e.Element("comment")?.Value.Contains("SKIP") != true) + e.Element("comment")?.Value.ContainsICIC("SKIP") != true) .ToList(); } @@ -59,7 +59,7 @@ public static List CollectNewStrings(List data, string path) d.Attribute("type") == null && ( // collect all edited entries - d.Element("comment")?.Value.Contains("EDIT") == true || + d.Element("comment")?.Value.ContainsICIC("EDIT") == true || // collect entries that don't exist in target !target.Elements("data") .Any(e => e.Attribute("name")?.Value == d.Attribute("name").Value) @@ -84,8 +84,8 @@ public static List CollectNewStrings(List data, string path) public static int MergeHints(XElement root, XElement hints) { var count = 0; - foreach (var hint in hints.Elements()) - { + foreach (var hint in hints.Elements()) + { var preferred = hint.Element("preferred").Value.Trim(); var element = root.Elements("data").FirstOrDefault(e => @@ -102,7 +102,7 @@ public static int MergeHints(XElement root, XElement hints) } } - return count; + return count; } @@ -131,8 +131,8 @@ public static void SortData(XElement root) var files = data .Where(e => e.Attribute("type") != null) .Select(e => new { Element = e, Values = e.Element("value").Value.Split(';') }) - .OrderBy(e => e.Values[1]) // type - .ThenBy(e => e.Values[0]) // path + .OrderBy(e => e.Values[1]) // type + .ThenBy(e => e.Values[0]) // path .ThenBy(e => e.Element.Attribute("name").Value) .Select(e => e.Element) .ToList(); diff --git a/StringExtensions.cs b/StringExtensions.cs index 2d3acb7..ee39165 100644 --- a/StringExtensions.cs +++ b/StringExtensions.cs @@ -1,9 +1,10 @@ //************************************************************************************************ -// Copyright © 2020 Steven M Cohn. All rights reserved. +// Copyright © 2020 Steven M Cohn. All rights reserved. //************************************************************************************************ namespace ResxTranslator { + using System; using System.Text; @@ -24,6 +25,24 @@ internal static class StringExtensions private static readonly char[] EscapeChars = new char[] { '<', '>', '&' }; + /// + /// Compares a string against the given instance, as non-case-sensitive. + /// + /// The string instance + /// The other string for comparison + /// True if the instance contains at least one occurance of value + public static bool ContainsICIC(this string s, string value) + { + return s.IndexOf(value, StringComparison.InvariantCultureIgnoreCase) >= 0; + } + + + /// + /// Escapes special XML characters in the given text values so those characters + /// survive round-trips as user-input text + /// + /// The user input string + /// The user string with special XML characters escaped public static string XmlEscape(this string str) { if (str == null) diff --git a/Translator.cs b/Translator.cs index a9b350c..4e276ad 100644 --- a/Translator.cs +++ b/Translator.cs @@ -355,7 +355,7 @@ public async Task TranslateResx( continue; } - var editing = data[index].Element("comment")?.Value.Contains("EDIT") == true; + var editing = data[index].Element("comment")?.Value.ContainsICIC("EDIT") == true; var name = editing ? $"{data[index].Attribute("name").Value} (EDITED)" @@ -478,7 +478,7 @@ public static int ClearMarkers(string path) { var root = XElement.Load(path); var comments = root.Elements("data").Elements("comment") - .Where(e => e.Value.Contains("EDIT")); + .Where(e => e.Value.ContainsICIC("EDIT")); if (comments.Any()) {