Ejemplo n.º 1
0
        public HomeController(IStringLocalizerFactory stringLocalizerFactory, IStringLocalizer<HomeController> T)
        {
            var stringLocalizer = stringLocalizerFactory.Create("Test", location: null);

            var resourceFiles = typeof(HomeController).Assembly.GetManifestResourceNames();
            foreach (var resFile in resourceFiles)
                Console.WriteLine(resFile.ToString());
            //bug 1. See the base name contruction is with capital in the ResourceManagerStringLocalizerFactory.cs
            Console.WriteLine("Watch the capital problem in the 2e localize");

            //Make sure this is working
            Console.WriteLine(T["test"], T["test"].ResourceNotFound.ToString());
            //bug 2
            Console.WriteLine(T.WithCulture(new CultureInfo("nl-NL"))["test"] + ":" + T["test"].ResourceNotFound.ToString() + "should be false!!!"); ;
            Console.WriteLine(T.WithCulture(new CultureInfo("nl-NL"))["Hello"]);
            Console.WriteLine(T.WithCulture(new CultureInfo("nl"))["Hello"]);
            Console.WriteLine(T.WithCulture(new CultureInfo(""))["Hello"]);

            var specific = T.WithCulture(new CultureInfo("nl-NL")).GetAllStrings(true);
            var neutral = T.WithCulture(new CultureInfo("nl")).GetAllStrings(true);
            var invariant = T.WithCulture(new CultureInfo("")).GetAllStrings(true);

            // bug 1 will crashes because of capital problem
            // bug 3 this should not crash at all but the wrong execption is catched MissingManifestResourceException
            // But swallowed  the null Exception in GetResourceNamesFromCultureHierarchy doesn't see a good idea
            foreach (string s in invariant)
                Console.WriteLine(s);
            Debugger.Launch();
            // will 4 will crash because of missing resource file
            foreach (string s in specific)
                Console.WriteLine(s);
            foreach (string s in neutral)
                Console.WriteLine(s);
        }
 /// <summary>
 /// Create a new instance of <see cref="DataAnnotationsModelValidatorProvider"/>.
 /// </summary>
 /// <param name="options">The <see cref="IOptions{MvcDataAnnotationsLocalizationOptions}"/>.</param>
 /// <param name="stringLocalizerFactory">The <see cref="IStringLocalizerFactory"/>.</param>
 public DataAnnotationsModelValidatorProvider(
     IOptions<MvcDataAnnotationsLocalizationOptions> options,
     IStringLocalizerFactory stringLocalizerFactory)
 {
     _options = options;
     _stringLocalizerFactory = stringLocalizerFactory;
 }
 public Func<string, string> GetLocalizerFunction(IStringLocalizerFactory factory)
 {
     if (LocalizerType != null)
     {
         var localizer = factory.Create(LocalizerType);
         return x => localizer[x];
     }
     else return x => x;
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="HtmlLocalizerFactory"/>.
        /// </summary>
        /// <param name="localizerFactory">The <see cref="IStringLocalizerFactory"/>.</param>
        public HtmlLocalizerFactory(IStringLocalizerFactory localizerFactory)
        {
            if (localizerFactory == null)
            {
                throw new ArgumentNullException(nameof(localizerFactory));
            }

            _factory = localizerFactory;
        }
 public GridTagHelper(IOptions<MvcViewOptions> optionsAccessor,
     IHtmlHelper html, 
     IHttpContextAccessor httpAccessor, IViewComponentHelper component, 
     IUrlHelperFactory urlHelperFactory,
     IStringLocalizerFactory factory)
 {
     IdAttributeDotReplacement = optionsAccessor.Value.HtmlHelperOptions.IdAttributeDotReplacement;
     this.html = html;
     this.httpAccessor = httpAccessor;
     this.component = component;
     this.urlHelperFactory = urlHelperFactory;
     this.factory = factory;
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new <see cref="HtmlLocalizer"/>.
        /// </summary>
        /// <param name="localizerFactory">The <see cref="IStringLocalizerFactory"/>.</param>
        /// <param name="encoder">The <see cref="IHtmlEncoder"/>.</param>
        public HtmlLocalizerFactory(IStringLocalizerFactory localizerFactory, IHtmlEncoder encoder)
        {
            if (localizerFactory == null)
            {
                throw new ArgumentNullException(nameof(localizerFactory));
            }

            if (encoder == null)
            {
                throw new ArgumentNullException(nameof(encoder));
            }

            _factory = localizerFactory;
            _encoder = encoder;
        }
        /// <summary>
        /// Create a new instance of <see cref="DataAnnotationsClientModelValidatorProvider"/>.
        /// </summary>
        /// <param name="options">The <see cref="IOptions{MvcDataAnnotationsLocalizationOptions}"/>.</param>
        /// <param name="stringLocalizerFactory">The <see cref="IStringLocalizerFactory"/>.</param>
        public DataAnnotationsClientModelValidatorProvider(
            IValidationAttributeAdapterProvider validationAttributeAdapterProvider,
            IOptions<MvcDataAnnotationsLocalizationOptions> options,
            IStringLocalizerFactory stringLocalizerFactory)
        {
            if (validationAttributeAdapterProvider == null)
            {
                throw new ArgumentNullException(nameof(validationAttributeAdapterProvider));
            }
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            _validationAttributeAdapterProvider = validationAttributeAdapterProvider;
            _options = options;
            _stringLocalizerFactory = stringLocalizerFactory;
        }
Ejemplo n.º 8
0
        private static ClientModelValidationContext GetValidationContext(
            IUrlHelper urlHelper,
            IStringLocalizerFactory localizerFactory = null,
            IModelMetadataProvider metadataProvider = null)
        {
            var serviceCollection = GetServiceCollection(localizerFactory);
            var factory = new Mock<IUrlHelperFactory>(MockBehavior.Strict);
            serviceCollection.AddSingleton<IUrlHelperFactory>(factory.Object);

            var serviceProvider = serviceCollection.BuildServiceProvider();
            var actionContext = GetActionContext(serviceProvider, routeData: null);

            factory
                .Setup(f => f.GetUrlHelper(actionContext))
                .Returns(urlHelper);

            var metadata = _metadata;
            if (metadataProvider == null)
            {
                metadataProvider = _metadataProvider;
            }
            else
            {
                metadata = metadataProvider.GetMetadataForProperty(typeof(string), nameof(string.Length));
            }

            return new ClientModelValidationContext(
                actionContext,
                metadata,
                metadataProvider,
                new AttributeDictionary());
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="defaultTemplateProvider">Default Template Provider</param>
 /// <param name="cachedDbAccess">Cached Db Access</param>        
 /// <param name="languageKeyGenerator">Language Key Generator</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 /// <param name="isPlayer">true if the renderer is for the player, else false</param>
 public ChangeNpcStateActionRenderer(ICachedExportDefaultTemplateProvider defaultTemplateProvider, IExportCachedDbAccess cachedDbAccess, ILanguageKeyGenerator languageKeyGenerator, IStringLocalizerFactory localizerFactory, bool isPlayer)
 {
     _defaultTemplateProvider = defaultTemplateProvider;
     _cachedDbAccess = cachedDbAccess;
     _localizer = localizerFactory.Create(typeof(ChangeNpcStateActionRenderer));
     _isPlayer = isPlayer;
     _flexFieldPlaceholderResolver = new FlexFieldExportTemplatePlaceholderResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory, FlexField_Npc_Prefix);
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="npcDbAccess">Npc Db Access</param>
 /// <param name="npcSnapshotDbAccess">Npc Implementation Snapshot Db Access</param>
 /// <param name="itemDbAccess">Item Db Access</param>
 /// <param name="itemSnapshotDbAccess">Item Implementation Snapshot Db Access</param>
 /// <param name="skillDbAccess">Skill Db Access</param>
 /// <param name="skillSnapshotDbAccess">Skill Implementation Snapshot Db Access</param>
 /// <param name="dialogDbAccess">Dialog Db Access</param>
 /// <param name="dialogSnapshotDbAccess">Dialog Implementation Snapshot Db Access</param>
 /// <param name="questDbAccess">Quest Db Access</param>
 /// <param name="questSnapshotDbAccess">Quest Implementation Snapshot Db Access</param>
 /// <param name="mapDbAccess">Map Db Access</param>
 /// <param name="markerSnapshotDbAccess">Marker Db Access</param>
 /// <param name="objectExportSnippetDbAccess">Object export snippet Db Access</param>
 /// <param name="objectExportSnippetSnapshotDbAccess">Object export snippet snapshot Db Access</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public GenericImplementationStatusComparer(IKortistoNpcDbAccess npcDbAccess, IKortistoNpcImplementationSnapshotDbAccess npcSnapshotDbAccess, IStyrItemDbAccess itemDbAccess, IStyrItemImplementationSnapshotDbAccess itemSnapshotDbAccess,
                                            IEvneSkillDbAccess skillDbAccess, IEvneSkillImplementationSnapshotDbAccess skillSnapshotDbAccess, ITaleDbAccess dialogDbAccess, ITaleDialogImplementationSnapshotDbAccess dialogSnapshotDbAccess,
                                            IAikaQuestDbAccess questDbAccess, IAikaQuestImplementationSnapshotDbAccess questSnapshotDbAccess, IKartaMapDbAccess mapDbAccess, IKartaMarkerImplementationSnapshotDbAccess markerSnapshotDbAccess,
                                            IObjectExportSnippetDbAccess objectExportSnippetDbAccess, IObjectExportSnippetSnapshotDbAccess objectExportSnippetSnapshotDbAccess, IStringLocalizerFactory localizerFactory)
 {
     _npcDbAccess                         = npcDbAccess;
     _npcSnapshotDbAccess                 = npcSnapshotDbAccess;
     _itemDbAccess                        = itemDbAccess;
     _itemSnapshotDbAccess                = itemSnapshotDbAccess;
     _skillDbAccess                       = skillDbAccess;
     _skillSnapshotDbAccess               = skillSnapshotDbAccess;
     _dialogDbAccess                      = dialogDbAccess;
     _dialogSnapshotDbAccess              = dialogSnapshotDbAccess;
     _questDbAccess                       = questDbAccess;
     _questSnapshotDbAccess               = questSnapshotDbAccess;
     _mapDbAccess                         = mapDbAccess;
     _markerSnapshotDbAccess              = markerSnapshotDbAccess;
     _objectExportSnippetDbAccess         = objectExportSnippetDbAccess;
     _objectExportSnippetSnapshotDbAccess = objectExportSnippetSnapshotDbAccess;
     _localizer = localizerFactory.Create(typeof(GenericImplementationStatusComparer));
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="localizerFactory">Localizer factory</param>
 public ConditionTranslator(IStringLocalizerFactory localizerFactory)
 {
     _localizer = localizerFactory.Create(typeof(ConditionTranslator));
 }
Ejemplo n.º 12
0
 public BazController(
     IStringLocalizerFactory localizerFactory)
 {
     _localizer = localizerFactory.Create("Controllers.BazController", "WebLib");
 }
Ejemplo n.º 13
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="templatePlaceholderResolver">Template placeholder resolver</param>
 /// <param name="exportCachedDbAccess">Export cached database access</param>
 /// <param name="defaultTemplateProvider">Default template provider</param>
 /// <param name="languageKeyGenerator">Language key generator</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public ItemExportValueCollector(IExportTemplatePlaceholderResolver templatePlaceholderResolver, IExportCachedDbAccess exportCachedDbAccess, ICachedExportDefaultTemplateProvider defaultTemplateProvider,
                                 IScribanLanguageKeyGenerator languageKeyGenerator, IStringLocalizerFactory localizerFactory) : base(templatePlaceholderResolver, exportCachedDbAccess, defaultTemplateProvider, languageKeyGenerator, localizerFactory)
 {
 }
        public CommonLocalizationService(IStringLocalizerFactory factory)
        {
            var assemblyName = new AssemblyName(typeof(CommonResources).GetTypeInfo().Assembly.FullName);

            localizer = factory.Create(nameof(CommonResources), assemblyName.Name);
        }
 public PASurveyController(IStringLocalizerFactory factory)
 {
     _localizer = new SharedLocalizer(factory);
 }
Ejemplo n.º 16
0
 public OpenModStringLocalizer(IStringLocalizerFactory stringLocalizerFactory, IRuntime runtime)
 {
     m_StringLocalizer = stringLocalizerFactory.Create("openmod.translations", runtime.WorkingDirectory);
 }
Ejemplo n.º 17
0
 public StringLocalizer(IStringLocalizerFactory factory)
 {
     _localizer = factory.Create(string.Empty, string.Empty);
 }
Ejemplo n.º 18
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="defaultTemplateProvider">Default Template Provider</param>
        /// <param name="cachedDbAccess">Cached Db Access</param>
        /// <param name="dailyRoutineFunctionNameGenerator">Daily routine function name generator</param>
        /// <param name="dailyRoutineEventPlaceholderResolver">Legacy Daily routine event placeholder resolver</param>
        /// <param name="scribanLanguageKeyGenerator">Scriban language key generator</param>
        /// <param name="languageKeyGenerator">Language Key Generator</param>
        /// <param name="conditionTranslator">Condition translator</param>
        /// <param name="localizerFactory">Localizer Factory</param>
        public ConditionRenderer(ICachedExportDefaultTemplateProvider defaultTemplateProvider, IExportCachedDbAccess cachedDbAccess, ILegacyDailyRoutineEventPlaceholderResolver dailyRoutineEventPlaceholderResolver,
                                 IDailyRoutineFunctionNameGenerator dailyRoutineFunctionNameGenerator, IScribanLanguageKeyGenerator scribanLanguageKeyGenerator, ILanguageKeyGenerator languageKeyGenerator,
                                 IConditionTranslator conditionTranslator, IStringLocalizerFactory localizerFactory)
        {
            _defaultTemplateProvider = defaultTemplateProvider;
            _conditionTranslator     = conditionTranslator;
            _localizer = localizerFactory.Create(typeof(ConditionRenderer));

            _elementRenderes = new Dictionary <ConditionType, ConditionRendererDispatcher>();
            _elementRenderes.Add(ConditionType.Group, new ConditionRendererDispatcher(TemplateType.GeneralLogicGroup, defaultTemplateProvider,
                                                                                      new GroupConditionResolver(this, defaultTemplateProvider, localizerFactory),
                                                                                      new ScribanGroupConditionRenderer(this, defaultTemplateProvider, cachedDbAccess, localizerFactory)));
            _elementRenderes.Add(ConditionType.PlayerValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionPlayerValue, defaultTemplateProvider,
                                                                                                     new NpcValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory, true),
                                                                                                     new ScribanNpcValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, true)));
            _elementRenderes.Add(ConditionType.NpcValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionNpcValue, defaultTemplateProvider,
                                                                                                  new NpcValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory, false),
                                                                                                  new ScribanNpcValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, false)));
            _elementRenderes.Add(ConditionType.PlayerInventoryCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionPlayerInventory, defaultTemplateProvider,
                                                                                                         new InventoryConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                         new ScribanInventoryConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, true)));
            _elementRenderes.Add(ConditionType.NpcInventoryCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionNpcInventory, defaultTemplateProvider,
                                                                                                      new InventoryConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                      new ScribanInventoryConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, false)));
            _elementRenderes.Add(ConditionType.ChooseQuestValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionQuestValue, defaultTemplateProvider,
                                                                                                          new QuestValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                          new ScribanQuestValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.QuestStateCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionQuestState, defaultTemplateProvider,
                                                                                                    new QuestStateConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                    new ScribanQuestStateConditionRenderer(cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.NpcAliveStateCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionNpcAliveState, defaultTemplateProvider,
                                                                                                       new NpcAliveStateConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                       new ScribanNpcAliveStateConditionRenderer(cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.CurrentSkillValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionCurrentSkillValue, defaultTemplateProvider,
                                                                                                           new CurrentSkillValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                           new ScribanCurrentSkillValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.GameTimeCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionGameTime, defaultTemplateProvider,
                                                                                                  new GameTimeConditionResolver(defaultTemplateProvider, cachedDbAccess, localizerFactory),
                                                                                                  new ScribanGameTimeConditionRenderer(defaultTemplateProvider, cachedDbAccess, localizerFactory)));
            _elementRenderes.Add(ConditionType.PlayerSkillValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionPlayerSkillValue, defaultTemplateProvider,
                                                                                                          new SkillValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                          new ScribanSkillValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.NpcSkillValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionNpcSkillValue, defaultTemplateProvider,
                                                                                                       new SkillValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                       new ScribanSkillValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.PlayerLearnedSkillCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionPlayerLearnedSkill, defaultTemplateProvider,
                                                                                                            new LearnedSkillConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                            new ScribanLearnedSkillConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, true)));
            _elementRenderes.Add(ConditionType.PlayerNotLearnedSkillCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionPlayerNotLearnedSkill, defaultTemplateProvider,
                                                                                                               new LearnedSkillConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                               new ScribanLearnedSkillConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, true)));
            _elementRenderes.Add(ConditionType.NpcLearnedSkillCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionNpcLearnedSkill, defaultTemplateProvider,
                                                                                                         new LearnedSkillConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                         new ScribanLearnedSkillConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, false)));
            _elementRenderes.Add(ConditionType.NpcNotLearnedSkillCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionNpcNotLearnedSkill, defaultTemplateProvider,
                                                                                                            new LearnedSkillConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                            new ScribanLearnedSkillConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory, false)));
            _elementRenderes.Add(ConditionType.RandomValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionRandomValue, defaultTemplateProvider,
                                                                                                     new RandomValueConditionResolver(defaultTemplateProvider, localizerFactory),
                                                                                                     new ScribanRandomValueConditionRenderer(cachedDbAccess, defaultTemplateProvider, localizerFactory)));
            _elementRenderes.Add(ConditionType.DailyRoutineEventIsDisabledCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionDailyRoutineEventDisabled, defaultTemplateProvider,
                                                                                                                     new DailyRoutineEventStateConditionResolver(defaultTemplateProvider, cachedDbAccess, dailyRoutineEventPlaceholderResolver, languageKeyGenerator, localizerFactory),
                                                                                                                     new ScribanDailyRoutineEventStateConditionRenderer(cachedDbAccess, dailyRoutineFunctionNameGenerator, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.DailyRoutineEventIsEnabledCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionDailyRoutineEventEnabled, defaultTemplateProvider,
                                                                                                                    new DailyRoutineEventStateConditionResolver(defaultTemplateProvider, cachedDbAccess, dailyRoutineEventPlaceholderResolver, languageKeyGenerator, localizerFactory),
                                                                                                                    new ScribanDailyRoutineEventStateConditionRenderer(cachedDbAccess, dailyRoutineFunctionNameGenerator, scribanLanguageKeyGenerator, localizerFactory)));
            _elementRenderes.Add(ConditionType.CodeCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionCode, defaultTemplateProvider,
                                                                                              new CodeConditionResolver(localizerFactory),
                                                                                              new ScribanCodeConditionRenderer(cachedDbAccess, localizerFactory)));
            _elementRenderes.Add(ConditionType.ItemValueCondition, new ConditionRendererDispatcher(TemplateType.TaleConditionItemValue, defaultTemplateProvider,
                                                                                                   new ItemValueConditionResolver(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory),
                                                                                                   new ScribanItemValueConditionRenderer(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)));
        }
Ejemplo n.º 19
0
 public ProjectPermissionDefinitionProvider(IStringLocalizerFactory factory)
 {
     _localizer = factory.Create("Welcome", Assembly.GetExecutingAssembly().FullName ?? string.Empty);
 }
Ejemplo n.º 20
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="defaultTemplateProvider">Default Template Provider</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public CodeActionRenderer(ICachedExportDefaultTemplateProvider defaultTemplateProvider, IStringLocalizerFactory localizerFactory)
 {
     _defaultTemplateProvider = defaultTemplateProvider;
     _localizer = localizerFactory.Create(typeof(CodeActionRenderer));
 }
        private static HtmlHelper <TModel> GetHtmlHelper <TModel>(
            ViewDataDictionary <TModel> viewData,
            IUrlHelper urlHelper,
            ICompositeViewEngine viewEngine,
            IModelMetadataProvider provider,
            IStringLocalizerFactory localizerFactory,
            Func <IHtmlHelper, IHtmlHelper> innerHelperWrapper,
            IHtmlGenerator htmlGenerator,
            string idAttributeDotReplacement)
        {
            var httpContext   = new DefaultHttpContext();
            var actionContext = new ActionContext(httpContext, new RouteData(), new ActionDescriptor());

            var options = new MvcViewOptions();

            if (!string.IsNullOrEmpty(idAttributeDotReplacement))
            {
                options.HtmlHelperOptions.IdAttributeDotReplacement = idAttributeDotReplacement;
            }

            var localizationOptions        = new MvcDataAnnotationsLocalizationOptions();
            var localizationOptionsAccesor = Options.Create(localizationOptions);

            options.ClientModelValidatorProviders.Add(new DataAnnotationsClientModelValidatorProvider(
                                                          new ValidationAttributeAdapterProvider(),
                                                          localizationOptionsAccesor,
                                                          localizerFactory));

            var urlHelperFactory = new Mock <IUrlHelperFactory>();

            urlHelperFactory
            .Setup(f => f.GetUrlHelper(It.IsAny <ActionContext>()))
            .Returns(urlHelper);

            if (htmlGenerator == null)
            {
                htmlGenerator = HtmlGeneratorUtilities.GetHtmlGenerator(provider, urlHelperFactory.Object, options);
            }

            // TemplateRenderer will Contextualize this transient service.
            var innerHelper = (IHtmlHelper) new HtmlHelper(
                htmlGenerator,
                viewEngine,
                provider,
                new TestViewBufferScope(),
                new HtmlTestEncoder(),
                UrlEncoder.Default);

            if (innerHelperWrapper != null)
            {
                innerHelper = innerHelperWrapper(innerHelper);
            }

            var serviceProvider = new ServiceCollection()
                                  .AddSingleton(viewEngine)
                                  .AddSingleton(urlHelperFactory.Object)
                                  .AddSingleton(Mock.Of <IViewComponentHelper>())
                                  .AddSingleton(innerHelper)
                                  .AddSingleton <IViewBufferScope, TestViewBufferScope>()
                                  .BuildServiceProvider();

            httpContext.RequestServices = serviceProvider;

            var htmlHelper = new HtmlHelper <TModel>(
                htmlGenerator,
                viewEngine,
                provider,
                new TestViewBufferScope(),
                new HtmlTestEncoder(),
                UrlEncoder.Default,
                new ModelExpressionProvider(provider));

            var viewContext = new ViewContext(
                actionContext,
                Mock.Of <IView>(),
                viewData,
                new TempDataDictionary(
                    httpContext,
                    Mock.Of <ITempDataProvider>()),
                new StringWriter(),
                options.HtmlHelperOptions);

            htmlHelper.Contextualize(viewContext);

            return(htmlHelper);
        }
Ejemplo n.º 22
0
 /// <summary>
 /// Creates a new <see cref="HtmlLocalizer"/>.
 /// </summary>
 /// <param name="localizerFactory">The <see cref="IStringLocalizerFactory"/>.</param>
 /// <param name="encoder">The <see cref="IHtmlEncoder"/>.</param>
 public HtmlLocalizerFactory([NotNull] IStringLocalizerFactory localizerFactory, [NotNull] IHtmlEncoder encoder)
 {
     _factory = localizerFactory;
     _encoder = encoder;
 }
 public MissingStringLocalizerFactory(IStringLocalizerFactory inner, IAsyncLocalizerFactory asyncInner, IMissingStringLocalizerLogger missing)
 {
     this.inner      = inner;
     this.asyncInner = asyncInner;
     this.missing    = missing;
 }
Ejemplo n.º 24
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="cachedDbAccess">Cached Db Access</param>
 /// <param name="scribanLanguageKeyGenerator">Scriban language key generator</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 /// <param name="isRemoval">True if the action is for a removal, else false</param>
 public ScribanInventoryActionChooseNpcRenderer(IExportCachedDbAccess cachedDbAccess, IScribanLanguageKeyGenerator scribanLanguageKeyGenerator, IStringLocalizerFactory localizerFactory, bool isRemoval) :
     base(cachedDbAccess, isRemoval)
 {
     _scribanLanguageKeyGenerator = scribanLanguageKeyGenerator;
     _localizerFactory            = localizerFactory;
 }
 public static IStringLocalizer Create <TResource>(this IStringLocalizerFactory localizerFactory)
 {
     return(localizerFactory.Create(typeof(TResource)));
 }
 public string Localize(IStringLocalizerFactory factory)
 {
     return(FixedString);
 }
Ejemplo n.º 27
0
 public FooController(
     IStringLocalizerFactory localizerFactory
     )
 {
     _localizer = localizerFactory.Create("MyResources.Controllers.FooController", "WebLib");
 }
Ejemplo n.º 28
0
 public StringLocalizer(IStringLocalizerFactory factory)
 {
     _localizer = factory.Create(typeof(TResourceSource));
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="projectDbAccess">User Db Access</param>
 /// <param name="kortistoFolderDbAccess">Kortisto Folder Db Access</param>
 /// <param name="npcDbAccess">Npc Db Access</param>
 /// <param name="styrFolderDbAccess">Styr Folder Db Access</param>
 /// <param name="itemDbAccess">Item Db Access</param>
 /// <param name="kirjaPageDbAccess">Kirja Page Db Access</param>
 /// <param name="chapterDetailDbAccess">Chapter Detail Db Access</param>
 /// <param name="questDbAccess">Quest Db Access</param>
 /// <param name="mapDbAccess">Map Db Access</param>
 /// <param name="taskBoardDbAccess">Task Board Db Access</param>
 /// <param name="taskNumberDbAccess">Task Number Db Access</param>
 /// <param name="userTaskBoardHistoryDbAccess">User Task board history db access</param>
 /// <param name="exportSettingsDbAccess">Export Settings Db Access</param>
 /// <param name="exportTemplateDbAccess">Export Template Db Access</param>
 /// <param name="taleConfigDbAccess">Tale Config Db Access</param>
 /// <param name="timelineService">Timeline Service</param>
 /// <param name="logger">Logger</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public ProjectApiController(IProjectDbAccess projectDbAccess, IKortistoFolderDbAccess kortistoFolderDbAccess, IKortistoNpcDbAccess npcDbAccess, IStyrFolderDbAccess styrFolderDbAccess, IStyrItemDbAccess itemDbAccess, IKirjaPageDbAccess kirjaPageDbAccess,
                             IAikaChapterDetailDbAccess chapterDetailDbAccess, IAikaQuestDbAccess questDbAccess, IKartaMapDbAccess mapDbAccess, ITaskBoardDbAccess taskBoardDbAccess, ITaskNumberDbAccess taskNumberDbAccess, IUserTaskBoardHistoryDbAccess userTaskBoardHistoryDbAccess,
                             IExportSettingsDbAccess exportSettingsDbAccess, IExportTemplateDbAccess exportTemplateDbAccess, ITaleConfigDbAccess taleConfigDbAccess, ITimelineService timelineService, ILogger <ProjectApiController> logger, IStringLocalizerFactory localizerFactory)
 {
     _projectDbAccess              = projectDbAccess;
     _kortistoFolderDbAccess       = kortistoFolderDbAccess;
     _npcDbAccess                  = npcDbAccess;
     _styrFolderDbAccess           = styrFolderDbAccess;
     _itemDbAccess                 = itemDbAccess;
     _kirjaPageDbAccess            = kirjaPageDbAccess;
     _chapterDetailDbAccess        = chapterDetailDbAccess;
     _questDbAccess                = questDbAccess;
     _mapDbAccess                  = mapDbAccess;
     _taskBoardDbAccess            = taskBoardDbAccess;
     _taskNumberDbAccess           = taskNumberDbAccess;
     _userTaskBoardHistoryDbAccess = userTaskBoardHistoryDbAccess;
     _exportSettingsDbAccess       = exportSettingsDbAccess;
     _exportTemplateDbAccess       = exportTemplateDbAccess;
     _taleConfigDbAccess           = taleConfigDbAccess;
     _timelineService              = timelineService;
     _logger    = logger;
     _localizer = localizerFactory.Create(typeof(ProjectApiController));
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="chapterOverviewDbAccess">Chapter Overview Db Access</param>
 /// <param name="chapterDetailDbAccess">Chapter Detail Db Access</param>
 /// <param name="questDbAccess">Quest Db Access</param>
 /// <param name="projectDbAccess">Project Db Access</param>
 /// <param name="kirjaPageDbAccess">Kirja Db Access</param>
 /// <param name="taleDbAccess">Tale Db Access</param>
 /// <param name="kortistoNpcDbAccess">Kortisto Npc Db Access</param>
 /// <param name="kartaMapDbAccess">Karta Map Db Access</param>
 /// <param name="userManager">User Manager</param>
 /// <param name="implementationStatusComparer">Implementation status comparer</param>
 /// <param name="timelineService">Timeline Service</param>
 /// <param name="logger">Logger</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public AikaApiController(IAikaChapterOverviewDbAccess chapterOverviewDbAccess, IAikaChapterDetailDbAccess chapterDetailDbAccess, IAikaQuestDbAccess questDbAccess, IProjectDbAccess projectDbAccess,
                          IKirjaPageDbAccess kirjaPageDbAccess, ITaleDbAccess taleDbAccess, IKortistoNpcDbAccess kortistoNpcDbAccess, IKartaMapDbAccess kartaMapDbAccess, UserManager <GoNorthUser> userManager,
                          IImplementationStatusComparer implementationStatusComparer, ITimelineService timelineService, ILogger <AikaApiController> logger, IStringLocalizerFactory localizerFactory)
 {
     _chapterOverviewDbAccess      = chapterOverviewDbAccess;
     _chapterDetailDbAccess        = chapterDetailDbAccess;
     _questDbAccess                = questDbAccess;
     _projectDbAccess              = projectDbAccess;
     _kirjaPageDbAccess            = kirjaPageDbAccess;
     _taleDbAccess                 = taleDbAccess;
     _kortistoNpcDbAccess          = kortistoNpcDbAccess;
     _kartaMapDbAccess             = kartaMapDbAccess;
     _userManager                  = userManager;
     _implementationStatusComparer = implementationStatusComparer;
     _timelineService              = timelineService;
     _logger    = logger;
     _localizer = localizerFactory.Create(typeof(AikaApiController));
 }
Ejemplo n.º 31
0
 public JStringLocalizer(IStringLocalizerFactory localizerFactory)
 {
     Localizer = localizerFactory.Create(typeof(T));
 }
Ejemplo n.º 32
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="localizerFactory">Localizer Factory</param>
 public GoNorthIdentityErrorDescriber(IStringLocalizerFactory localizerFactory)
 {
     _localizer = localizerFactory.Create(typeof(GoNorthIdentityErrorDescriber));
 }
Ejemplo n.º 33
0
        public static void Main(string[] args)
        {
            {
                #region Snippet_1a
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "Culture:en:Type:MyController:Key:hello", "Hello World!" }
                };
                // Create asset
                IAsset asset = new StringAsset(source, LineFormat.Parameters);
                // Create culture policy
                ICulturePolicy culturePolicy = new CulturePolicy();
                // Create root
                ILineRoot root = new LineRoot(asset, culturePolicy);
                #endregion Snippet_1a

                #region Snippet_1b
                // Construct key
                ILine key = root.Type("MyController").Key("Hello");
                #endregion Snippet_1b

                #region Snippet_1c
                // Set active culture for this root
                (root.FindCulturePolicy() as ICulturePolicyAssignable).SetCultures("en", "");
                // Provide string
                string str = key.ToString();
                #endregion Snippet_1c
            }

            {
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "Culture:en:Section:Section:Key:Key", "Hello World!" }
                };
                // Create asset
                IAsset asset = new StringAsset(source, LineFormat.Parameters);
                #region Snippet_5x
                // Create reference
                ILine key = LineAppender.NonResolving.Section("Section").Key("Key");
                // Retreieve with reference
                IString str = asset.GetLine(key).GetString();
                #endregion Snippet_5x
            }

            {
                #region Snippet_2a
                // Create key from global root
                ILine key = LineRoot.Global.Type("MyController").Key("Hello");
                #endregion Snippet_2a

                #region Snippet_2b
                // Create localization source
                var source = new Dictionary <string, string> {
                    { "Culture:en:Type:MyController:Key:hello", "Hello World!" }
                };
                // Create asset
                IAsset asset = new StringAsset(source, LineFormat.Parameters);
                // Assets are added to global static builder. It must be (re-)built after adding.
                LineRoot.Builder.AddAsset(asset).Build();
                #endregion Snippet_2b

                #region Snippet_2c
                // If ran in multi-threaded initialization, lock to LineRoot.Builder.
                lock (LineRoot.Builder) LineRoot.Builder.AddAsset(asset).Build();
                #endregion Snippet_2c

                #region Snippet_2d
                // StringLocalizerRoot is root for IStringLocalizer interoperability
                IStringLocalizerFactory stringLocalizerFactory = StringLocalizerRoot.Global;
                #endregion Snippet_2d

                #region Snippet_2e
                // LineRoot and StringLocalizerRoot are interchangeable. They share the same asset(s).
                LineRoot.Builder.AddAsset(asset).Build();
                IStringLocalizer <MyController> stringLocalizer = StringLocalizerRoot.Global.Type <MyController>().AsStringLocalizer <MyController>();
                #endregion Snippet_2e

                #region Snippet_2f
                // Dynamic instance is acquired with LineRoot.GlobalDynamic
                dynamic key_ = LineRoot.GlobalDynamic.Section("Section").Key("Key");
                #endregion Snippet_2f
            }
        }
 public string Localize(IStringLocalizerFactory factory)
 {
     return(factory.Create(ResourceName, ResourceLocation).GetString(Name));
 }
Ejemplo n.º 35
0
 public TestController(IStringLocalizerFactory factory)
 {
     _localizer = factory.Create(typeof(SharedResource));
     _localizer2 = factory.Create("SharedResource", location: null);
 }
Ejemplo n.º 36
0
 public LocService(IStringLocalizerFactory factory, ITranslationService translationService) : base(factory)
 {
     _translationService = translationService;
 }
Ejemplo n.º 37
0
        private static ServiceCollection GetServiceCollection(IStringLocalizerFactory localizerFactory)
        {
            var serviceCollection = new ServiceCollection();
            serviceCollection
                .AddSingleton<ObjectPoolProvider, DefaultObjectPoolProvider>()
                .AddSingleton<ILoggerFactory>(new NullLoggerFactory())
                .AddSingleton<UrlEncoder>(new UrlTestEncoder());

            serviceCollection.AddOptions();
            serviceCollection.AddRouting();

            serviceCollection.AddSingleton<IInlineConstraintResolver>(
                provider => new DefaultInlineConstraintResolver(provider.GetRequiredService<IOptions<RouteOptions>>()));

            if (localizerFactory != null)
            {
                serviceCollection.AddSingleton<IStringLocalizerFactory>(localizerFactory);
            }

            return serviceCollection;
        }
Ejemplo n.º 38
0
 public LocService(IStringLocalizerFactory factory) : base(factory)
 {
 }
 public ResourcesController(IStringLocalizerFactory localizerFactory, IApplicationEnvironment app)
 {
     _localizerFactory = localizerFactory;
     _app = app;
     _files = new PhysicalFileProvider(_app.ApplicationBasePath + "/Resources/bin");
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="defaultTemplateProvider">Default Template Provider</param>
 /// <param name="cachedDbAccess">Cached Db Access</param>
 /// <param name="languageKeyGenerator">Language Key Generator</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public SpawnItemAtMarkerRender(ICachedExportDefaultTemplateProvider defaultTemplateProvider, IExportCachedDbAccess cachedDbAccess, ILanguageKeyGenerator languageKeyGenerator, IStringLocalizerFactory localizerFactory) :
     base(defaultTemplateProvider, cachedDbAccess, languageKeyGenerator, localizerFactory)
 {
 }
 public HtmlLocalizerFactory(IStringLocalizerFactory localizerFactory, IHtmlEncoder encoder)
 {
     _factory = localizerFactory;
     _encoder = encoder;
 }
Ejemplo n.º 42
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="defaultTemplateProvider">Default Template Provider</param>
 /// <param name="cachedDbAccess">Cached Db Access</param>
 /// <param name="scribanLanguageKeyGenerator">Scriban Language Key Generator</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 /// <param name="isPlayer">true if the action renderer is for a skill of the player, else false</param>
 public ScribanSkillValueChangeRenderer(ICachedExportDefaultTemplateProvider defaultTemplateProvider, IExportCachedDbAccess cachedDbAccess, IScribanLanguageKeyGenerator scribanLanguageKeyGenerator,
                                        IStringLocalizerFactory localizerFactory, bool isPlayer) : base(defaultTemplateProvider, cachedDbAccess, scribanLanguageKeyGenerator, localizerFactory)
 {
     _isPlayer = isPlayer;
 }
 public PagerTagHelper(
     IHtmlHelper html,
     IHttpContextAccessor httpAccessor, IViewComponentHelper component,
     IUrlHelperFactory urlHelperFactory,
     IStringLocalizerFactory factory)
 {
     this.html = html;
     this.httpAccessor = httpAccessor;
     this.component = component;
     this.urlHelperFactory = urlHelperFactory;
     this.factory = factory;
 }
Ejemplo n.º 44
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="folderDbAccess">Folder Db Access</param>
 /// <param name="templateDbAccess">Template Db Access</param>
 /// <param name="skillDbAccess">Skill Db Access</param>
 /// <param name="projectDbAccess">User Db Access</param>
 /// <param name="tagDbAccess">Tag Db Access</param>
 /// <param name="exportTemplateDbAccess">Export Template Db Access</param>
 /// <param name="languageKeyDbAccess">Language Key Db Access</param>
 /// <param name="exportFunctionIdDbAccess">Export Function Id Db Access</param>
 /// <param name="imageAccess">Skill Image Access</param>
 /// <param name="thumbnailService">Thumbnail Service</param>
 /// <param name="aikaQuestDbAccess">Aika Quest Db ACcess</param>
 /// <param name="kirjaPageDbAccess">Kirja Page Db Access</param>
 /// <param name="taleDbAccess">Tale Db Access</param>
 /// <param name="kortistoNpcDbAccess">Kortisto Npc Db Access</param>
 /// <param name="userManager">User Manager</param>
 /// <param name="implementationStatusComparer">Implementation Status Comparer</param>
 /// <param name="timelineService">Timeline Service</param>
 /// <param name="xssChecker">Xss Checker</param>
 /// <param name="logger">Logger</param>
 /// <param name="localizerFactory">Localizer Factory</param>
 public EvneApiController(IEvneFolderDbAccess folderDbAccess, IEvneSkillTemplateDbAccess templateDbAccess, IEvneSkillDbAccess skillDbAccess, IProjectDbAccess projectDbAccess, IEvneSkillTagDbAccess tagDbAccess, IExportTemplateDbAccess exportTemplateDbAccess, ILanguageKeyDbAccess languageKeyDbAccess,
                          IExportFunctionIdDbAccess exportFunctionIdDbAccess, IEvneSkillImageAccess imageAccess, IEvneThumbnailService thumbnailService, IAikaQuestDbAccess aikaQuestDbAccess, ITaleDbAccess taleDbAccess, IKirjaPageDbAccess kirjaPageDbAccess, IKortistoNpcDbAccess kortistoNpcDbAccess,
                          UserManager <GoNorthUser> userManager, IImplementationStatusComparer implementationStatusComparer, ITimelineService timelineService, IXssChecker xssChecker, ILogger <EvneApiController> logger, IStringLocalizerFactory localizerFactory)
     : base(folderDbAccess, templateDbAccess, skillDbAccess, projectDbAccess, tagDbAccess, exportTemplateDbAccess, languageKeyDbAccess, exportFunctionIdDbAccess, imageAccess, thumbnailService, userManager,
            implementationStatusComparer, timelineService, xssChecker, logger, localizerFactory)
 {
     _aikaQuestDbAccess   = aikaQuestDbAccess;
     _taleDbAccess        = taleDbAccess;
     _kirjaPageDbAccess   = kirjaPageDbAccess;
     _kortistoNpcDbAccess = kortistoNpcDbAccess;
 }
        public void Configure(
            IApplicationBuilder app,
            ILoggerFactory loggerFactory,
            IStringLocalizerFactory stringLocalizerFactory,
            IStringLocalizer<StartupResourcesInFolder> startupStringLocalizer,
            IStringLocalizer<Customer> custromerStringLocalizer)
        {
            loggerFactory.AddConsole(minLevel: LogLevel.Warning);

            var options = new RequestLocalizationOptions
            {
                SupportedCultures = new List<CultureInfo>()
                {
                    new CultureInfo("fr-FR")
                },
                SupportedUICultures = new List<CultureInfo>()
                {
                    new CultureInfo("fr-FR")
                }
            };

            app.UseRequestLocalization(options, defaultRequestCulture: new RequestCulture("en-US"));

            var stringLocalizer = stringLocalizerFactory.Create("Test", location: null);

            app.Run(async (context) =>
            {
                await context.Response.WriteAsync(startupStringLocalizer["Hello"]);
                await context.Response.WriteAsync(" ");
                await context.Response.WriteAsync(stringLocalizer["Hello"]);
                await context.Response.WriteAsync(" ");
                await context.Response.WriteAsync(custromerStringLocalizer["Hello"]);
            });
        }