简体   繁体   English

如何处理 ASP.NET Core 中的本地化内容?

[英]How to handle localized content in ASP.NET Core?

what is the best way to store and display localized user-supplied content through models in ASP.Net Core so that your site can be multilingual?通过 ASP.Net Core 中的模型存储和显示本地化用户提供的内容以便您的站点可以使用多语言的最佳方法是什么? The ASP.NET localization guides show how to localize the static parts of a web site like labels and messages. ASP.NET 本地化指南展示了如何本地化网站的静态部分,如标签和消息。

I'm looking for a way to be able to store localized user-supplied content in multiple languages, and display the correct language based on in the user's selection.我正在寻找一种方法,能够以多种语言存储本地化的用户提供的内容,并根据用户的选择显示正确的语言。 So if the language is set to Thai, the application displays the Thai versions of the content, such as product description in Thai.因此,如果语言设置为泰语,应用程序会显示内容的泰语版本,例如泰语的产品描述。

Is there a way to do this in ASP.NET Core?有没有办法在 ASP.NET Core 中做到这一点?

nopCommerce provides this feature - you can add multiple languages and enter details for product, user, category models etc in all the languages that you've selected (see image). nopCommerce 提供此功能 - 您可以添加多种语言,并以您选择的所有语言输入产品、用户、类别模型等的详细信息(见图)。

nopCommerce bilingual model entry form nopCommerce 双语模型报名表nopCommerce 双语模型报名表

nopCommerce stores these localization features in a database table (LocalizedProperty) essentially as key-value pairs with foreign keys to determine the object it's tied to. nopCommerce 将这些本地化功能存储在数据库表 (LocalizedProperty) 中,本质上是作为键值对与外键来确定它所关联的对象。

nopCommerce LocalizedProperty table nopCommerce LocalizedProperty 表nopCommerce LocalizedProperty 表

How do you make the application serve the correct values from such a table depending on locale?您如何使应用程序根据区域设置从这样的表中提供正确的值?

You may follow this solution.您可以遵循此解决方案。 I suggest you have two tables.我建议你有两张桌子。 One is for the master data, and the other is for localized data.一个用于主数据,另一个用于本地化数据。 For example:例如:

  1. Have main table eg Product, to contains master data like ProductCode, Name, Description, and also have a field named like ObjectGuid, to identify Product object uniqueness.有主表,例如产品,包含产品代码、名称、描述等主数据,还有一个名为 ObjectGuid 的字段,用于标识产品对象的唯一性。
  2. Have Localize Table, to contains translated data of Name, Description, and also have a field named like "Language" to identify language of Name, Descript.有Localize Table,包含Name、Description的翻译数据,还有一个像“Language”这样的字段来标识Name、Descript的语言。 This table need to have OwnerGuid where linked to ObjectGuid.这个表需要有 OwnerGuid 链接到 ObjectGuid。
  3. Link Product to Localize with one-two-many relationship, using Product.ObjectGuid==Localize.OwnerGuid && UICulture.language==Localize.Language, where UICulture.language is provided by your user.使用 Product.ObjectGuid==Localize.OwnerGuid && UICulture.language==Localize.Language 将 Product 链接到具有一对多关系的 Localize,其中 UICulture.language 由您的用户提供。

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

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