多语言应用的数据库设计问题

发布于 2024-10-30 03:35:40 字数 962 浏览 0 评论 0原文

我们正在开发一个旅游门户网站,对于旅游门户网站来说,其内容和细节是核心。我们计划将其放在多个区域设置中,因此这意味着我们需要处理每个区域设置的动态数据。

目前我们有以下表格,

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心碎的声音 2024-11-06 03:35:41

以前在国际化应用程序时,我们有一个基于区域设置的值表。因此,我们做了这样的事情:

创建一个名为 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.

暮光沉寂 2024-11-06 03:35:41

有多种选项可以解决此问题:

  1. 通过区域设置列扩展表并在每个查询中包含区域设置。您甚至可以修改索引以包含区域设置列。
  2. 为本地化字符串创建一个单独的表

我肯定会喜欢选项 1,因为它使表看起来仍然像真实的东西,并且仍然可以通过直接查看数据来读取它们。它还可以防止您进行子选择或连接,这有助于提高性能。
选项 2 的优点只是让管理界面的程序员更加轻松(如果您有的话)。

There are several options to solve this:

  1. Extend your tables by a locale column and include the locale in every query. You could even modify the index to include the locale column.
  2. Create a separate table for lokalized strings

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文