Example #1
0
        public void Set_New_Translation_Should_Create_Non_Existing_Entries()
        {
            lock (ConnectionString)
            {
                CleanDatabase();

                var key         = "Key";
                var translation = "Translation";
                var collection  = "some_collection";
                var category    = "some_category";
                var culture     = new CultureInfo("en-US");

                _provider.Set(key, translation, collection, category, culture);

                var insertedEntry = _provider.Get(key, null, null, culture);

                Assert.NotNull(insertedEntry);
                Assert.Equal(translation, insertedEntry.Value);

                Assert.NotNull(insertedEntry.LocalizationLanguage);
                Assert.Equal(culture.DisplayName, insertedEntry.LocalizationLanguage.Name);
                Assert.Equal(culture.TwoLetterISOLanguageName, insertedEntry.LocalizationLanguage.Value);

                Assert.NotNull(insertedEntry.LocalizationKey);
                Assert.Equal(key, insertedEntry.LocalizationKey.Name);

                Assert.NotNull(insertedEntry.LocalizationCollection);
                Assert.Equal(collection, insertedEntry.LocalizationCollection.Name);

                Assert.NotNull(insertedEntry.LocalizationCollection.LocalizationCategory);
                Assert.Equal(category, insertedEntry.LocalizationCollection.LocalizationCategory.Name);

                CleanDatabase();
            }
        }
Example #2
0
        /// <summary>
        /// Translate key in all colections
        /// </summary>
        /// <param name="localizationProvider"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string Translate(this ILocalizationProvider localizationProvider, string key, CultureInfo culture = null)
        {
            if (string.IsNullOrEmpty(key))
            {
                return(null);
            }

            var value = localizationProvider.Get(key, culture: culture)?.Value;

            return(value ?? $"Oops! {key} is not translated!");
        }
Example #3
0
        public void Localization_FromFile_Exists()
        {
            var message = _provider.Get("SOME_KEY", null, null, new CultureInfo("en-US"));

            Assert.Equal("Some message", message.Value);
        }