Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to internationalize data that came from Database?

I have a ASP.NET MVC Website that relys on resource files for UI internationalization. Some data in the database will be generated by useres (in their language), but some data is generated by me and users shouldn't edit it. For that system data, I would need to store just a "token" in database and translate it at the moment of diplay it to the user in his language.

I really don't like the idea of having the translation in the database, and join every text column with the translation tables.

What are my alternatives to accomplish this? May be an hybrid of DB and resources?

EDIT: The number of languages is indeterminated, for now we are working with 3 languages, but I hope we could need many other.

EDIT 2: This is mainly for Catalog data... some catalogs have system and user data in the same table. System data needs translation as is not editable by the user.

like image 367
Romias Avatar asked Nov 27 '25 01:11

Romias


1 Answers

You could actually store just the identifiers in the database and resolve them to language content from Resource Files (regular *.resx) at runtime.
Although in such case it quite does not make sense to store this in the database at all (just using resource files would suffice). And of course maintaining this would be a nightmare (you would need to actually synchronize contents of the database with resource files).

Other than that, you could actually create your own Resource Manager to read the contents from the database, and put translations along with identifiers - in such case, your primary key would need to be defined on both resource identifier and language (I think it is called compound key, isn't it?):

---------------------------------------------------------
| Id | Locale | Translation                             |
---------------------------------------------------------
| 1  | en-US  | Something happened on the way to heaven |
| 1  | pl     | Coś się stało na drodze do nieba        |
---------------------------------------------------------

But it would require modifying Database Schema...

like image 187
Paweł Dyda Avatar answered Nov 28 '25 15:11

Paweł Dyda



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!