Esempio n. 1
0
        /// <summary>
        ///   Resolves a HTML localizer using all the specified parameters.
        /// </summary>
        /// <param name="factory">The html factory to create the HTML localizer from.</param>
        /// <param name="context">
        ///   The view context to resolve the name if both <paramref name="resourceType" /> and
        ///   <paramref name="resourceType" /> is <see langword="null" /> or <c>empty</c>.
        /// </param>
        /// <param name="applicationName">Name of the application (Usually the Assembly name).</param>
        /// <param name="resourceType">
        ///   Type of the resource to create the HTML localizer from (can be <see langword="null" />).
        /// </param>
        /// <param name="resourceName">
        ///   Name of the resource to create the HTML localizer from (can be <see langword="null" /> or empty).
        /// </param>
        /// <returns>The created HTML localizer.</returns>
        /// <seealso cref="ResolveLocalizer(IHtmlLocalizerFactory, ViewContext, string)" />
        /// <seealso cref="IHtmlLocalizerFactory.Create(string, string)" />
        /// <seealso cref="IHtmlLocalizerFactory.Create(Type)" />
        public static IHtmlLocalizer ResolveLocalizer(
            this IHtmlLocalizerFactory factory,
            ViewContext context,
            string applicationName,
            Type resourceType,
            string resourceName)
        {
            if (resourceType != null)
            {
                return(factory.Create(resourceType));
            }
            else
            {
                string name = resourceName;
                if (string.IsNullOrEmpty(name))
                {
                    var path = context.ExecutingFilePath;
                    if (string.IsNullOrEmpty(path))
                    {
                        path = context.View.Path;
                    }

                    Debug.Assert(!string.IsNullOrEmpty(path), "Couldn't determine a path for the view");

                    name = BuildBaseName(path, applicationName);
                }

                return(factory.Create(name, applicationName));
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new <see cref="ViewLocalizer"/>.
 /// </summary>
 /// <param name="localizerFactory">The <see cref="IHtmlLocalizerFactory"/>.</param>
 /// <param name="applicationEnvironment">The <see cref="IApplicationEnvironment"/>.</param>
 public ViewLocalizer(
     [NotNull] IHtmlLocalizerFactory localizerFactory,
     [NotNull] IApplicationEnvironment applicationEnvironment)
 {
     _applicationName  = applicationEnvironment.ApplicationName;
     _localizerFactory = localizerFactory;
 }
Esempio n. 3
0
 /// <summary>
 ///   Resolves a HTML localizer using the view name from the specified
 ///   <paramref name="context">view context</paramref>
 /// </summary>
 /// <param name="factory">The html factory to create the HTML localizer from.</param>
 /// <param name="context">The view context to resolve the view name from.</param>
 /// <param name="applicationName">Name of the application (Usually the Assembly name).</param>
 /// <returns>The created HTML localizer.</returns>
 /// <seealso cref="ResolveLocalizer(IHtmlLocalizerFactory, ViewContext, string, Type, string)" />
 /// <seealso cref="IHtmlLocalizerFactory.Create(string, string)" />
 public static IHtmlLocalizer ResolveLocalizer(
     this IHtmlLocalizerFactory factory,
     ViewContext context,
     string applicationName)
 {
     return(ResolveLocalizer(factory, context, applicationName, null, null));
 }
Esempio n. 4
0
 public UnloadsListModel(IHtmlLocalizerFactory htmlLocalizerFactory, IEmailService emailService, IHostingEnvironment env)
 {
     _loc               = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.UnloadsList", Includes.AppShortName);
     _emailService      = emailService;
     _hostingEnviroment = env;
     UnloadsListData    = new ViewData();
 }
Esempio n. 5
0
        public SharedLocalizer(IHtmlLocalizerFactory factory)
        {
            var type         = typeof(Shared);
            var assemblyName = new AssemblyName(type.GetTypeInfo().Assembly.FullName);

            _localizer = factory.Create("Shared", assemblyName.Name);
        }
Esempio n. 6
0
 /// <summary>
 /// Creates a new <see cref="ViewLocalizer"/>.
 /// </summary>
 /// <param name="localizerFactory">The <see cref="IHtmlLocalizerFactory"/>.</param>
 /// <param name="applicationEnvironment">The <see cref="IApplicationEnvironment"/>.</param>
 public ViewLocalizer(
     [NotNull] IHtmlLocalizerFactory localizerFactory,
     [NotNull] IApplicationEnvironment applicationEnvironment)
 {
     _applicationName = applicationEnvironment.ApplicationName;
     _localizerFactory = localizerFactory;
 }
        public DbGenericLocalizeTagHelper(IHtmlLocalizerFactory localizerFactory,
                                          IHostingEnvironment hostingEnvironment, IOptions <LocalizeTagHelperOptions> options)
        {
            _localizerFactory = localizerFactory ?? throw new ArgumentNullException(nameof(localizerFactory));
            if (hostingEnvironment == null)
            {
                throw new ArgumentNullException(nameof(hostingEnvironment));
            }

            _localizerFactory = localizerFactory;
            _applicationName  = hostingEnvironment.ApplicationName;

            if (options != null)
            {
                NewLineHandling = options.Value.NewLineHandling;
                TrimWhitespace  = options.Value.TrimWhitespace;
                IsHtml          = !options.Value.HtmlEncodeByDefault;
            }
            else
            {
                NewLineHandling = NewLineHandling.Auto;
                TrimWhitespace  = true;
                IsHtml          = false;
            }
        }
Esempio n. 8
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="LocalizeAttributeTagHelper" /> class.
        /// </summary>
        /// <param name="localizerFactory">The localizer factory.</param>
        /// <param name="hostingEnvironment">The hosting environment.</param>
        public LocalizeAttributeTagHelper(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment)
        {
            Throws.NotNull(localizerFactory, nameof(localizerFactory));
            Throws.NotNull(hostingEnvironment, nameof(hostingEnvironment));

            this.localizerFactory = localizerFactory;
            applicationName       = hostingEnvironment.ApplicationName;
        }
Esempio n. 9
0
        public I18nViewLocalizer(IStringLocalizerFactory stringFactory,
                                 IHtmlLocalizerFactory htmlFactory)
        {
            var assemblyName = new AssemblyName(typeof(SharedResources).GetTypeInfo().Assembly.FullName);

            _stringLocalizer = stringFactory.Create("SharedResources", assemblyName.Name);
            _htmlLocalizer   = htmlFactory.Create("SharedResources", assemblyName.Name);
        }
Esempio n. 10
0
 public ReservationModel(IHtmlLocalizerFactory htmlLocalizerFactory, IEmailService emailService, IHostingEnvironment env)
 {
     _loc                  = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.Reservation", Includes.AppShortName);
     _emailService         = emailService;
     _hostingEnviroment    = env;
     _htmlLocalizerFactory = htmlLocalizerFactory;
     ResData               = new ReservationData();
 }
Esempio n. 11
0
        /// <summary>
        /// Shared culture localizer for razor pages views
        /// </summary>
        /// <param name="factory"></param>
        /// <param name="type"></param>
        public SharedCultureLocalizer(IHtmlLocalizerFactory factory, Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            var assemblyName = new AssemblyName(type.GetTypeInfo().Assembly.FullName);

            _localizer = factory.Create(type.Name, assemblyName.Name);
        }
Esempio n. 12
0
 public LeaveManagementCustomLocalizerFactory(
     IStringLocalizerFactory stringLocalizerFactory,
     IHtmlLocalizerFactory htmlLocalizerFactory,
     Microsoft.Extensions.Configuration.IConfiguration configuration,
     ILogger <LeaveManagementCustomLocalizerFactory> logger,
     IWebHostEnvironment hostEnvironement = null
     )
 {
     StringLocalizerFactory = stringLocalizerFactory;
     HtmlLocalizerFactory   = htmlLocalizerFactory;
     WebHostEnvironment     = hostEnvironement;
     _Configuration         = configuration;
     _Logger = logger;
     InitMappers();
 }
Esempio n. 13
0
        /// <summary>
        /// Creates a new <see cref="ViewLocalizer"/>.
        /// </summary>
        /// <param name="localizerFactory">The <see cref="IHtmlLocalizerFactory"/>.</param>
        /// <param name="applicationEnvironment">The <see cref="IApplicationEnvironment"/>.</param>
        public ViewLocalizer(IHtmlLocalizerFactory localizerFactory, IApplicationEnvironment applicationEnvironment)
        {
            if (localizerFactory == null)
            {
                throw new ArgumentNullException(nameof(localizerFactory));
            }

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

            _applicationName = applicationEnvironment.ApplicationName;
            _localizerFactory = localizerFactory;
        }
        /// <summary>
        /// Creates a new <see cref="Microsoft.AspNetCore.Mvc.Localization.ViewLocalizer"/>.
        /// </summary>
        /// <param name="localizerFactory">The <see cref="IHtmlLocalizerFactory"/>.</param>
        /// <param name="hostingEnvironment">The <see cref="IHostingEnvironment"/>.</param>
        public ViewLocalizer(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment)
        {
            if (localizerFactory == null)
            {
                throw new ArgumentNullException(nameof(localizerFactory));
            }

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

            _applicationName  = hostingEnvironment.ApplicationName;
            _localizerFactory = localizerFactory;
        }
        public static T CreateTagHelper <T>(IHtmlLocalizerFactory factory)
            where T : GenericLocalizeTagHelper
        {
            var hostingEnvironmentMock = new Mock <IHostingEnvironment>();

            hostingEnvironmentMock.SetupGet(x => x.ApplicationName).Returns(ApplicationName);
            if (factory == null)
            {
                factory = CreateFactoryMock(true).Object;
            }

            var instance = (T)Activator.CreateInstance(typeof(T), factory, hostingEnvironmentMock.Object, null);

            instance.ViewContext     = DefaultViewContext;
            instance.NewLineHandling = NewLineHandling.None;

            return(instance);
        }
        /// <summary>
        ///   Initializes a new instance of the <see cref="GenericLocalizeTagHelper" /> class.
        /// </summary>
        /// <param name="localizerFactory">
        ///   The localizer factory to create a <see cref="IHtmlLocalizer" /> from.
        /// </param>
        /// <param name="hostingEnvironment">The hosting environment.</param>
        /// <param name="options">The default options unless overridden when calling the tag helper.</param>
        public GenericLocalizeTagHelper(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment, IOptions <LocalizeTagHelperOptions> options)
        {
            Throws.NotNull(localizerFactory, nameof(localizerFactory));
            Throws.NotNull(hostingEnvironment, nameof(hostingEnvironment));

            this.localizerFactory = localizerFactory;
            this.applicationName  = hostingEnvironment.ApplicationName;

            if (options != null)
            {
                NewLineHandling = options.Value.NewLineHandling;
                TrimWhitespace  = options.Value.TrimWhitespace;
            }
            else
            {
                NewLineHandling = NewLineHandling.Auto;
                TrimWhitespace  = true;
            }
        }
Esempio n. 17
0
        public SharedHtmlLocalizer(IHtmlLocalizerFactory factory)
        {
            this.localLocalizer = this.sharedLocalizer = factory.Create(typeof(T));

            var resourceType = typeof(T);

            if (resourceType.Namespace?.StartsWith(AssemblyNamePrefix) != true)
            {
                return;
            }

            var resourceNamespaceNameWithoutPrefix = resourceType.Namespace?.Remove(0, AssemblyNamePrefix.Length + 1);
            var resourceTypeName = resourceType.Name;

            var resourceName       = $"{resourceNamespaceNameWithoutPrefix}.{resourceTypeName}.{resourceTypeName}";
            var sharedAssemblyName = Assembly.GetExecutingAssembly().GetName().Name;

            this.sharedLocalizer = factory.Create(resourceName, sharedAssemblyName);
        }
Esempio n. 18
0
    /// <summary>
    /// Creates a new <see cref="ViewLocalizer"/>.
    /// </summary>
    /// <param name="localizerFactory">The <see cref="IHtmlLocalizerFactory"/>.</param>
    /// <param name="hostingEnvironment">The <see cref="IWebHostEnvironment"/>.</param>
    public ViewLocalizer(IHtmlLocalizerFactory localizerFactory, IWebHostEnvironment hostingEnvironment)
    {
        if (localizerFactory == null)
        {
            throw new ArgumentNullException(nameof(localizerFactory));
        }

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

        if (string.IsNullOrEmpty(hostingEnvironment.ApplicationName))
        {
            throw new InvalidOperationException($"{nameof(hostingEnvironment)}.ApplicationName must have a value.");
        }

        _applicationName  = hostingEnvironment.ApplicationName;
        _localizerFactory = localizerFactory;
    }
Esempio n. 19
0
        public IndexModel(IHtmlLocalizerFactory htmlLocalizerFactory)
        {
            _loc = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.Index", Includes.AppShortName);

            LoginCreds = new LoginCredentials();
        }
        // private readonly IHtmlLocalizer _localizer;

        public HtmlLocalizerFix(IHtmlLocalizerFactory factory) : base(factory)
        {
        }
 public NoParametersSupported(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment, IOptions <LocalizeTagHelperOptions> options)
     : base(localizerFactory, hostingEnvironment, options)
 {
 }
 protected GenericLocalizeTagHelper CreateTagHelper(IHtmlLocalizerFactory factory)
 => TestHelper.CreateTagHelper <GenericLocalizeTagHelper>(factory);
 public MainMenuModel(IHtmlLocalizerFactory htmlLocalizerFactory)
 {
     _loc     = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.MainMenu", Includes.AppShortName);
     PersInfo = new VendorPersFooterInfo();
 }
 public ViewLocalizer(IHtmlLocalizerFactory localizerFactory, IApplicationEnvironment appEnv)
 {
     _appName = appEnv.ApplicationName;
     _localizerFactory = localizerFactory;
 }
 /// <summary>
 ///   Initializes a new instance of the <see cref="LocalizeTagHelper" /> class.
 /// </summary>
 /// <param name="localizerFactory">
 ///   The localizer factory to create a <see cref="IHtmlLocalizer" /> from.
 /// </param>
 /// <param name="hostingEnvironment">The hosting environment.</param>
 /// <param name="options">The default options unless overridden when calling the tag helper.</param>
 public LocalizeTagHelper(IHtmlLocalizerFactory localizerFactory, IHostingEnvironment hostingEnvironment, IOptions <LocalizeTagHelperOptions> options)
     : base(localizerFactory, hostingEnvironment, options)
 {
 }
        public PasswordChangeModel(IHtmlLocalizerFactory htmlLocalizerFactory)
        {
            _loc = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.Index", Includes.AppShortName);

            NewPwd = new NewPassword();
        }
 public PrivacyModel(IHtmlLocalizerFactory htmlLocalizerFactory)
 {
     _loc = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.MainMenu", Includes.AppShortName);
 }
Esempio n. 28
0
        /// <summary>
        /// 创建默认多语言工厂
        /// </summary>
        /// <param name="htmlLocalizerFactory"></param>
        /// <returns></returns>
        public static IHtmlLocalizer Create(this IHtmlLocalizerFactory htmlLocalizerFactory)
        {
            var localizationSettings = App.GetOptions <LocalizationSettingsOptions>();

            return(htmlLocalizerFactory.Create(localizationSettings.LanguageFilePrefix, localizationSettings.AssemblyName));
        }
Esempio n. 29
0
 public IdentityPagesLocalizer(IHtmlLocalizerFactory factory)
 {
     _localizer = factory.Create(typeof(TResource));
 }
Esempio n. 30
0
 public ReservationSummaryModel(IHtmlLocalizerFactory htmlLocalizerFactory)
 {
     _loc        = htmlLocalizerFactory.Create(Includes.AppShortName + ".Pages.ReservationSummary", Includes.AppShortName);
     ResSummData = new ReservationSummaryData();
 }
Esempio n. 31
0
 /// <summary>
 /// Creates a new <see cref="HtmlLocalizer"/>.
 /// </summary>
 /// <param name="factory">The <see cref="IHtmlLocalizerFactory"/>.</param>
 public HtmlLocalizer(IHtmlLocalizerFactory factory)
 {
     _localizer = factory.Create(typeof(TResource));
 }
 public JsonFileViewExtendedLocalizer(IHtmlLocalizerFactory htmlLocalizerFactory, IObjectLocalizerFactory objectLocalizerFactory)
 {
     _htmlLocalizerFactory   = htmlLocalizerFactory ?? throw new ArgumentNullException(nameof(htmlLocalizerFactory));
     _objectLocalizerFactory = objectLocalizerFactory ?? throw new ArgumentNullException(nameof(objectLocalizerFactory));
 }
 protected LocalizeTagHelper CreateTagHelper(IHtmlLocalizerFactory factory)
 {
     return(TestHelper.CreateTagHelper <LocalizeTagHelper>(factory));
 }