Reputation: 14133
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.
Upvotes: 3
Views: 1420
Reputation: 15410
I'm not clear reading your post whether you are maintaining user-generated content together with your own localizable content in the same DB table. If that's the case, it sounds like you should consider separating them.
If your own content is stable (i.e. you won't be adding new content or changing it between deployments of updates of your app), then it should live in your localizable resources rather than in the database and you should treat it just like your localized UI.
If on the other hand it is dynamic content, then there seems to be no alternative to storing it in the DB. You would need to store a content ID as well as a language ID for each (the compound key Paweł Dyda refers to) in a separate localization table that provides the translated versions of each content. Or perhaps you could rely on a multilingual CMS to manage this multilingual content (see for example the WPML plug-in for WordPress)
Upvotes: 0
Reputation: 18662
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...
Upvotes: 1