Reputation: 13075
Following the tutorial on adding localization to Blazor WebAssembly, I successfully have a demo app that will show me either English or Spanish.
For the sake of simplicity, I've implemented just the parts in Statically set the culture and Localization -- i.e. I'm directly setting the target culture in Program.cs using code such as this:
var culture = new CultureInfo("es-ES");
CultureInfo.DefaultThreadCurrentCulture = culture;
CultureInfo.DefaultThreadCurrentUICulture = culture;
As noted above, this works fine. But I would also like to add support for pseudo-translation.
I already have a tool that generates *.qps-ploc.resx
files from *.resx
files automatically. I have confirmed that this is generating the satellite resource assembly file in qps-ploc\MyApp.resources.dll
, and it contains the correct resources.
The qps-ploc resources are also copied to the publish/wwwroot/_framework/qps-ploc
folder as expected on using dotnet publish
. And they are listed under satelliteResources
in the blazor.boot.json
.
However, when specifying the following, it loads the default resources instead of the pseudo resources:
var culture = new CultureInfo("qps-ploc");
Why, and how do I fix this?
Upvotes: 2
Views: 240
Reputation: 155
You haven't mentioned how you are bringing in the IStringLocalizer service required for actually converting your strings into the new language, nor how you have the strings configured for localization.
You need to have:
@inject IStringLocalizer<...> Loc
on each razor page that you want to have translations performed on.
You also need to use @Loc["blah blah..."]
for each string that you want translated. Then in your resource file you would have a matching entry for every "blah blah..." string that you want localized.
Have you definitely followed the exact wording of the Microsoft sample first (for es-CL), before you then try to get smart and do your other language?
It's worked fine for me (using es-CL and other cultures), so I suspect you've not ticked all the required boxes.
Have you traced down into the ResourceManager for this? You should be able to single step through the client-side code.
Upvotes: -1