Example #1
0
        public void EnDublicatesByContentTest()
        {
            var allRuTranslations = TranslationFiles
                                    .Where(file => file.Language == "ru")
                                    .SelectMany(item => item.Translations)
                                    .ToList();

            var allEnDuplicates = TranslationFiles
                                  .Where(file => file.Language == "en")
                                  .SelectMany(item => item.Translations)
                                  .GroupBy(t => t.Value)
                                  .Where(grp => grp.Count() > 1)
                                  .Select(grp => new { ContentKey = grp.Key, Count = grp.Count(), List = grp.ToList() })
                                  .OrderByDescending(itm => itm.Count)
                                  .ToList();

            var duplicatesKeys = new List <TranslationItem>();

            foreach (var item in allEnDuplicates)
            {
                var ruEquivalents = allRuTranslations
                                    .Where(t => item.List.Select(k => k.Key).Contains(t.Key))
                                    .GroupBy(t => t.Value)
                                    .Select(grp => new
                {
                    ContentKey = grp.Key,
                    Count      = grp.Count(),
                    Keys       = grp.Select(k => k.Key).ToList()
                })
                                    .Where(t => t.Count > 1)
                                    .ToList();

                if (!ruEquivalents.Any())
                {
                    continue;
                }

                duplicatesKeys.AddRange(
                    item.List.Where(item => ruEquivalents
                                    .SelectMany(k => k.Keys)
                                    .Any(k => k == item.Key)
                                    )
                    );
            }

            var duplicates = duplicatesKeys
                             .GroupBy(k => k.Value)
                             .Select(g => new { ContentKey = g.Key, Count = g.Count(), Keys = g.ToList() })
                             .ToList();

            Assert.AreEqual(0, duplicates.Count, string.Join(", ", duplicates.Select(d => JObject.FromObject(d).ToString())));
        }
Example #2
0
        public void FullEnDublicatesTest()
        {
            var fullEnDuplicates = TranslationFiles
                                   .Where(file => file.Language == "en")
                                   .SelectMany(item => item.Translations)
                                   .GroupBy(t => new { t.Key, t.Value })
                                   .Where(grp => grp.Count() > 1)
                                   .Select(grp => new { Key = grp.Key, Count = grp.Count(), Keys = grp.ToList() })
                                   .OrderByDescending(itm => itm.Count)
                                   .Select(grp => new { Key = grp.Key.Key, Value = grp.Key.Value, grp.Count })
                                   .ToList();

            Assert.AreEqual(0, fullEnDuplicates.Count, string.Join("\r\n", fullEnDuplicates.Select(d => JObject.FromObject(d).ToString())));
        }
Example #3
0
        public void NotFoundKeysTest()
        {
            var allEnKeys = TranslationFiles
                            .Where(file => file.Language == "en")
                            .SelectMany(item => item.Translations)
                            .Select(item => item.Key);

            var allJsTranslationKeys = JavaScriptFiles
                                       .Where(f => !f.Path.Contains("Banner.js")) // skip Banner.js (translations from firebase)
                                       .SelectMany(j => j.TranslationKeys)
                                       .Select(k => k.Substring(k.IndexOf(":") + 1))
                                       .Distinct();

            var notFoundJsKeys = allJsTranslationKeys.Except(allEnKeys);

            Assert.AreEqual(0, notFoundJsKeys.Count(),
                            "Some i18n-keys are not exist in translations in 'en' language: Keys: '{0}'",
                            string.Join("\r\n", notFoundJsKeys));
        }
Example #4
0
        public void DublicatesFilesByMD5HashTest()
        {
            var skipHashes = new List <string>()
            {
                "bcba174a8dadc0ff97f37f9a2d816d88",
                "2a506ed97d0fbd0858192b755ae122d0",
                "ec73989085d4e1b984c1c9dca10524da"
            };

            var duplicatesByMD5 = TranslationFiles
                                  .Where(t => !skipHashes.Contains(t.Md5Hash))
                                  .GroupBy(t => t.Md5Hash)
                                  .Where(grp => grp.Count() > 1)
                                  .Select(grp => new { Key = grp.Key, Count = grp.Count(), Paths = grp.ToList().Select(f => f.FilePath) })
                                  .OrderByDescending(itm => itm.Count)
                                  .ToList();

            Assert.AreEqual(0, duplicatesByMD5.Count, "Dublicates by MD5 hash:\r\n" + string.Join("\r\n", duplicatesByMD5.Select(d => $"\r\nMD5='{d.Key}':\r\n{string.Join("\r\n", d.Paths.Select(p => p))}'")));
        }
Example #5
0
        public void UselessTranslationKeysTest()
        {
            var allEnKeys = TranslationFiles
                            .Where(file => file.Language == "en")
                            .SelectMany(item => item.Translations)
                            .Select(item => item.Key)
                            .Where(k => !k.StartsWith("Culture_"));

            var allJsTranslationKeys = JavaScriptFiles
                                       .SelectMany(j => j.TranslationKeys)
                                       .Select(k => k.Substring(k.IndexOf(":") + 1))
                                       .Where(k => !k.StartsWith("Culture_"))
                                       .Distinct();

            var notFoundi18nKeys = allEnKeys.Except(allJsTranslationKeys);

            Assert.AreEqual(0, notFoundi18nKeys.Count(),
                            "Some i18n-keys are not found in js: \r\nKeys: '\r\n{0}'",
                            string.Join("\r\n", notFoundi18nKeys));
        }