如何设计具有多语言支持的图像标签/标签数据库?

时间:2018-11-09 03:18:53

标签: database database-design

我有一个数据库表,用于存储图像标签,其结构如下:

table:
- tags
column:
- id (tag primary key)
- title (tag text)
- description (tag description)

我需要将标题和说明翻译成其他语言。一种方法是创建一个包含以下语言的表:

table:
- languages
column:
- lang_code (language unique code like 'en', 'ar')
- title (language text like 'English', 'Arabic')

,然后将lang_code字段添加到tags表中:

table:
- tags
column:
- id (tag primary key)
- lang_code (foreign key referencing the language table)
- title (tag text)
- description (tag description)

采用这种设计,无法将标签翻译链接在一起。也就是说,不可能为某个标签选择所有翻译,因为每个标签条目都有自己的id,对吗?

为解决此问题,我将使用在HERE发布的Stackoverflow答案中描述的数据库设计方法,而我的表将是:

table:
- tags
column:
- id (tag primary key)


table:
- tags_translations
column:
- tag_id (foreign key referencing the tags table)
- lang_code (foreign key referencing the language table)
- title (tag text)
- description (tag description)

使用这种方法,不同的标签翻译将引用相同的标签ID。使用此ID,可以使用SELECTJOIN命令选择某个标签的所有翻译。

我对最后一种方法的看法是,tags表仅包含一列,即id作为与语言无关的字段。对于标记翻译案例,这将是一个好的数据库设计吗?满足此需求的其他方法是什么?

0 个答案:

没有答案