简体   繁体   English

使用数据库资源本地化 Blazor 托管的 Web 程序集

[英]Localize a Blazor hosted Webassembly with a databse resource

I try to localize my Blazor hosted Webassembly.我尝试本地化我的 Blazor 托管的 Webassembly。 For this i have created a Database and oriented on the following link:为此,我创建了一个数据库并针对以下链接:

https://www.ezzylearning.net/tutorial/asp-net-core-localization-from-database https://www.ezzylearning.net/tutorial/asp-net-core-localization-from-database

But the tutorial is for a ASP.NET Core application.但本教程适用于 ASP.NET Core 应用程序。 How can i use this solution in Blazor?如何在 Blazor 中使用此解决方案?

I following all the steps but in the end i can´t connect the database as a resource to my IStringLocalizer<T> localizer .我遵循了所有步骤,但最后我无法将数据库作为资源连接到我的IStringLocalizer<T> localizer How can i achieve that in my client project instead of the usual resx file the database is created via the controller in my server project is used?如何在我的客户端项目而不是通常的 resx 文件中实现这一点,数据库是通过我的服务器项目中的控制器创建的?

You'd need to implement your own version of the IStringLocalizer interface... however you should note that this is really just a shim interface over the ResourceManagerLocalizer, and the ResourceManagerStringLocalizerFactory.您需要实现您自己的 IStringLocalizer 接口版本……但是您应该注意,这实际上只是 ResourceManagerLocalizer 和 ResourceManagerStringLocalizerFactory 上的 shim 接口。 These obviously use the ResourceManager which is where the resx file formats (which get embedded as resources into assemblies) come into it.这些显然使用 ResourceManager,这是 resx 文件格式(作为资源嵌入到程序集中)进入其中的地方。

So you'd:所以你会:

  1. Create a DbStringLocalizer (implementing IStringLocalizer) which would retrieve your desired translation from the DB, you'd probably want to cache translations also, to avoid network round trips.创建一个 DbStringLocalizer(实现 IStringLocalizer),它将从数据库中检索您想要的翻译,您可能还想缓存翻译,以避免网络往返。
  2. Create a DbStringLocalizerFactory which would cache DbStringLocalizer instances to avoid losing cached translations also创建一个 DbStringLocalizerFactory 将缓存 DbStringLocalizer 实例以避免丢失缓存的翻译
  3. Create an Extension method to easily allow you to register your Singleton DbStringLocalizerFactory, and your Transient DbStringLocalizer创建一个扩展方法,让您轻松注册您的 Singleton DbStringLocalizerFactory 和您的 Transient DbStringLocalizer

The .NET Core sources are readily available, so you could implement closely in line with the existing source. .NET Core 源代码现成可用,因此您可以根据现有源代码实现紧密结合。 Just using a DB connection (and CultureInfo handling) in place of the ResourceManager (which already handles CultureInfo lookups).只需使用数据库连接(和 CultureInfo 处理)代替 ResourceManager(它已经处理 CultureInfo 查找)。

And the Microsoft guide for the ResourceManager Webassembly version (that you should use as your starting point for DB driven)以及 ResourceManager Webassembly 版本的 Microsoft 指南(您应该将其用作 DB 驱动的起点)

https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-6.0&pivots=webassembly https://docs.microsoft.com/en-us/aspnet/core/blazor/globalization-localization?view=aspnetcore-6.0&pivots=webassembly

暂无
暂无

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

相关问题 Blazor webassembly 托管在子文件夹中 - Blazor webassembly hosted in sub folder 将 WebAssembly Blazor 转换为托管的 - Convert WebAssembly Blazor to a Hosted one blazor webassembly windows 身份验证 + .netcore 托管 - blazor webassembly windows authentication + .netcore hosted 请求 header 'Referer' 在托管 Blazor Webassembly 和非托管 Blazor Webassembly 之间是不同的 - Request header 'Referer' is different between Hosted Blazor Webassembly, and non hosted Blazor Webassembly Blazor WebAssembly 应用程序与个人帐户和 ASP.NET 核心托管 - IIS - SQLLocalDB 15.0 找不到指定的资源语言 ID - Blazor WebAssembly App with Individual Accounts and ASP.NET Core Hosted - IIS - SQLLocalDB 15.0 The specified resource language ID cannot be found 如何使用 ASP.NET 核心托管发布 Blazor WebAssembly - How to publish Blazor WebAssembly with ASP.NET Core hosted 部署托管到 Azure 的 Blazor WebAssembly 应用 ASP.NET Core - Deploy Blazor WebAssembly App ASP.NET Core hosted to Azure 如何在具有控制器 API 服务的 razor pages 应用程序托管的 blazor webassembly 上启用 CORS - How to enable CORS on a blazor webassembly, hosted by a razor pages app with controller API services Blazor Webassembly (PWA) 是否支持独立的 session 存储(不在 asp.net 内核中托管)? - Is session storage supported in Blazor Webassembly (PWA) standalone (Not hosted in asp.net core)? C# .NET 核心托管 Blazor WebAssembly - 将其他客户端添加到.Server 项目 ZDB974238714CA38DE634A7CE1D0 - C# .NET Core Hosted Blazor WebAssembly - Add additional clients to .Server project API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM