/// <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); }
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); }
/// <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; }
/// <summary> /// Instantiates a new <see cref="DefaultTagHelperActivator"/> instance. /// </summary> /// <param name="option">The <see cref="LanguageViewLocationExpanderOption"/>.</param> public LanguageViewLocationExpander(LanguageViewLocationExpanderOption option) { _option = option; }
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); }