如何为多语言网站 (PHP) 构建数据库
我将建立一个多语言网站。我不太确定如何构建数据库。我应该有一个数据库并有这样的表格:
markets_en
materials_en
...
markets_es
materials_es
...
还是应该为每种语言都有一个数据库,其中所有表格的名称都没有语言扩展名(市场、材料等)?简而言之,我不确定切换数据库并使所有结构并行是否更明智,或者只是在一个数据库中拥有不同语言的相同表。
I'm going to be building a multilingual website. I'm not quite sure how to structure the database(s). Should I have one database and have tables like this:
markets_en
materials_en
...
markets_es
materials_es
...
Or should I have a database for each language with all of the tables having names without the language extension (markets, materials, etc)? In short, I'm not sure whether it's wiser to switch databases and have all of the structures be parallel, or just have identical tables with different languages in them, all in one database.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议多个数据库具有并行表结构,这意味着您只修改连接字符串而不是每个查询
I suggest multiple databases with parallel table structures, it means you are only modifying the connection string and not every query
在不了解您的具体情况的情况下,在我看来,DRY 原则建议您只使用一个数据库,其中一个表存储所有语言,而不是按语言对其进行细分。那根本无法扩展。相反,只需使用 UTF-8 或类似的方式对所有条目进行编码/存储,然后在用户级别处理编码。 (我们有一个存储全球客户的数据库,编码范围从拉丁语到日语编码。)因此,在用户表(或其他有意义的地方)中创建一个编码列,该列基于您确定他们使用的语言正在使用。然后,当您存储和检索给定用户的记录时,请检查其编码和滚动。在我看来,你会省去很多麻烦。
希望有帮助。
Without knowing your specific situation, it seems to me that DRY principles would suggest you just have one database with one table storing all languages and not break it out by language. That just doesn't scale. Instead, just encode/store all entries using UTF-8 or something similar, and then handle encoding at the user level. (We had a database storing customers worldwide, with encodings ranging from the latins to the japanese encodings.) So, in the user table (or somewhere else if it makes sense) create a column for encoding that's based on however you determine what language they're using. Then, as you store and retrieve records for a given user, check their encoding and roll. You'll save yourself lots of headaches, IMO.
hope that helps.