且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 ORM 中使用多语言数据库模式?

更新时间:2023-01-22 11:44:54

仅使用一个表进行所有翻译可能会很快导致任何操作(选择/插入/更新/删除)的严重性能和复杂性问题;试着理解我的意思.

Using only one table for all translations may quickly lead to severe performance and complexity issues for any operation (select/insert/update/delete) ; just try it to understand what I mean.

然后我会采用以下方法(每个可翻译"对象有两个表),这似乎在性能、复杂性和维护问题之间取得了很好的平衡.

I would then go for the following method (two tables per "translatable" object), which seems a good balance between performance, complexity, and maintenance issues.

product
  - id (PK)
  - number1
  - number2
  - date1
  - date2
  ...

product_i18n
  - id (PK)
  - product_id (FK)
  - language_id (FK)
  - string1
  - string2
  ...

language
  - id (PK)
  - name

检查它是如何使用 Propel ORM (PHP) 完成的:http://propelorm.org/blog/2011/01/11/propel-gets-i18n-behavior-and-why-it-matters.html

Check how it's done with Propel ORM (PHP) : http://propelorm.org/blog/2011/01/11/propel-gets-i18n-behavior-and-why-it-matters.html

HTH