全球化架构
我需要在数据库中存储电子商务解决方案的产品。 每个产品都应该有描述性信息,例如名称、描述等。
我需要将任何产品本地化为 x 种语言。
到目前为止,我所做的就是创建任何应该本地化的列和 nvarchar(MAX)
,然后我存储这样的 XML 字符串:
<cultures>
<culture code="en-us">Super fast laptop</culture>
<culture code="da-dk">Super hurtig bærbar</culture>
</cultures>
当我从数据库加载它时,将其加载到我的业务逻辑对象时,我将 XML 字符串解析为 Dictionary
,其中键是文化/语言代码。
因此,当我想显示产品名称时,我会这样做:
lblName.Text = product.Name["en-us"];
有人有更好的解决方案吗?
I need to store products for an e-commerce solution in a database. Each product should have descriptive information, such as name, description etc.
I need any product to be localized to x number of languages.
What I've done so far, is to make any column that should be localized and nvarchar(MAX)
and then i store an XML string like this:
<cultures>
<culture code="en-us">Super fast laptop</culture>
<culture code="da-dk">Super hurtig bærbar</culture>
</cultures>
And when I load it from the database, into my business logic objects, I parse the XML string to a Dictionary<string, string>
where the key is the culture/language code.
So when I want to display the name of a product, I do this:
lblName.Text = product.Name["en-us"];
Does anyone have a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您应该将当前语言存储在某个地方(例如,在 singleton 中)并且在product.Name 属性中使用语言设置来获取正确的字符串。 这样,您只需为每个字段编写一次特定于语言的代码,而不必考虑使用该字段的每个地方的语言。
例如,假设您的单例是在 Localizer 类中定义的,该类存储与当前语言对应的枚举:
其中 GetLocalString 看起来像:
You should store the current language somewhere (in a singleton, for instance) and in the product.Name property use the language setting to get the correct string. This way you only have to write the language specific code once for each field rather than thinking about languages everywhere the field is used.
For example, assuming your singleton is defined in the Localizer class that stores an enum corresponding to the current language:
Where GetLocalString looks something like:
Rob Conery 的 MVC Storefront 网络广播系列有有关此问题的视频(他在 5:30 左右到达数据库)。 他存储文化列表,然后有一个用于非本地化数据的 Product 表和一个用于本地化文本的 ProductCultureDetail 表。
Rob Conery's MVC Storefront webcast series has a video on this issue (he gets to the database around 5:30). He stores a list of cultures, and then has a Product table for non-localized data and a ProductCultureDetail table for localized text.
资源文件
resource files
这基本上就是我们在 Microsoft Commerce Server 2002 中采用的方法。是的,索引视图将提高您的性能。
This is basically the approach we took with Microsoft Commerce Server 2002. Yeah indexed views will help your performance.