public void NotAllLanguageTranslatedTest() { var groupedByLng = TranslationFiles .GroupBy(t => t.Language) .Select(grp => new { Lng = grp.Key, Count = grp.Count(), Files = grp.ToList() }) .ToList(); // Uncomment if new language is needed //var newLng = "sk"; //if (!groupedByLng.Exists(t => t.Lng == newLng)) // groupedByLng.Add(new { Lng = newLng, Count = 0, Files = new List<TranslationFile>() }); var enGroup = groupedByLng.Find(f => f.Lng == "en"); var expectedCount = enGroup.Count; var otherLngs = groupedByLng.Where(g => g.Lng != "en"); var incompleteList = otherLngs .Where(lng => lng.Count != expectedCount) .Select(lng => new { Issue = $"Language '{lng.Lng}' (Count={lng.Count}). Not found files:\r\n", lng.Lng, lng.Files }) .ToList(); var message = $"Next languages are not equal 'en' (Count= {expectedCount}) by translated files count:\r\n\r\n"; if (incompleteList.Count > 0) { var enFilePaths = enGroup.Files.Select(f => f.FilePath); for (int i = 0; i < incompleteList.Count; i++) { var lng = incompleteList[i]; message += $"\r\n\r\n{i}. {lng.Issue}\r\n"; var lngFilePaths = lng.Files.Select(f => f.FilePath).ToList(); var notFoundFilePaths = enFilePaths .Select(p => p.Replace("\\en\\", $"\\{lng.Lng}\\")) .Where(p => !lngFilePaths.Contains(p)); message += string.Join("\r\n", notFoundFilePaths); /* Save empty 'EN' keys to not found files */ /*foreach (var path in notFoundFilePaths) * { * SaveNotFoundLanguage(path.Replace($"\\{lng.Lng}\\", "\\en\\"), path); * }*/ } } Assert.AreEqual(0, incompleteList.Count, message); }
public void LanguageTranslatedPercentTest() { var message = $"Next languages translated less then 100%:\r\n\r\n"; var groupedByLng = TranslationFiles .GroupBy(t => t.Language) .Select(g => new { Language = g.Key, AllTranslated = g.ToList() .SelectMany(t => t.Translations) .ToList() }) .Select(t => new { t.Language, TotalKeysCount = t.AllTranslated.LongCount(), EmptyKeysCount = t.AllTranslated .Where(t => string.IsNullOrEmpty(t.Value)) .LongCount() }) .ToList(); var i = 0; var exists = false; var expectedTotalKeysCount = groupedByLng.Where(t => t.Language == "en").Single().TotalKeysCount; foreach (var lng in groupedByLng) { if (lng.EmptyKeysCount == 0 && lng.TotalKeysCount == expectedTotalKeysCount) { continue; } exists = true; var translated = lng.TotalKeysCount == expectedTotalKeysCount ? Math.Round(100f - (lng.EmptyKeysCount * 100f / expectedTotalKeysCount), 1) : Math.Round(lng.TotalKeysCount * 100f / expectedTotalKeysCount, 1); message += $"{++i}. Language '{lng.Language}' translated by '{translated}%'\r\n"; } Assert.AreEqual(false, exists, message); }
public void SpellCheckTest() { const string dictionariesPath = @"..\..\..\dictionaries"; var i = 0; var errorsCount = 0; var message = $"Next keys have spell check issues:\r\n\r\n"; //var list = new List<SpellCheckExclude>(); var groupByLng = TranslationFiles .GroupBy(t => t.Language) .Select(g => new { Language = g.Key, Files = g.ToList() }) .ToList(); foreach (var group in groupByLng) { try { var language = SpellCheck.GetDictionaryLanguage(group.Language); //var spellCheckExclude = new SpellCheckExclude(group.Language); using (var dictionaryStream = File.OpenRead(Path.Combine(dictionariesPath, language, $"{language}.dic"))) using (var affixStream = File.OpenRead(Path.Combine(dictionariesPath, language, $"{language}.aff"))) { var dictionary = WordList.CreateFromStreams(dictionaryStream, affixStream); foreach (var g in group.Files) { foreach (var item in g.Translations) { var result = SpellCheck.HasSpellIssues(item.Value, group.Language, dictionary); if (result.HasProblems) { message += $"{++i}. lng='{group.Language}' file='{g.FilePath}'\r\nkey='{item.Key}' value='{item.Value}'\r\nIncorrect words:\r\n{string.Join("\r\n", result.SpellIssues.Select(issue => $"'{issue.Word}' Suggestion: '{issue.Suggestions.FirstOrDefault()}'"))}\r\n\r\n"; errorsCount++; /*foreach (var word in result.SpellIssues * .Where(issue => issue.Suggestions.Any()) * .Select(issue => issue.Word)) * { * if (!spellCheckExclude.Excludes.Contains(word)) * { * spellCheckExclude.Excludes.Add(word); * } * }*/ } } } } //spellCheckExclude.Excludes.Sort(); //list.Add(spellCheckExclude); } catch (NotSupportedException) { // Skip not supported continue; } } //string json = JsonConvert.SerializeObject(list, Formatting.Indented); //File.WriteAllText("../../../spellcheck-excludes.json", json); Assert.AreEqual(0, errorsCount, message); }
public void WrongTranslationVariablesTest() { var message = $"Next keys have wrong variables:\r\n\r\n"; var regVariables = new Regex("\\{\\{([^\\{].?[^\\}]+)\\}\\}", RegexOptions.Compiled | RegexOptions.Multiline); var groupedByLng = TranslationFiles .GroupBy(t => t.Language) .Select(g => new { Language = g.Key, TranslationsWithVariables = g.ToList() .SelectMany(t => t.Translations) .Where(k => k.Value.IndexOf("{{") != -1) .Select(t => new { t.Key, t.Value, Variables = regVariables.Matches(t.Value) .Select(m => m.Groups[1]?.Value?.Trim().Replace(", lowercase", "")) .ToList() }) .ToList() }) .ToList(); var enWithVariables = groupedByLng .Where(t => t.Language == "en") .SelectMany(t => t.TranslationsWithVariables) .ToList(); var otherLanguagesWithVariables = groupedByLng .Where(t => t.Language != "en") .ToList(); var i = 0; var errorsCount = 0; foreach (var lng in otherLanguagesWithVariables) { foreach (var t in lng.TranslationsWithVariables) { var enKey = enWithVariables .Where(en => en.Key == t.Key) .FirstOrDefault(); if (enKey == null) { // wrong message += $"{++i}. lng='{lng.Language}' key='{t.Key}' has no 'en' language variant (!!!useless key!!!)\r\n\r\n"; errorsCount++; continue; } if (enKey.Variables.Count != t.Variables.Count) { // wrong message += $"{++i}. lng='{lng.Language}' key='{t.Key}' has less variables then 'en' language have " + $"(en={enKey.Variables.Count}|{lng.Language}={t.Variables.Count})\r\n" + $"'en': '{enKey.Value}'\r\n'{lng.Language}': '{t.Value}'\r\n\r\n"; errorsCount++; } if (!t.Variables.All(v => enKey.Variables.Contains(v))) { // wrong errorsCount++; message += $"{++i}. lng='{lng.Language}' key='{t.Key}' has not equals variables of 'en' language have\r\n\r\n" + $"Have to be:\r\n'{enKey.Value}'\r\n\r\n{string.Join("\r\n", enKey.Variables)}\r\n\r\n" + $"But in real:\r\n'{t.Value}'\r\n\r\n{string.Join("\r\n", t.Variables)} \r\n\r\n"; } } } Assert.AreEqual(0, errorsCount, message); }