0

I have these files in Resources project

  • Titles.resx
  • Titles.en.resx
  • Titles.fa.resx
  • Messages.resx
  • Messages.en.resx
  • Messages.fa.resx

now the switching works, but if the language in localstorage initially is set as "fa-IR" from last session, the switching works fine between english and persian, but if the language in localstorage is set as "en-US" from last session the switching doesnt work and what ever i do, all the captions are in english and i had checked and i am sure the culture is set to right culture, please help.

i did add this in program.cs :

    var host = builder.Build();
    var jsRuntime = host.Services.GetRequiredService\<IJSRuntime\>();
    var lang = await jsRuntime.InvokeAsync\<string\>("localStorage.getItem", "lang");
    if (!string.IsNullOrEmpty(lang))
    {
      var culture = new CultureInfo(lang);
      CultureInfo.DefaultThreadCurrentCulture = culture;
      CultureInfo.DefaultThreadCurrentUICulture = culture;
    
    }
    await host.RunAsync();

and this to languageService :

    public async Task<bool> SetLanguageAsync(string lang)
    {
      SetCulture(lang);
      await _jSRuntime.InvokeVoidAsync("localStorage.setItem", "lang", lang);

      return true;
    }

    private void SetCulture(string cultureName)
    {
      var culture = new CultureInfo(cultureName);
      CultureInfo.DefaultThreadCurrentCulture = culture;
      CultureInfo.DefaultThreadCurrentUICulture = culture;
    }
1

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.