问题描述
我们有一个PostgreSQL数据库。而且我们有几个表需要用几种语言保存某些数据(可能的语言列表在系统范围内已定义)。
We have a PostgreSQL database. And we have several tables which need to keep certain data in several languages (the list of possible languages is thankfully system-wide defined).
例如,让我们开始:
create table blah (id serial, foo text, bar text);
现在,让我们使用多种语言。
怎么样:
Now, let's make it multilingual.How about:
create table blah (id serial, foo_en text, foo_de text, foo_jp text,
bar_en text, bar_de text, bar_jp text);
这对Postgres中的全文本搜索会很好。只需为每种语言添加一个tsvector列
。
That would be good for full-text search in Postgres. Just add a tsvector columnfor each language.
但这是最佳选择吗?
也许我们应该使用另一个表来保留翻译?
像:
But is it optimal?Maybe we should use another table to keep the translations?Like:
create table texts (id serial, colspec text, obj_id int, language text, data text);
也许,也许,我们应该使用其他东西-SQL世界之外的东西?
感谢您的帮助。
Maybe, just maybe, we should use something else - something out of the SQL world?Any help is appreciated.
推荐答案
我认为最好创建两个表。一种用于语言,一种用于ID,依此类推。
first_table(id)
second_table(s_id,id_first_table,language_id,language_text)
I think it is best if you create two tables. One for languages, one for ids and so on.first_table( id )second_table( s_id, id_first_table, language_id, language_text)
这篇关于如何设计数据库模式以存储多种语言的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!