用于翻译的 MySQL 结构

发布于 2024-11-06 04:15:36 字数 1247 浏览 3 评论 0原文

根据这种方法,默认语言在第一个表中已翻译。如果用户不需要翻译,他就不会为之烦恼。只需连接主表,仅此而已...

产品表(InnoDB):

 Obj_id(PK)             name                    desc
 ---------      -------------------     ------------------
     1          Million Dollar Baby    Short description is...
     2          Music Album            Another explanation...

翻译表(InnoDB)

 trans_id (PK)    Obj_id (FK)   lang      field              trans
--------------   -----------   ------    --------    ---------------------
      22              1          TR        name       Milyonluk Bebek
      23              1          BA        name       Djevojka od milijun...
      24              1          TR        desc       Kisa açiklama burada
      25              1          BA        desc       Kratki opis je ovdje
      26              2          BA        name       Glazba albuma

但是当管理员想要更改默认语言时就会出现问题。我有两个选择来解决这个问题:

  1. 管理员必须在项目开始时决定default_lang,如果他将来仍然想更改default_lang,程序会说:去死吧 .

  2. 像第一个解决方案一样,管理员必须首先决定default_lang,但是系统将能够将新的default_lang数据从转换表传输到主表(我实际上不这样做)。

我认为我的解决方案还不够好。

您对更改结构或不更改结构的 DEFAULT_LANG 问题有更好的了解吗(如果可能,请不要更改结构 - 我喜欢它)?

According to this approach, default language is already translated in first table. If a user doesn't need a translation, he won't struggle with them. Just connect primary table, that's all...

PRODUCT TABLE (InnoDB):

 Obj_id(PK)             name                    desc
 ---------      -------------------     ------------------
     1          Million Dollar Baby    Short description is...
     2          Music Album            Another explanation...

TRANSLATION TABLE (InnoDB)

 trans_id (PK)    Obj_id (FK)   lang      field              trans
--------------   -----------   ------    --------    ---------------------
      22              1          TR        name       Milyonluk Bebek
      23              1          BA        name       Djevojka od milijun...
      24              1          TR        desc       Kisa açiklama burada
      25              1          BA        desc       Kratki opis je ovdje
      26              2          BA        name       Glazba albuma

But the problem occurs when administrator wants to change default language. I have two options to solve this problem:

  1. Administrator has to decide default_lang at the beginning of the project and if he still wants to change default_lang in the future, the program will say: Go to hell.

  2. Like first solution, admin has to decide default_lang at first, but the system will be able to transfer new default_lang data from translation table to primary table (i don't do this actually).

I think my solutions are not good enough.

Do you have better idea about DEFAULT_LANG problem with or without change the structure (if it's possible, don't change the structure - i like it)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

云之铃。 2024-11-13 04:15:36

我想知道每种语言都有一个表是否会更好。这样您只需切换正在使用的表即可。

TRANSLATIONS_TR
TRANSLATIONS_EN
TRANSLATIONS_FR
TRANSLATIONS_BR

然后,在用户显示例程中,您决定在显示翻译文本时查询哪个表。

I wonder if having a table per language would be better. That way you'd just switch out tables that are being used.

TRANSLATIONS_TR
TRANSLATIONS_EN
TRANSLATIONS_FR
TRANSLATIONS_BR

Then in your user display routines, you decide what table to query when displaying translation text.

云胡 2024-11-13 04:15:36

gettext 解决了与多语言数据库不同的问题:gettext 用于 UI,而数据库用于内容。

您可以对错误消息、按钮标签或页面标题等固定装置使用 gettext 或等效方法,其中有一小部分不经常更改的项目。

多语言数据库适用于可能会或可能不会经常更改的大量内容,例如数十万本书和电影的标题或招标说明。

gettext solves a different kind of problem than a multilingual database: gettext is for the UI, while the database is for the content.

You'd use gettext or equivalent for fixtures like error messages, a button label or a page title, where there's a small list of items that change infrequently.

A multilingual database is for large volumes of content that may or may not change frequently, like, say, the titles of hundreds of thousands of books and movies, or descriptions for tenders.

长途伴 2024-11-13 04:15:36

我认为我的方法是(我正在自己构建这个过程中):

也许(1)产品有(N)个名称(取决于语言,假设您只有一列描述该语言,例如“es”, 'en')

[ Product ]—(1)—————(N)-[ProductName]
|    id   |             | name      |
                        | language  |

也许 N:M 关系中的产品语言更好:

[ Product ]-(N)—————————(M)-[Language]
|   id    |        |        |iso_code|
             (translation)  | name   |


[   Product   ]<————[ProdTranslation]———>[language]
|    id       |     | name          |    |iso_code|
|default name?|                          | name   |--- (name of language: "English")

另一种选择可能是将产品的每个翻译视为产品的“类型”(子类)。逻辑模型如下:

[   Product   ]
|    id       |-(1)————(1)-[ EnglishProduct ]
|default name?|            | name (in eng.) |
|             |
|             |-(1)——(1)-[FrenchProduct]
|             |          | name(in fr.)|

在关系数据库中实现这一点时,您可以 a) 有 3 个表(在本示例中,更多表包含更多语言)或 b) 将其全部放入一个表中。这取决于您拥有多少种语言、名称/描述的大小、性能等。

[ Product ]
| id      |
| name_en |
| name_fr |
| name_de |

查询数据库的代码将知道要使用的语言,然后从右列查询名称。

My approach I think it would be (I'm in the process of building this myself):

Maybe (1)Product has (N)Names (depending on language, assuming you only have one column describing the language, like 'es', 'en')

[ Product ]—(1)—————(N)-[ProductName]
|    id   |             | name      |
                        | language  |

Maybe it's better Product-Language in a N:M relationship:

[ Product ]-(N)—————————(M)-[Language]
|   id    |        |        |iso_code|
             (translation)  | name   |


[   Product   ]<————[ProdTranslation]———>[language]
|    id       |     | name          |    |iso_code|
|default name?|                          | name   |--- (name of language: "English")

Another option could be to consider each translated of the product to be a "type of" Product (a subclass). Logical model follows:

[   Product   ]
|    id       |-(1)————(1)-[ EnglishProduct ]
|default name?|            | name (in eng.) |
|             |
|             |-(1)——(1)-[FrenchProduct]
|             |          | name(in fr.)|

When implementing this in a relational database, then you could either a) have 3 tables (in this example, more with more languages) or b) put it all in one table. It depends on how many languages you would have, size of the name/description, performance, etc.

[ Product ]
| id      |
| name_en |
| name_fr |
| name_de |

The code querying the database would know the language to be used, and then query the name from the right column.

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