Reputation: 107
What's the best way to localize datas which come from db. Such as Category Names ?
MVC C# .net 4,4.5
Upvotes: 3
Views: 2238
Reputation: 2207
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".
Upvotes: 1
Reputation: 9901
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.
Upvotes: 3