简体   繁体   English

Blazor WebAssembly 中的伪本地化

[英]Pseudo-localization in Blazor WebAssembly

Following the tutorial on adding localization to Blazor WebAssembly , I successfully have a demo app that will show me either English or Spanish.按照有关向 Blazor WebAssembly 添加本地化的教程,我成功地拥有了一个演示应用程序,它将向我显示英语或西班牙语。

For the sake of simplicity, I've implemented just the parts in Statically set the culture and Localization -- ie I'm directly setting the target culture in Program.cs using code such as this:为了简单起见,我只实现了静态设置文化本地化中的部分——即,我使用如下代码直接在 Program.cs 中设置目标文化:

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.我已经有一个工具可以自动从*.resx文件生成*.qps-ploc.resx文件。 I have confirmed that this is generating the satellite resource assembly file in qps-ploc\MyApp.resources.dll , and it contains the correct resources.我已经确认这是在qps-ploc\MyApp.resources.dll中生成卫星资源程序集文件,并且它包含正确的资源。

The qps-ploc resources are also copied to the publish/wwwroot/_framework/qps-ploc folder as expected on using dotnet publish . qps-ploc 资源也被复制到publish/wwwroot/_framework/qps-ploc文件夹,正如使用dotnet publish时所期望的那样。 And they are listed under satelliteResources in the blazor.boot.json .它们列在blazor.boot.json中的satelliteResources下。

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?为什么,我该如何解决这个问题?

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.您没有提到如何引入将字符串实际转换为新语言所需的 IStringLocalizer 服务,也没有提到如何为本地化配置字符串。

You need to have: @inject IStringLocalizer<...> Loc on each razor page that you want to have translations performed on.您需要: @inject IStringLocalizer<...> Loc在您想要执行翻译的每个剃须刀页面上。

You also need to use @Loc["blah blah..."] for each string that you want translated.您还需要为每个要翻译的字符串使用@Loc["blah blah..."] Then in your resource file you would have a matching entry for every "blah blah..." string that you want localized.然后在您的资源文件中,您将有一个匹配的条目,用于您想要本地化的每个“blah blah ...”字符串。

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?在尝试变得聪明并使用其他语言之前,您是否确实首先遵循了 Microsoft 示例的确切措辞(对于 es-CL)?

It's worked fine for me (using es-CL and other cultures), so I suspect you've not ticked all the required boxes.它对我来说效果很好(使用 es-CL 和其他文化),所以我怀疑你没有勾选所有必需的框。

Have you traced down into the ResourceManager for this?你有没有为此追踪到 ResourceManager ? You should be able to single step through the client-side code.您应该能够单步执行客户端代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM