多语言应用的数据库设计问题
我们正在开发一个旅游门户网站,对于旅游门户网站来说,其内容和细节是核心。我们计划将其放在多个区域设置中,因此这意味着我们需要处理每个区域设置的动态数据。
目前我们有以下表格,
Destination
Transport
Places of Interests
user comments etc.
每个表格包含很多字段
Name
ShortDescription
LongDescription
,以及许多其他字段,这些字段可以包含大量数据,我们需要以特定于区域设置的方式处理数据。
我不确定我们如何最好地设计一个应用程序来处理这种情况,我想到的一件事是为每个表中的每个区域设置添加额外的列,但这意味着对于新的区域设置,需要从数据库级别更改为代码级别这一点都不好。
由于每个表包含很多列,其中可以包含符合国际化条件的数据,所以我的问题是处理这种情况的最佳方法是什么
edit1 经过一些分析和仔细研究后,我想到的一种方法如下..
我计划为每个表创建一个翻译表 就像目的地一样,我有以下设计
table languages
-- uuid (varchar)
-- language_id(varchar)
-- name (varchar)
table Destination
--uuid (varchar)
other fields which are not part of internationalization.
table Destination_translation
-- id (int)
-- destination_id (int)
-- language_id (int)
-- name (text)
-- description(text)
非常欢迎对上述方法提出任何宝贵的建议......
We are working on a travelling portal and for a traveling portal its content and details are the heart.we are planning to have it in multiple locale so this means we need to handle the dynamic data for each locale.
currently we have following tables
Destination
Transport
Places of Interests
user comments etc.
each table contains a lot of fields like
Name
ShortDescription
LongDescription
and many other fields which can contains a lot of data and we need to handle data in locale specific way.
i am not sure how best we can design an application to handle this case,one thing came to my mind is like putting extra column for each locale in each table but that means for a new locale things needs to be changed from database to code level and that is not good at all.
Since each table contains a lot of columns which can contain data eligible for internationalization so my question is what might be the best way to handle this case
edit1
After doing some analysis and some goggling one approach that came to my mind is as below..
i am planning to create a translation table for each table
like for destination i have the following design
table languages
-- uuid (varchar)
-- language_id(varchar)
-- name (varchar)
table Destination
--uuid (varchar)
other fields which are not part of internationalization.
table Destination_translation
-- id (int)
-- destination_id (int)
-- language_id (int)
-- name (text)
-- description(text)
Any valuable suggestion for above mentioned approach are most welcome...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以前在国际化应用程序时,我们有一个基于区域设置的值表。因此,我们做了这样的事情:
创建一个名为 local_strings 的表,由 string_code、locale_code、值组成。这包含各种值的翻译。因此,如果您已翻译成三种语言,则每个 string_code 都会有三个具有不同 locale_codes 的条目。
然后,每个主表(在您的情况下为目的地、传输等)都会引用 local_strings 表中的 string_code 。
最后,当从数据库中查询值时,请确保始终加入 local_strings 表并始终使用用户的当前区域设置。或者,您可以将这些值缓存在内存中,这样您就不必总是连接该表。然而,根据我的经验,表永远不会变得那么大,因此加入它并没有太多开销。
When internationalizing an application previously, we had a table of locale-based values. So, we did something like this:
Create a table called local_strings, made up of a string_code, locale_code, value. This contains translations of various values. So, if you had translated to three languages, there would be three entries with different locale_codes for each string_code..
Then, each of the master tables, in your case destination, transport, etc. has a reference to a string_code in the local_strings table.
Finally, when querying values out of the database, just be sure that you always join in the local_strings table and always use the user's current locale. Alternatively, you could cache these values in memory so that you don't always join with this table. However, the table never gets that big, in my experience, so there's not much overhead to just join it.
有多种选项可以解决此问题:
我肯定会喜欢选项 1,因为它使表看起来仍然像真实的东西,并且仍然可以通过直接查看数据来读取它们。它还可以防止您进行子选择或连接,这有助于提高性能。
选项 2 的优点只是让管理界面的程序员更加轻松(如果您有的话)。
There are several options to solve this:
I would definitely favor option 1 as it makes the tables still look like the real thing and they can still be read by looking at the data directly. It also prevents you from having to do subselects or joins, which helps performance.
Option 2's advantage is only the greater ease for the programmer of the administrative interface (if you have one).