public void I18n_GetNameTranslation_ShouldBeFrenchThenUSTranslation()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");

            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(_jsonLocalizationOptions);

            var frResult = localizer.GetString("Name");

            Assert.AreEqual("Nom", frResult.Value);

            CultureInfo.CurrentUICulture = new CultureInfo("en-US");
            var usResult = localizer.GetString("Name");

            Assert.AreEqual("Nom", frResult.Value);
        }
        public void I18n_Should_Read_Base_NotFound()
        {
            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(_jsonLocalizationOptions);
            LocalizedString result = localizer.GetString("Nop");

            Assert.AreEqual("Nop", result);
        }
예제 #3
0
        public void I18n_Should_ReadHirarchicalValue()
        {
            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(_jsonLocalizationOptions);
            LocalizedString result = localizer.GetString("Restricted.Sentence");

            Assert.AreEqual("You are not available is this area", result);
        }
        public void Should_SwitchCulture_WithoutReloadingLocalizer()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");

            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture = new CultureInfo("fr-FR")
            });

            LocalizedString result = localizer.GetString("BaseName1");

            Assert.AreEqual("Mon Nom de Base 1", result);

            CultureInfo.CurrentUICulture = new CultureInfo("en-US");

            result = localizer.GetString("BaseName1");

            Assert.AreEqual("My Base Name 1", result);
        }
        public void I18n_GetColorTranslation_ShouldBeUSTranslation()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("en-US");

            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(_jsonLocalizationOptions);

            var result = localizer.GetString("Color");

            Assert.AreEqual("Color", result.Value);
        }
        public void Should_Read_Base_NotFound()
        {
            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture = new CultureInfo("en-US")
            });
            LocalizedString result = localizer.GetString("Nop");

            Assert.AreEqual("Nop", result);
        }
        public void Should_SwitchCulture_FromWithCulture()
        {
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture = new CultureInfo("fr-FR")
            });

            localizer.WithCulture(new CultureInfo("en-US"));
            var result = localizer.GetString("BaseName1");

            Assert.AreEqual("My Base Name 1", result);
        }
        public void Should_Read_Base_Name1()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");

            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture = new CultureInfo("fr-FR")
            });

            LocalizedString result = localizer.GetString("BaseName1");

            Assert.AreEqual("Mon Nom de Base 1", result);
        }
        public void Should_Read_Default_Name1_US()
        {
            // Arrange
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture        = new CultureInfo("en-US"),
                SupportedCultureInfos = new System.Collections.Generic.HashSet <CultureInfo>()
                {
                    new CultureInfo("de-DE")
                }
            });
            LocalizedString result = localizer.GetString("BaseName1");

            Assert.AreEqual("My Base Name 1", result);
        }
        public void Should_Read_CaseInsensitive_UseDefault()
        {
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture        = new CultureInfo("en-US"),
                SupportedCultureInfos = new System.Collections.Generic.HashSet <CultureInfo>()
                {
                    new CultureInfo("de-DE")
                }
            });

            LocalizedString result = localizer.GetString("CaseInsensitiveCultureName");

            Assert.AreEqual("US English", result);
        }
예제 #11
0
        public void TestReadName1_ISOEncoding()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");
            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture        = new CultureInfo("en-US"),
                SupportedCultureInfos = new System.Collections.Generic.HashSet <CultureInfo>()
                {
                    new CultureInfo("fr-FR")
                },
                ResourcesPath = "encoding",
                FileEncoding  = Encoding.GetEncoding("ISO-8859-1")
            });

            LocalizedString result = localizer.GetString("Name1");

            Assert.AreEqual("Mon Nom 1", result);
        }
        public void Should_GetAllStrings_ByCaseInsensitiveCultureName()
        {
            CultureInfo.CurrentUICulture = new CultureInfo("fr-FR");

            JsonLocalizer.Localizer.JsonStringLocalizer localizer = JsonStringLocalizerHelperFactory.Create(new JsonLocalizationOptions()
            {
                DefaultCulture = new CultureInfo("fr-FR")
            });

            string[] expected = new[] {
                "Mon Nom de Base 1",
                "Mon Nom de Base 2",
                "French"
            };
            LocalizedString result = localizer.GetString("BaseName1");

            string[] results = localizer.GetAllStrings().Select(x => x.Value).ToArray();
            CollectionAssert.AreEquivalent(expected, results);
        }