1

I have a ASP.NET CORE 3.1 c# Web Application with multilanguage support. The multilanguage support uses Portable Object Localization. I'm in need to get the current language via Javascript. It is stored in a cookie setted using the following method :

    //GET /SetLanguage
    [HttpGet]
    public IActionResult SetLanguage(string culture, string returnUrl)
    {
        Response.Cookies.Append(
            CookieRequestCultureProvider.DefaultCookieName,
            CookieRequestCultureProvider.MakeCookieValue(new RequestCulture(culture)),
        new CookieOptions { Expires = DateTimeOffset.UtcNow.AddYears(1), IsEssential= true }
        );
        return LocalRedirect(returnUrl);
    }

Hoe can I do it? Thanks,

1 Answer 1

2

I think you can use the following code.

var current = document.cookie.split('; ').reduce((r, v) => {
                 const parts = v.split('=')
                 return parts[0] === '.AspNetCore.Culture'? decodeURIComponent(parts[1]) : r
                      }, '').split('|')[0].split('=')[1]
Sign up to request clarification or add additional context in comments.

Comments

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.