Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Localization

$
0
0

Hi!

Im trying to get localization to work in a ASP.NET Core project. (Visual Studio 2017)

In my view /Views/Home/Index.chtml I whant to print out @Localizer["StartPageTitle"] (Now only shows "StartPageTitle")
I also print out current culture, which is correct set. (sv-SE)

In the Resource folder I got an resourcefile "Views.Home.Index.sv-SE.resx", with the "StartPageTitle" translation.

In Startup.cs / ConfigureServices:

services.AddLocalization(options => options.ResourcesPath = "Resources");

            services.AddMvc(options =>
            {
                options.SslPort = 44300;
                options.Filters.Add(new RequireHttpsAttribute());
            }).AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
                .AddDataAnnotationsLocalization();

In Startup.cs / Configure

 var supportedCultures = new[]
            {
                new CultureInfo("en-US"),
                new CultureInfo("en"),
                new CultureInfo("sv-SE"),
                new CultureInfo("sv")
            };

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

Any one have any ideas or suggestions?

/Jonas


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>