English 中文(简体)
如何使数据库的数据国际化?
原标题: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.

我真的不喜欢把翻译放在数据库中的想法,也不与翻译表格一起加入每个文本栏。

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

http://www.un.org。 语言数量没有定论,因为现在我们用3种语言开展工作,但我希望我们能够需要许多其他语言。

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.

最佳回答

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).

除此以外,您实际上可以创建自己的资源管理员,读取数据库的内容,并将翻译与识别资料结合起来——在这种情况下,需要根据资源识别和语言来界定你的主要关键内容(我认为,它被称为复合钥匙,是没有的):

---------------------------------------------------------
| 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...

问题回答

我不明白你的立场是,你是否在同一个非行表中保持用户生成的内容以及你自己的当地可观的内容。 如果是这样的话,它就象你一样认为分离。

如果你自己的内容稳定(即,你没有在更新你的照片之间增加新的内容或改变内容),那么,它就应该生活在你的当地资源中,而不是数据库中,而且你应该像你的地方化倡议一样对待它。

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)





相关问题
How does gettext handle dynamic content?

In php (or maybe gettext in general), what does gettext do when it sees a variable to dynamic content? I have 2 cases in mind. 1) Let s say I have <?=$user1?> poked John <?=$user2?>. ...

Explain the Need for Mutexes in Locales, Please

Reading the question Why doesn’t C++ STL support atoi(const string& ) like functions?, I encountered a comment which warned that GCC (at least) has a bug that can slow down multi-threaded ...

How does Vistalizer work

How does Vistalizer manage to override the language limit in Windows Vista Home edition. Which api s does it use to allow installation of Multiple language packages.

Localized exceptions (within a Struts2 app)

I am developing a Struts 2 application with support for multiple languages. If one of the domain objects needs to throw an exception, how can it do so in such a way that the error message is no ...

Rails Globalize plugin help

Has anyone gotten the Globalize plugin to work Rails 2.3.2 or later? If so, could you direct me to some useful info?

热门标签