示例#1
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]
        {
            get
            {
                var value = _localizationProvider.GetString(
                    _keyBuilder.BuildResourceKey(_containerType, _propertyName, _validatorMetadata));

                return(new LocalizedString(name, value ?? name, value == null));
            }
        }
示例#3
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());
        }
        internal string GetTranslation(string resourceKey)
        {
            var result = resourceKey;

            if (!_configurationContext.EnableLocalization())
            {
                return(result);
            }

            var localizedDisplayName = _localizationProvider.GetString(resourceKey);

            result = localizedDisplayName;

            // for the legacy purposes - we need to look for this resource translation using display name
            // once again - this will make sure that existing XPath resources are still working
            if (localizedDisplayName != null && !_configurationContext.ShouldLookupResource(localizedDisplayName))
            {
                result = _localizationProvider.GetString(localizedDisplayName);
            }

            // If other data annotations exists except for [Display], an exception is thrown when display name is ""
            // It should be null to avoid exception as ModelMetadata.GetDisplayName only checks for null and not String.Empty
            return(string.IsNullOrWhiteSpace(localizedDisplayName) ? null : result);
        }
        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)));
        }
示例#6
0
 public string GetTranslation()
 {
     return(_provider.GetString(() => ResourceClass.SomeProperty));
 }