MySQL数据库模式的多语言站点-表与翻译每个父表或一个为所有?



因此,我正在为将来可能出现多个表的大型可伸缩应用程序创建数据库设计。我目前有大约30个表需要翻译。由于这个数字,我不想通过示例创建表:Products &产品翻译,只有一个表的所有翻译。

第一种方法(对我来说非常耗时)
Products

| ID | Status  | Sku     | Availability |
+====+=========+=========+==============+
| 1  | Enabled | 1-black | 50           |

Products_translations

| ID | Product_ID | Lang | is_default | Name | Description    |
+====+============+======+============+======+================+
| 1  | 1          | EN   | true       | Bike | Very nice bike |

等。

第二种方式(我的偏好)
Products

| ID | Status  | Sku     | Availability |
+====+=========+=========+==============+
| 1  | Enabled | 1-black | 50           |

translations

| ID | Parent_table | Parent_id | Lang | is_default | Key         | Value         |
+====+==============+===========+======+============+=============+===============+
| 1  | product      | 1         | EN   | true       | Name        | Bike          |
| 2  | product      | 1         | EN   | true       | Description | Very niceike  |

我的问题

  • 第二种方式与公认的标准有很大的不同吗?
  • 按照图案标准是否正确?
  • 是否有更好的方法(考虑到翻译所需的表的数量)?

所以我想到了这个主意:

创建两个表:translations

| ID | Parent_table | Parent_id | Lang | is_default | Key         | Value         |
+====+==============+===========+======+============+=============+===============+
| 1  | products     | 1         | EN   | true       | Name        | Bike          |
| 2  | products     | 1         | EN   | true       | Description | Very niceike  |

translations_config

| ID | table    | required_translations   | optional_translations |
+====+==========+=========================+=======================+
| 1  | products | ["name", "description"] | ["attributes"]        |

translations_config需要从ACP创建翻译。

和正则表。products

| ID | Status  | Sku     | Availability |
+====+=========+=========+==============+
| 1  | Enabled | 1-black | 50           |

SELECT看起来类似于:

SELECT 
products.id, translations.lang, translations.is_default, translations.key, translations.value
FROM 
products
INNER JOIN 
translations ON (translations.parent_id = products.id AND translations.parent_table = 'products')

但我不知道它是否被接受的标准,并将为未来的工程师在这个项目上工作。

最新更新