コード例 #1
0
        /// <summary>
        ///  Adds Mvc localization to the application.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="option">The view format for localized views.</param>
        /// <returns>The <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection AddMvcLocalization(
            [NotNull] this IServiceCollection services,
            LanguageViewLocationExpanderOption option)
        {
            services.ConfigureRazorViewEngine(options =>
            {
                options.ViewLocationExpanders.Add(new LanguageViewLocationExpander(option));
            });

            return(services);
        }
コード例 #2
0
        public void ExpandViewLocations_SpecificLocale(
            LanguageViewLocationExpanderOption option,
            IEnumerable <string> viewLocations,
            IEnumerable <string> expectedViewLocations)
        {
            // Arrange
            var viewLocationExpanderContext  = new ViewLocationExpanderContext(new ActionContext(), "testView", false);
            var languageViewLocationExpander = new LanguageViewLocationExpander(option);

            viewLocationExpanderContext.Values             = new Dictionary <string, string>();
            viewLocationExpanderContext.Values["language"] = "en-GB";

            // Act
            var expandedViewLocations = languageViewLocationExpander.ExpandViewLocations(
                viewLocationExpanderContext,
                viewLocations);

            // Assert
            Assert.Equal(expectedViewLocations, expandedViewLocations);
        }
コード例 #3
0
        /// <summary>
        ///  Adds Mvc localization to the application.
        /// </summary>
        /// <param name="services">The <see cref="IServiceCollection"/>.</param>
        /// <param name="option">The view format for localized views.</param>
        /// <returns>The <see cref="IServiceCollection"/>.</returns>
        public static IServiceCollection AddMvcLocalization(
            [NotNull] this IServiceCollection services,
            LanguageViewLocationExpanderOption option)
        {
            services.ConfigureRazorViewEngine(options =>
            {
                options.ViewLocationExpanders.Add(new LanguageViewLocationExpander(option));
            });

            return services;
        }
コード例 #4
0
 /// <summary>
 /// Instantiates a new <see cref="DefaultTagHelperActivator"/> instance.
 /// </summary>
 /// <param name="option">The <see cref="LanguageViewLocationExpanderOption"/>.</param>
 public LanguageViewLocationExpander(LanguageViewLocationExpanderOption option)
 {
     _option = option;
 }
コード例 #5
0
        public void ExpandViewLocations_SpecificLocale(
            LanguageViewLocationExpanderOption option,
            IEnumerable<string> viewLocations,
            IEnumerable<string> expectedViewLocations)
        {
            // Arrange
            var viewLocationExpanderContext = new ViewLocationExpanderContext(new ActionContext(),"testView", false);
            var languageViewLocationExpander = new LanguageViewLocationExpander(option);
            viewLocationExpanderContext.Values = new Dictionary<string, string>();
            viewLocationExpanderContext.Values["language"] = "en-GB";

            // Act
            var expandedViewLocations = languageViewLocationExpander.ExpandViewLocations(
                viewLocationExpanderContext,
                viewLocations);

            // Assert
            Assert.Equal(expectedViewLocations, expandedViewLocations);
        }
コード例 #6
0
 /// <summary>
 /// Instantiates a new <see cref="DefaultTagHelperActivator"/> instance.
 /// </summary>
 /// <param name="option">The <see cref="LanguageViewLocationExpanderOption"/>.</param>
 public LanguageViewLocationExpander(LanguageViewLocationExpanderOption option)
 {
     _option = option;
 }