Translations tests refactoring

This commit is contained in:
Alexey Safronov 2022-12-02 15:56:52 +03:00
parent c0d1645b45
commit d401c06876

View File

@ -194,10 +194,11 @@ public class Tests
JavaScriptFiles = new List<JavaScriptFile>(); JavaScriptFiles = new List<JavaScriptFile>();
var pattern1 = "[.{\\s\\(]t\\(\\s*[\"\'`]([a-zA-Z0-9_.:_\\s{}/_-]+)[\"\'`]\\s*[\\),]"; var pattern1 = "[.{\\s\\(]t\\(\\s*[\"\'`]([a-zA-Z0-9_.:\\s{}/-]+)[\"\'`]\\s*[\\),]";
var pattern2 = "i18nKey=\"([a-zA-Z0-9_.-]+)\""; var pattern2 = "i18nKey=\"([a-zA-Z0-9_.:-]+)\"";
var pattern3 = "tKey:\\s\"([a-zA-Z0-9_.:-]+)\"";
var regexp = new Regex($"({pattern1})|({pattern2})", RegexOptions.Multiline | RegexOptions.ECMAScript); var regexp = new Regex($"({pattern1})|({pattern2})|({pattern3})", RegexOptions.Multiline | RegexOptions.ECMAScript);
var notTranslatedToastsRegex = new Regex("(?<=toastr.info\\([\"`\'])(.*)(?=[\"\'`])" + var notTranslatedToastsRegex = new Regex("(?<=toastr.info\\([\"`\'])(.*)(?=[\"\'`])" +
"|(?<=toastr.error\\([\"`\'])(.*)(?=[\"\'`])" + "|(?<=toastr.error\\([\"`\'])(.*)(?=[\"\'`])" +
@ -210,18 +211,15 @@ public class Tests
{ {
var jsFileText = File.ReadAllText(path); var jsFileText = File.ReadAllText(path);
if (!path.Contains("asc-web-components")) var toastMatches = notTranslatedToastsRegex.Matches(jsFileText).ToList();
{
var toastMatches = notTranslatedToastsRegex.Matches(jsFileText).ToList();
if (toastMatches.Any()) if (toastMatches.Any())
{
foreach (var toastMatch in toastMatches)
{ {
foreach (var toastMatch in toastMatches) var found = toastMatch.Value;
{ if (!string.IsNullOrEmpty(found) && !NotTranslatedToasts.Exists(t => t.Value == found))
var found = toastMatch.Value; NotTranslatedToasts.Add(new KeyValuePair<string, string>(path, found));
if (!string.IsNullOrEmpty(found) && !NotTranslatedToasts.Exists(t => t.Value == found))
NotTranslatedToasts.Add(new KeyValuePair<string, string>(path, found));
}
} }
} }
@ -702,13 +700,15 @@ public class Tests
.Where(file => file.Language == "en") .Where(file => file.Language == "en")
.SelectMany(item => item.Translations) .SelectMany(item => item.Translations)
.Select(item => item.Key) .Select(item => item.Key)
.Where(k => !k.StartsWith("Culture_")); .Where(k => !k.StartsWith("Culture_"))
.OrderBy(t => t);
var allJsTranslationKeys = JavaScriptFiles var allJsTranslationKeys = JavaScriptFiles
.SelectMany(j => j.TranslationKeys) .SelectMany(j => j.TranslationKeys)
.Select(k => k.Substring(k.IndexOf(":") + 1)) .Select(k => k.Substring(k.IndexOf(":") + 1))
.Where(k => !k.StartsWith("Culture_")) .Where(k => !k.StartsWith("Culture_"))
.Distinct(); .Distinct()
.OrderBy(t => t);
var notFoundi18nKeys = allEnKeys.Except(allJsTranslationKeys); var notFoundi18nKeys = allEnKeys.Except(allJsTranslationKeys);