I am working for a client on a web app that requires localization in 3 languages (English and 2 others). I understand how to use resources in an ASP.NET application to display localized versions of static data. However, I am not sure how to approach the issue of localized user-entered data. For example, an administrator may want to add some new metadata the application (e.g. a new product category). This will eventually need to be translated into all 3 languages, but it will initially be entered in whatever language the administrator knows. Since this kind of data is not static, we store it in the database. Should we add a culture code to the primary key to differentiate different localized versions of the same data? Is there a "best practice" or pattern I'm not aware of for this kind of problem?
我在一个Web应用程序上为客户工作,该应用程序需要以3种语言进行本地化(英语和其他2种语言)。我了解如何在ASP.NET应用程序中使用资源来显示静态数据的本地化版本。但是,我不知道如何处理本地化用户输入数据的问题。例如,管理员可能想要在应用程序中添加一些新元数据(例如,新产品类别)。这最终需要翻译成所有3种语言,但最初将以管理员知道的任何语言输入。由于这种数据不是静态的,我们将其存储在数据库中。我们是否应该向主键添加区域性代码以区分相同数据的不同本地化版本?对于这类问题,我是否有“最佳实践”或模式?
3 个解决方案
#1
2
Have a child table your your entity, with a composite PK of MainItemID and LanguageCode (EN, DE, FR etc). This child table stores your language specific text.
使用MainItemID和LanguageCode(EN,DE,FR等)的复合PK,让您的实体拥有子表。此子表存储您的语言特定文本。
If you always have English, or it is a fallback then you could have the child table for DE, FR etc and the main table for English. A LEFT JOIN and ISNULL will take care of this.
如果你总是有英语,或者它是一个后备,那么你可以拥有DE,FR等的子表和英语的主表。 LEFT JOIN和ISNULL会处理这个问题。
Either way is OK depending on your exact needs which I suspect is the first one. Of course, you'd need to ensure you have at least one child row on data entry of, say, a new product category
无论哪种方式都可以,取决于您的确切需求,我怀疑是第一个。当然,您需要确保在数据输入中至少有一个子行,例如新产品类别
#2
1
I would suggest you make a table to track the Language
and then use the languageID as a foreign key in the other table instead of language code.
我建议你创建一个表来跟踪语言,然后使用languageID作为另一个表中的外键而不是语言代码。
Language(LanguageID, Name)
And then in the other tables use that LanguageID
as a foreign key.
然后在其他表中使用该Language作为外键。
e.g. you are storing localized text in the table
例如您将本地化的文本存储在表中
LocalizedTextTable(ID,text,LanguageID)
#3
0
My solution was to create a string column which holds encoded data for all supported languages. Special application logic is required to insert and extract the data. Specialized text editor supporting multi-lingual data helped a lot too.
我的解决方案是创建一个字符串列,其中包含所有支持语言的编码数据。插入和提取数据需要特殊的应用程序逻辑。支持多语言数据的专业文本编辑器也有很多帮助。
#1
2
Have a child table your your entity, with a composite PK of MainItemID and LanguageCode (EN, DE, FR etc). This child table stores your language specific text.
使用MainItemID和LanguageCode(EN,DE,FR等)的复合PK,让您的实体拥有子表。此子表存储您的语言特定文本。
If you always have English, or it is a fallback then you could have the child table for DE, FR etc and the main table for English. A LEFT JOIN and ISNULL will take care of this.
如果你总是有英语,或者它是一个后备,那么你可以拥有DE,FR等的子表和英语的主表。 LEFT JOIN和ISNULL会处理这个问题。
Either way is OK depending on your exact needs which I suspect is the first one. Of course, you'd need to ensure you have at least one child row on data entry of, say, a new product category
无论哪种方式都可以,取决于您的确切需求,我怀疑是第一个。当然,您需要确保在数据输入中至少有一个子行,例如新产品类别
#2
1
I would suggest you make a table to track the Language
and then use the languageID as a foreign key in the other table instead of language code.
我建议你创建一个表来跟踪语言,然后使用languageID作为另一个表中的外键而不是语言代码。
Language(LanguageID, Name)
And then in the other tables use that LanguageID
as a foreign key.
然后在其他表中使用该Language作为外键。
e.g. you are storing localized text in the table
例如您将本地化的文本存储在表中
LocalizedTextTable(ID,text,LanguageID)
#3
0
My solution was to create a string column which holds encoded data for all supported languages. Special application logic is required to insert and extract the data. Specialized text editor supporting multi-lingual data helped a lot too.
我的解决方案是创建一个字符串列,其中包含所有支持语言的编码数据。插入和提取数据需要特殊的应用程序逻辑。支持多语言数据的专业文本编辑器也有很多帮助。