コード例 #1
0
        private string GetTranslation(string resourceKey, CultureInfo language, bool exactLanguage)
        {
            if (string.IsNullOrEmpty(resourceKey))
            {
                return(null);
            }

            //check for changes everytime (changes-dict can update late, incase of ExcelFileProvider).
            TryAddChangesIntoDictOfDicts();

            return(CultureInfoUtil.GetLanguageDictValueOrDefault(_dictOfDicts, language, resourceKey,
                                                                 InputLanguage, exactLanguage));
        }
コード例 #2
0
        public void TryGetLanguageDict_NoMatchesInDictionaryAlAllWithoutExact_ReturnsNull()
        {
            //Arrange
            var dictionary    = DictionaryExample;
            var targetCulture = new CultureInfo("fr");
            var inputCulture  = new CultureInfo("id-ID");
            var key           = "accept";
            var useExact      = false;

            //Act
            var returnTranslation =
                CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, key, inputCulture, useExact);

            //Assert
            Assert.AreEqual(null, returnTranslation);
        }
コード例 #3
0
        public void TryGetLanguageDict_TargetParentIsInDictionaryWithExact_ReturnsNull()
        {
            //Arrange
            var dictionary    = DictionaryExample;
            var targetCulture = new CultureInfo("en-US");
            var inputCulture  = new CultureInfo("id-ID");
            var key           = "accept";
            var useExact      = true;

            //Act
            var returnTranslation =
                CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, key, inputCulture, useExact);

            //Assert
            Assert.AreEqual(null, returnTranslation);
        }
コード例 #4
0
        public void TryGetLanguageDict_TargetIsInDictionary_ReturnsCorrespondingTranslation(bool useExact)
        {
            //Arrange
            var dictionary          = DictionaryExample;
            var targetCulture       = new CultureInfo("en");
            var inputCulture        = new CultureInfo("id-ID");
            var key                 = "accept";
            var expectedTranslation = DictionaryExample[targetCulture][key];

            //Act
            var returnTranslation =
                CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, key, inputCulture, useExact);

            //Assert
            Assert.AreEqual(expectedTranslation, returnTranslation);
        }
コード例 #5
0
        public void TryGetLanguageDict_NoMatchesInDictionaryWithoutExact_ReturnsInputTranslation()
        {
            //Arrange
            var dictionary          = DictionaryExample;
            var targetCulture       = new CultureInfo("fr");
            var inputCulture        = new CultureInfo("de");
            var key                 = "accept";
            var useExact            = false;
            var expectedTranslation = DictionaryExample[inputCulture][key];

            //Act
            var returnTranslation =
                CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, key, inputCulture, useExact);

            //Assert
            Assert.AreEqual(expectedTranslation, returnTranslation);
        }
コード例 #6
0
        public void TryGetLanguageDict_TargetParentIsInDictionaryWithoutExact_ReturnsParentTranslation()
        {
            //Arrange
            var dictionary          = DictionaryExample;
            var targetCulture       = new CultureInfo("en-US");
            var parentOfTarget      = targetCulture.Parent;
            var inputCulture        = new CultureInfo("id-ID");
            var key                 = "accept";
            var useExact            = false;
            var expectedTranslation = DictionaryExample[parentOfTarget][key];

            //Act
            var returnTranslation =
                CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, key, inputCulture, useExact);

            //Assert
            Assert.AreEqual(expectedTranslation, returnTranslation);
        }
コード例 #7
0
        public void TryGetLanguageDict_AnyParameterNull_ThrowsArgumentNullException()
        {
            //Arrange
            var dictionary    = DictionaryExample;
            var targetCulture = new CultureInfo("en-UK");
            var inputCulture  = new CultureInfo("en-US");
            var key           = "key";
            var useExact      = false;

            //Act //Assert
            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           CultureInfoUtil.GetLanguageDictValueOrDefault(null, targetCulture, key, inputCulture, useExact));
            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, null, key, inputCulture, useExact));
            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, null, inputCulture, useExact));
            Assert.ThrowsException <ArgumentNullException>(() =>
                                                           CultureInfoUtil.GetLanguageDictValueOrDefault(dictionary, targetCulture, key, null, useExact));
        }
コード例 #8
0
        private TextLocalization GetLiteral(CultureInfo language, string dialogName, string type, string elementName,
                                            bool exactLanguage)
        {
            var key = CreateGuiDictionaryKey(dialogName, type, elementName);

            var dictOfDicts = GetDictionaryFromFileProvider();

            var result = CultureInfoUtil.GetLanguageDictValueOrDefault(dictOfDicts, language, key,
                                                                       InputLanguage, exactLanguage);

            if (result == null && !exactLanguage)
            {
                _logger.Log(LogLevel.Debug,
                            "Found no translation for dialog '{0}', type '{1}', name '{2}' and language '{3}'.",
                            dialogName, type, elementName, language);
            }

            result = EscapedStringConverter.ToNormalString(result);

            return(new TextLocalization {
                Language = language, Text = result
            });
        }