Blazor WebAssembly 中的本地化

Localization in Blazor WebAssembly

我正在尝试为 Blazor WebAssembly 应用实现本地化。 我跟着example referred in the Documentation。 我按照示例创建了 .resx 文件,但我的 Blazor WebAssembly 应用程序只显示默认 .resx 文件的字符串,忽略了各个区域性的 .resx 文件。 在上面提到的文档中,我读到:

By default, Blazor's linker configuration for Blazor WebAssembly apps strips out internationalization information except for locales explicitly requested. For more information and guidance on controlling the linker's behavior, see Configure the Linker for ASP.NET Core Blazor.

在最后 link 之后,我尝试在我的项目文件下添加以下内容 <PropertyGroup>

<MonoLinkerI18NAssemblies>all</MonoLinkerI18NAssemblies>

但这似乎不起作用,在我的 Blazor WebAssembly 应用程序上我看不到本地化文本,我只能看到默认 .resx 文件的文本。

这应该会在下一版 Blazor 预览版 4 中得到解决。 example in a github issue的作者已经证实了这一点。 documentation 中的文章发布有点过早,但这应该会在 Blazor 预览版 4 发布后很快得到解决。

从 Blazor Web Assembly preview 4 本地化开始。此 article 展示了如何本地化 Web Assembly Blazor 应用程序。

无需再使用 .resx 文件。由于它们的 XML 结构,它们有点大。

试试这个插件,它太棒了,它使用 YAML 而不是 XML,这使得文件更轻,还有一个与之关联的在线工具,让您可以使用 Microsoft Translator 和 Azure 翻译文件.

https://akmultilanguages.azurewebsites.net

https://github.com/aksoftware98/multilanguages

这个项目https://github.com/enkodellc/blazorboilerplate has full localization for both WebAssembly and Server-side Blazor using the Microsoft.Extensions.Localization libraries. It does use Po files vs resx. Here is the documentation: https://blazor-boilerplate.readthedocs.io/en/latest/quickstarts/localization.html