2014-09-11 49 views
2

上的项目,我有如下表:查找表本地化

create table dbo.Posts 
(
    Id int identity not null primary key clustered (Id), 
    Created datetime not null, 
); 

create table dbo.PostsLocalized 
(
    Id int identity not null primary key clustered (Id), 
    PostId int not null, 
    LanguageId int not null, 
    PostTypeId int not null, 
    [Text] nvarchar (max) not null, 
    Title nvarchar (120) not null, 
     constraint UQ_PostsLocalized_PostId_LanguageId unique (PostId, LanguageId) 
); 

create table dbo.PostTypes 
(
    Id int identity not null primary key clustered (Id), 
    Name nvarchar (max) not null 
); 

所以我用PostsLocalized表本地化的职位,但不是PostTypes表。

PostTypes表基本上是一个查找表,就像其他人在我的数据库中一样。

你认为我应该本地化查找表,例如PostTypes?

我会添加一个名为PostTypesLocalized与本地化名称的新表。

同样对于像性别,其他国家的查找表,...

或者我应该只在应用本地化的查找表?

UPDATE

澄清:

  1. 一个职位的所有本地化版本具有相同的PostType。

  2. 我需要在UI中显示PostTypes,这就是为什么我需要翻译它们。

所以,我想@dasblinkenlight的回答以下的新方法:

create table dbo.Posts 
(
    Id int identity not null primary key clustered (Id), -- The id of the localized post 
    Created datetime not null, 
    PostId int not null, -- The id of the post 
    PostTypeId int not null 
    LanguageId int not null, 
    [Text] nvarchar (max) not null, 
    Title nvarchar (120) not null, 
     constraint UQ_PostsLocalized_PostId_LanguageId unique (PostId, LanguageId) 
); 

create table dbo.PostTypes 
(
    Id int identity not null primary key clustered (Id), -- PostType localized id 
    PostTypeId int not null, -- The id of the post type 
    Name nvarchar (max) not null 
); 

考虑到(1)再上岗> PostTypeId应与PostTypes> PostTypeId。

但我该怎么做?

+0

我还建议您使用有意义的名称作为主键而不是ID。简单的ID不明确,迫使你根据他们所在的表格来更改列的名称。随着系统变得更大,这是一个非常痛苦的工作。给他们一个有意义的名字并保持一致。 – 2014-09-11 14:09:28

+0

@SeanLange,对不起在哪张桌子? – 2014-09-11 15:01:29

+0

所有这些。例如,您在帖子命名标识中有一列,它在其他表中成为PostID。只需在每个表格中将其命名为PostID即可。与所有其他键一样。 – 2014-09-11 15:05:15

回答

1

的答案取决于PostTypesName场的用法:

  • 如果该字段的所有使用的代码和/或你可能有非本地化的脚本来,本地化不必要
  • 如果Name使它到最终用户的视图,您应该本地化表。

如果您需要本地化PostTypes,单独PostTypesLocalized表,除了PostTypes表语言环境无关的名称,听起来像一个合适的解决方案。

您应该考虑放置PostTypeId字段。具有相同PostId的所有本地化是否参考相同的PostTypeId,或者它们中的一些会不同?如果同一Post的所有本地化参考相同的PostType,则该字段应该属于Posts表,而不是PostLocalized

我应该只在应用程序中本地化查找表吗?

向您的数据库添加本地化会算作您应用程序的本地化。当您考虑使用相同数据库结构的多个应用程序时,这是一个很好的解决方案。

+0

我刚刚更新了我的代码...我还有一个问题。你觉得我应该怎么做? – 2014-09-11 15:01:54

+0

@MDMoura由于同一帖子的所有本地化将具有相同的PostType,所以Post帖应该具有PostTypeId字段:create table dbo.Posts(Id int identity not null主键聚簇(Id),Created datetime not null,PostTypeId int not null)'。语言ID,文本和标题应该属于'PostLocalized',这是您在原始结构中的方式。您应该使用特定于语言的名称创建'PostTypeLocalized',引用'PostType'。 – dasblinkenlight 2014-09-11 15:17:55

+0

所以你说我不可能有相同的PostType关联到所有翻译,并且只使用一个Posts表格,因为我在Update中添加了? – 2014-09-11 15:58:23