Esempio n. 1
0
 /// <summary>
 ///  Adds MVC localization to the application.
 /// </summary>
 /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
 /// <param name="format">The view format for localized views.</param>
 /// <returns>The <see cref="IMvcBuilder"/>.</returns>
 public static IMvcBuilder AddViewLocalization(
     [NotNull] this IMvcBuilder builder,
     LanguageViewLocationExpanderFormat format)
 {
     MvcLocalizationServices.AddLocalizationServices(builder.Services, format);
     return(builder);
 }
Esempio n. 2
0
        /// <summary>
        ///  Adds MVC localization to the application.
        /// </summary>
        /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
        /// <param name="format">The view format for localized views.</param>
        /// <returns>The <see cref="IMvcBuilder"/>.</returns>
        /// <remarks>
        /// Adding localization also adds support for views via
        /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
        /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
        /// </remarks>
        public static IMvcCoreBuilder AddViewLocalization(
            [NotNull] this IMvcCoreBuilder builder,
            LanguageViewLocationExpanderFormat format)
        {
            builder.AddViews();
            builder.AddRazorViewEngine();

            MvcLocalizationServices.AddLocalizationServices(builder.Services, format);
            return(builder);
        }
        /// <summary>
        ///  Adds MVC view localization to the application.
        /// </summary>
        /// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
        /// <param name="format">The view format for localized views.</param>
        /// <param name="setupAction">An action to configure the <see cref="LocalizationOptions"/>.</param>
        /// <returns>The <see cref="IMvcBuilder"/>.</returns>
        public static IMvcBuilder AddViewLocalization(
            this IMvcBuilder builder,
            LanguageViewLocationExpanderFormat format,
            Action <LocalizationOptions> setupAction)
        {
            if (builder == null)
            {
                throw new ArgumentNullException(nameof(builder));
            }

            MvcLocalizationServices.AddLocalizationServices(builder.Services, format, setupAction);
            return(builder);
        }
Esempio n. 4
0
    /// <summary>
    ///  Adds MVC view localization services to the application.
    /// </summary>
    /// <param name="builder">The <see cref="IMvcCoreBuilder"/>.</param>
    /// <param name="format">The view format for localized views.</param>
    /// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
    /// <remarks>
    /// Adding localization also adds support for views via
    /// <see cref="MvcViewFeaturesMvcCoreBuilderExtensions.AddViews(IMvcCoreBuilder)"/> and the Razor view engine
    /// via <see cref="MvcRazorMvcCoreBuilderExtensions.AddRazorViewEngine(IMvcCoreBuilder)"/>.
    /// </remarks>
    public static IMvcCoreBuilder AddViewLocalization(
        this IMvcCoreBuilder builder,
        LanguageViewLocationExpanderFormat format)
    {
        if (builder == null)
        {
            throw new ArgumentNullException(nameof(builder));
        }

        builder.AddViews();
        builder.AddRazorViewEngine();

        MvcLocalizationServices.AddLocalizationServices(builder.Services, format, setupAction: null);
        return(builder);
    }
Esempio n. 5
0
    public void AddLocalizationServices_AddsNeededServices()
    {
        // Arrange
        var collection = new ServiceCollection();

        // Act
        MvcLocalizationServices.AddMvcViewLocalizationServices(
            collection,
            LanguageViewLocationExpanderFormat.Suffix);

        // Assert
        AssertContainsSingle(collection, typeof(IHtmlLocalizerFactory), typeof(HtmlLocalizerFactory));
        AssertContainsSingle(collection, typeof(IHtmlLocalizer <>), typeof(HtmlLocalizer <>));
        AssertContainsSingle(collection, typeof(IViewLocalizer), typeof(ViewLocalizer));
    }
Esempio n. 6
0
    public void AddCustomLocalizers_BeforeAddLocalizationServices_AddsNeededServices()
    {
        // Arrange
        var collection = new ServiceCollection();

        // Act
        collection.Add(ServiceDescriptor.Singleton(typeof(IHtmlLocalizerFactory), typeof(TestHtmlLocalizerFactory)));
        collection.Add(ServiceDescriptor.Transient(typeof(IHtmlLocalizer <>), typeof(TestHtmlLocalizer <>)));
        collection.Add(ServiceDescriptor.Transient(typeof(IViewLocalizer), typeof(TestViewLocalizer)));

        MvcLocalizationServices.AddMvcViewLocalizationServices(
            collection,
            LanguageViewLocationExpanderFormat.Suffix);

        AssertContainsSingle(collection, typeof(IHtmlLocalizerFactory), typeof(TestHtmlLocalizerFactory));
        AssertContainsSingle(collection, typeof(IHtmlLocalizer <>), typeof(TestHtmlLocalizer <>));
        AssertContainsSingle(collection, typeof(IViewLocalizer), typeof(TestViewLocalizer));
    }