Esempio n. 1
0
        /// <summary>
        /// Returns localized string by name
        /// </summary>
        /// <param name="name">Name of the string to localize</param>
        /// <returns>Localized string by name</returns>
        LocalizedString IStringLocalizer.this[string name]
        {
            get
            {
                var value = _localizationProvider.GetStringByCulture(name, _culture ?? CultureInfo.CurrentUICulture);

                return(new LocalizedString(name, value ?? name, value == null));
            }
        }
        public ActionResult Index(StartPage currentPage, string lg)
        {
            if (!string.IsNullOrEmpty(lg))
            {
                CultureInfo.CurrentUICulture = new CultureInfo(lg);
            }

            LogManager.GetLogger(typeof(StartPageController)).Log(Level.Information, "Test log message");

            // register manually some of the resources
            _synchronizer.RegisterManually(new List <ManualResource>
            {
                new ManualResource("Manual.Resource.1", "English translation", new CultureInfo("en"))
            });

            var tr    = _provider.GetString("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue");
            var trSv  = _provider.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue", new CultureInfo("sv"));
            var trInv = _provider.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue", CultureInfo.InvariantCulture);
            var trLv  = _provider.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue", new CultureInfo("lv"));

            var svc    = _service.GetString("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue");
            var svcSv  = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue", new CultureInfo("sv"));
            var svcInv = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue", CultureInfo.InvariantCulture);
            var svcLv  = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.SecondValue", new CultureInfo("lv"));

            // this will be null
            var nullRes = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Resources.NullResource.NullProperty", new CultureInfo("lv"));

            var enumTr  = SomeValuesEnum.FirstValue.Translate();
            var enumSv  = SomeValuesEnum.FirstValue.TranslateByCulture(new CultureInfo("sv"));
            var enumInv = SomeValuesEnum.FirstValue.TranslateByCulture(CultureInfo.InvariantCulture);
            var enumLv  = SomeValuesEnum.FirstValue.TranslateByCulture(new CultureInfo("lv"));

            var thirdEnumTr  = SomeValuesEnum.ThirdOne.Translate();
            var thirdEnumSv  = SomeValuesEnum.ThirdOne.TranslateByCulture(new CultureInfo("sv"));
            var thirdEnumInv = SomeValuesEnum.ThirdOne.TranslateByCulture(CultureInfo.InvariantCulture);
            var thirdEnumLv  = SomeValuesEnum.ThirdOne.TranslateByCulture(new CultureInfo("lv"));

            var thirdSvc    = _service.GetString("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.ThirdOne");
            var thirdSvcSv  = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.ThirdOne", new CultureInfo("sv"));
            var thirdSvcInv = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.ThirdOne", CultureInfo.InvariantCulture);
            var thirdSvcLv  = _service.GetStringByCulture("DbLocalizationProvider.EPiServer.Sample.Models.Pages.SomeValuesEnum.ThirdOne", new CultureInfo("lv"));

            return(View(new StartPageViewModel(currentPage)));
        }
Esempio n. 3
0
        public IActionResult Index()
        {
            var u = ControllerContext.HttpContext.User?.Identity;

            var zz = _provider.GetStringByCulture(() => ResourcesForFallback.OnlyInInvariant, new CultureInfo("sv"));

            ViewData["TestString"] = _provider.GetString(() => Resources.Shared.CommonResources.Yes);
            return(View());
        }
        public LocalizedString this[string name, params object[] arguments]
        {
            get
            {
                var value = _localizationProvider.GetStringByCulture(
                    _keyBuilder.BuildResourceKey(_containerType, _propertyName, _validatorMetadata),
                    _culture,
                    arguments);

                return(new LocalizedString(name, value ?? name, value == null));
            }
        }
Esempio n. 5
0
        public IActionResult Index()
        {
            // register manually some of the resources
            _synchronizer.RegisterManually(new List <ManualResource>
            {
                new ManualResource("Manual.Resource.1", "English translation", new CultureInfo("en"))
            });

            var u = ControllerContext.HttpContext.User?.Identity;

            var zz = _provider.GetStringByCulture(() => ResourcesForFallback.OnlyInInvariant, new CultureInfo("sv"));

            ViewData["TestString"] = _provider.GetString(() => Resources.Shared.CommonResources.Yes);
            return(View());
        }