Esempio n. 1
0
        public void TestEnumTranslationsInEnglish()
        {
            Language lang = _translations.FirstOrDefault(l => l.CommonName.Equals("English"));

            Assert.IsNotNull(lang, "Could not load english translation");
            Translator trans = new BasicTranslator(Path.Combine(_languagePath, lang.FileName));

            var enumsWithoutTranslation = new List <Type>();

            enumsWithoutTranslation.Add(typeof(ApiProvider));
            enumsWithoutTranslation.Add(typeof(EncryptionLevel)); ////Associated radio buttons get translated manually
            enumsWithoutTranslation.Add(typeof(LoggingLevel));

            EnsureApplicationResources();

            //Get assembly which defines the settings
            var assembly = Assembly.GetAssembly(typeof(PdfCreatorSettings));
            //Get all enumTypes in "pdfforge.PDFCreator.Core.Settings.Enums"
            var enumTypes = assembly.GetTypes().Where(t => String.Equals(t.Namespace, "pdfforge.PDFCreator.Core.Settings.Enums", StringComparison.Ordinal));

            //Remove all enumtypes without translation
            enumTypes = enumTypes.Where(e => !enumsWithoutTranslation.Contains(e));

            foreach (var e in enumTypes)
            {
                var values = Enum.GetValues(e);
                foreach (var v in values)
                {
                    string enumValue = e.Name + "." + v;
                    Assert.IsNotNullOrEmpty(trans.GetTranslation("Enums", enumValue), enumValue + " has no translation in " + lang.CommonName);
                }
            }
        }
Esempio n. 2
0
        public void AllLanguages_ContainSameTokensAsEnglish(string translation)
        {
            // These translations contain something that looks like a token, but it is okay if they do not match
            var exceptions = new[]
            {
                "pdfforge.PDFCreator.UI.Views.ActionControls.UserTokenActionControl\\DescriptionText.Text"
            };

            var englishLanguage =
                _translations.First(x => x.CommonName.Equals("English", StringComparison.InvariantCultureIgnoreCase));
            var englishTranslationData = Data.CreateDataStorage();
            var iniStorage             = new IniStorage();

            iniStorage.SetData(englishTranslationData);
            iniStorage.ReadData(Path.Combine(_languagePath, englishLanguage.FileName), true);

            var lang = GetLanguage(translation);

            var translationData = Data.CreateDataStorage();
            var translatedIni   = new IniStorage();

            translatedIni.SetData(translationData);
            translatedIni.ReadData(Path.Combine(_languagePath, lang.FileName), true);

            ITranslator trans = new BasicTranslator(lang.CommonName, translationData);

            foreach (var section in englishTranslationData.GetSubSections(""))
            {
                if (section.StartsWith("General"))
                {
                    continue;
                }

                var values = englishTranslationData.GetValues(section);

                foreach (var keyValuePair in values)
                {
                    if (exceptions.Contains(section + keyValuePair.Key))
                    {
                        continue;
                    }

                    var translatedString = trans.GetTranslation(section.TrimEnd('\\'), keyValuePair.Key);

                    if (translatedString != "")
                    {
                        ValidateSingleTranslation(keyValuePair.Value, translatedString, lang, section + keyValuePair.Key);
                    }
                }
            }
        }
Esempio n. 3
0
        public void AllErrorCodes_AreMappedByErrorCodeInterpreter()
        {
            var section = "ErrorCodes";

            var translator = new BasicTranslator(Path.Combine(_translationTestHelper.FindTranslationFolder(), "english.ini"));

            var errorCodes = translator.GetKeysForSection(section)
                             .Where(IsInt)
                             .Select(int.Parse)
                             .Select(x => (ErrorCode)x)
                             .ToList();

            Assert.IsTrue(errorCodes.Any(), $"There are no entries in the section [{section}]");

            var errorCodeInterpreter = new ErrorCodeInterpreter(translator);

            foreach (var errorCode in errorCodes)
            {
                Assert.IsTrue(Enum.IsDefined(typeof(ErrorCode), errorCode), $"The error code {(int)errorCode} is not defined");
                var message = errorCodeInterpreter.GetErrorText(errorCode, true);
                StringAssert.DoesNotContain("Default", message, $"Error code {errorCode} contains the word 'default', which indicates that it has not been translated.");
                StringAssert.DoesNotContain(translator.GetTranslation(section, "Default"), message, $"Error code {errorCode} has the default translation!");
            }
        }