0

I have an ASP.net Core version 5 application. In this application there is some javascript. In this javascript I sometimes need to convert between strings and numbers. This conversion needs to use the correct locale. I would like to use the same locale in my javascript as I'm using on the servers side. The server side locale is set up using a cookie with this code:

    Response.Cookies.Append(
        CookieRequestCultureProvider.DefaultCookieName,
        CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture, culture)), 
        new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1) }
        );

I thought that I could set the locale on the client by setting ApplyCurrentCultureToResponseHeaders to true.

    var supportedCultures = new[] { "en-US", "en", "nb-NO", "sv-SE" };
    services.Configure<RequestLocalizationOptions>(options =>
    {
        options.DefaultRequestCulture = new RequestCulture("en-US");
        options.AddSupportedCultures(supportedCultures);
        options.AddSupportedUICultures(supportedCultures);
        options.ApplyCurrentCultureToResponseHeaders = true;
    });

This results in a response header called content-language being set to the correct culture. So the correct culture gets to the client. But now is the question, how do I use this in my javascript code? I'm using methods like toLocaleString and parseNumber when converting back and forth between number and string. The content-language header does not seem to change the values in navigator.language for example, which I maybe expected.

Or maybe I'm going about this the wrong way?

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.