Live Chat Icon For mobile
Live Chat Icon

How do I get a browser’s culture in Blazor WebAssembly?

Platform: Blazor| Category : JavaScript Interop, WebAssembly

To get a browser’s culture in Blazor WebAssembly, call the (navigator.language) property in JavaScript using the JavaScript interop function in Blazor. It will return the current browser’s language version.

Follow this code to get the browser’s culture in Blazor WebAssembly.


@page "/"
@inject IJSRuntime JSRuntime

    protected override async Task OnInitializedAsync()
        var browserLanguage = await JSRuntime.InvokeAsync<string>("getBrowserLanguage");


      . . .
      . . .

      window.getBrowserLanguage = function () {
            return (navigator.languages && navigator.languages.length) ? navigator.languages[0] :
                navigator.userLanguage || navigator.language || navigator.browserLanguage || 'en';

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.