BlazorWasmPreRendering.Build icon indicating copy to clipboard operation
BlazorWasmPreRendering.Build copied to clipboard

Localization did not work after publish the project.

Open mikeyoshino opened this issue 3 years ago • 3 comments

Hi, my Blazor Wasm has 2 resource files representing 2 languages Thai, and English. I have SetDefaultCulture method to set the default language to Thai when the application first starts.

public async static Task SetDefaultCulture(this WebAssemblyHost host)
    {
      ILocalStorageService localStorage =  host.Services.GetRequiredService<ILocalStorageService>();
      string getCulture =  await localStorage.GetItemAsStringAsync("Culture");
      CultureInfo culture;
      if (getCulture != null)
      {
        culture = new CultureInfo(getCulture);
      }
      else
      {
        await localStorage.SetItemAsStringAsync("Culture", "th-TH");
        culture = new CultureInfo("th-TH");
      }
      CultureInfo.DefaultThreadCurrentCulture = culture;
      CultureInfo.DefaultThreadCurrentUICulture = culture;
    }

but when I publish the project, the language in static files are in English. How can I set pretender to render Thai language and setting default culture doesn't really work?

mikeyoshino avatar Oct 21 '22 03:10 mikeyoshino

@mikeyoshino Thank you for your report! Honestly, I've never considered localization scenarios seriously. I'll investigate this localization scenario, and I'll try to resolve it. However, I haven't had enough time to do that recently, so it will take much longer than you expected. I'll appreciate your patience.

jsakamoto avatar Oct 22 '22 13:10 jsakamoto

@mikeyoshino I updated the new version of the "BlazorWasmPreRendering.Build" NuGet package. This latest version allows us to set the custom locale for pre-rendering via an MSBuild property. Please see the "Locale" section of the README document.

I also attach the sample project as the following zip file.

📦BlazorWasmApp1.zip

The zip file above includes Git local repository, so you can see the commit history to know how to change to add support for pre-rendering with the "th-TH" culture. I hope that this solution will make sense to you.

jsakamoto avatar Oct 23 '22 23:10 jsakamoto

@jsakamoto Localization: the extension seems to see only one main language on the HOME page. Do I have to write separate home pages for every language I use to have them indexed? The home page is pre-rendered only in the en language, I will test if it is possible to fix with <BlazorWasmPrerenderingLocale>ja-JP,en-US</BlazorWasmPrerenderingLocale>

my locales are more simple: en, ja, ru, tg, zh , but listing them is not working... :( <BlazorWasmPrerenderingLocale>en,ja,ru,tg,zh</BlazorWasmPrerenderingLocale>

nakigoe avatar Jul 03 '23 09:07 nakigoe