Hi I am trying to implement localization in .net core. I want to implement localization in my views static content. By default it will show German and can be changed to other languages as well. I have configured it to set default culture to German, but it is not working. Please Help

What i have tried is:-

In my startup file

public void ConfigureServices(IServiceCollection services)
        {

            //adding HttpContextAccessor middleware
            services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();

        services.AddRouting(options => options.LowercaseUrls = true);
        services.AddMvc();

        //configuration for multilanguage support
        services.AddLocalization();

        services.AddMvc()
 .AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
 .AddDataAnnotationsLocalization();



        //adding other services...
        ConfigureBusinessServices(services);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        var supportedCultures = new[]{
      new CultureInfo("en-US"),
      new CultureInfo("fr"),
      new CultureInfo("de"),

        };

        app.UseRequestLocalization(new RequestLocalizationOptions
        {
            DefaultRequestCulture = new RequestCulture("de"),
            // Formatting numbers, dates, etc.
            SupportedCultures = supportedCultures,
            // UI strings that we have localized.
            SupportedUICultures = supportedCultures
        });


        app.UseStaticFiles();
        app.UseSession();

        //configuring mvc routes...
        app.UseMvc(routes =>
        {
            routes.MapRoute(
               name: "areaRoute",
               template: "{area:exists}/{controller}/{action}/{id?}",
               defaults: new { controller = "Home", action = "Index" });

            routes.MapRoute(
                name: "default",
                template: "{controller}/{action}/{id?}",
                defaults: new { controller = "Home", action = "Index" });
        });
    }

In my View i have done this:-

@TestProject.Resources.TestProjectUI.Home.ContactUs.btn_TextSendMessage

to show the resource value

I am getting data from resource file but from English resource file because current culture is setting to English UK. I have getting output like this:

enter image description here

The current culture is showing as English, because of that the the message (Send Message English Culture) is coming from En.resx file.

0 Answers