ASP .NET Core 1.0 RTM Localization not working

前端 未结 3 475
小蘑菇
小蘑菇 2020-12-19 07:09

I\'ve been trying to implement localization for my asp .NET Core 1.0 RTM web app following microsofts documentation and I just can not get it to work. The problem I\'m havin

3条回答
  •  囚心锁ツ
    2020-12-19 08:12

    Edit on @Siim Haas.
    It's works good.
    In my case: I using the LanguageViewLocationExpanderFormat.SubFolder

    At ConfigureServices(IServiceCollection services)

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddLocalization(opts => { opts.ResourcesPath = "Resources"; });
    
        services.AddMvc()
            .AddViewLocalization(
                Microsoft.AspNetCore.Mvc.Razor.LanguageViewLocationExpanderFormat.SubFolder,
                opts => { opts.ResourcesPath = "Resources"; }
            )
            .AddDataAnnotationsLocalization();
    
        services.Configure(opts =>
        {
            var supportedCultures = new[]
            {
                new CultureInfo("en-AU"),
                new CultureInfo("en-GB"),
                new CultureInfo("en-US"),
                new CultureInfo("en"),
                new CultureInfo("zh-cn"),
                new CultureInfo("zh"),
            };
            opts.DefaultRequestCulture = new Microsoft.AspNetCore.Localization.RequestCulture("en-US");
            opts.SupportedCultures = supportedCultures;
            opts.SupportedUICultures = supportedCultures;
        });
    }
    

    At Configure (IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseRequestLocalization();
    
        app.UseMvc(routes =>
        {
            routes.MapRoute(name: "default", template: "{controller=Home}/{action=Index}");
        });
    }
    

    My Resources stucts Like:

    {Your Project}/Resources/Views/{your controller}/ViewName.en-us.resx

提交回复
热议问题