全球化架构

发布于 2024-07-05 18:21:39 字数 588 浏览 7 评论 0原文

我需要在数据库中存储电子商务解决方案的产品。 每个产品都应该有描述性信息,例如名称、描述等。

我需要将任何产品本地化为 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

美羊羊 2024-07-12 18:21:39

您应该将当前语言存储在某个地方(例如,在 singleton 中)并且在product.Name 属性中使用语言设置来获取正确的字符串。 这样,您只需为每个字段编写一次特定于语言的代码,而不必考虑使用该字段的每个地方的语言。

例如,假设您的单例是在 Localizer 类中定义的,该类存储与当前语言对应的枚举:

public class Product
{
  private idType id;
  public string Name
  {
    get
    {
      return Localizer.Instance.GetLocalString(id, "Name");
    }
  }
}

其中 GetLocalString 看起来像:

  public string GetLocalString(idType objectId, string fieldName)
  {
    switch (_currentLanguage)
    {
      case Language.English:
        // db access code to retrieve your string, may need to include the table
        // the object is in (e.g. "Products" "Orders" etc.)
        db.GetValue(objectId, fieldName, "en-us");
        break;
    }
  }

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:

public class Product
{
  private idType id;
  public string Name
  {
    get
    {
      return Localizer.Instance.GetLocalString(id, "Name");
    }
  }
}

Where GetLocalString looks something like:

  public string GetLocalString(idType objectId, string fieldName)
  {
    switch (_currentLanguage)
    {
      case Language.English:
        // db access code to retrieve your string, may need to include the table
        // the object is in (e.g. "Products" "Orders" etc.)
        db.GetValue(objectId, fieldName, "en-us");
        break;
    }
  }
你不是我要的菜∠ 2024-07-12 18:21:39

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.

中二柚 2024-07-12 18:21:39

资源文件

resource files

执手闯天涯 2024-07-12 18:21:39

这基本上就是我们在 Microsoft Commerce Server 2002 中采用的方法。是的,索引视图将提高您的性能。

This is basically the approach we took with Microsoft Commerce Server 2002. Yeah indexed views will help your performance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文