How to handle localized content in ASP.NET Core?

1.2k Views Asked by At

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? The ASP.NET localization guides show how to localize the static parts of a web site like labels and messages.

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?

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 bilingual model entry form nopCommerce bilingual model entry form

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 table nopCommerce LocalizedProperty table

How do you make the application serve the correct values from such a table depending on locale?

1

There are 1 best solutions below

0
On

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 e.g. Product, to contains master data like ProductCode, Name, Description, and also have a field named like ObjectGuid, to identify Product object uniqueness.
  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. This table need to have OwnerGuid where linked to 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.