public IEnumerable <string> GetWarnings(ExtractedText entry) { if (entry == null) { throw new ArgumentNullException(nameof(entry)); } var warnings = new List <string>(); if (string.IsNullOrEmpty(entry.English)) { return(warnings); } var cleanText = entry.English?.Replace("\n", "\\n").Replace("\r", "\\r").Replace("\t", "\\t"); var numbersInJapanese = Regex.Matches(entry.Japanese, @"(\d+)"); //var numbersInKorean = Regex.Matches(entry.Korean, @"(\d+)"); var numbersInEnglish = Regex.Matches(entry.English, @"(\d+)"); if (numbersInJapanese.Count < 1 && numbersInEnglish.Count < 1) { return(warnings); } var japaneseValues = numbersInJapanese.Select(m => m.Captures.First().Value); var englishValues = numbersInEnglish.Select(m => m.Captures.First().Value); var source = entry.Source; if (entry.SourceLine > 0) { source += $":{entry.SourceLine}"; } foreach (var match in englishValues.Except(japaneseValues)) { if (japaneseValues.Contains(ConvertAscii(match))) { continue; } warnings.Add($"{source}: Number in English text but not Japanese: '{match}'"); } foreach (var match in japaneseValues.Except(englishValues)) { if (englishValues.Contains(ConvertUnicode(match))) { continue; } if (ConvertUnicode(match) == "1" && entry.English.Contains("once", StringComparison.OrdinalIgnoreCase)) { continue; } warnings.Add($"{source}: Number in Japanese text but not English: '{match}'"); } return(warnings); }
private void AddToCatalog(POCatalog catalog, ExtractedText extractedEntry) { var catalogKey = new POKey(extractedEntry.Japanese); var catalogEntry = new POSingularEntry(catalogKey) { Comments = new List <POComment> { new POReferenceComment { References = new POSourceReference[] { new POSourceReference($"{extractedEntry.Source}", extractedEntry.SourceLine) } } }, }; if (!string.IsNullOrEmpty(extractedEntry.English)) { catalogEntry.Translation = extractedEntry.English.Trim(' '); } var comment = extractedEntry.Comment ?? ""; // If we have Korean text add it to the comment as well. This gives us multiple strings to throw at a // machine translator to hopefully get better context. if (!string.IsNullOrEmpty(extractedEntry.Korean) && extractedEntry.Korean != extractedEntry.Japanese && !comment.Contains("Korean Text: ", StringComparison.Ordinal)) { if (comment.Length > 0) { comment += "; "; } // The comment we save the Korean text in can't contain new lines, tabs are just for visual convenience comment += "Korean Text: '" + extractedEntry.Korean.Replace("\r", "\\r", StringComparison.Ordinal) .Replace("\n", "\\n", StringComparison.Ordinal) .Replace("\t", "\\t", StringComparison.Ordinal) + "'"; } if (!string.IsNullOrEmpty(comment)) { catalogEntry.Comments.Add(new POTranslatorComment() { Text = comment }); } catalog.Add(catalogEntry); }