Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mvc Localize Database values

What's the best way to localize datas which come from db. Such as Category Names ?

MVC C# .net 4,4.5

like image 429
ersin ceylan Avatar asked Apr 23 '26 20:04

ersin ceylan


2 Answers

You would need to have the translated values in the database.

If there are few languages, and will not change, you could add a column for each language (NameEn, NameEs, NameFr, etc.). Kinda goes against normalization rules, but makes life easier.

The other db approach would be to have a table that keeps all the translations:

Localize
 - Field
 - Locale
 - Translation

Then for the Category Name you would have three records, one for each language. You would simply query the table by field and locale.

like image 168
Cloud SME Avatar answered Apr 26 '26 10:04

Cloud SME


A quite common approach is to localize it via your database by creating a separate translation table for each table with at least one columns that needs localization. This is what we usually do in our projects. Database data -> localize in DB. View/UI strings -> localize in resx Files.

Take a look at this answer here: Good database table design for storing localized versions of data

Edit: Contrary to the link we usually store the "default" language in the original table so there's no need to actually have a translation entry.

For example, if your table "Categories" contains the columns Id and Name your corresponding Translation table "Categories_Translation" could contain the columns CategoryId, LanguageCode, Name_Tx whereas Name_Tx contains the translated text of "Name" in the language "LanguageCode".

like image 38
360Airwalk Avatar answered Apr 26 '26 11:04

360Airwalk