Globalization architecture

I need to store products for an e-commerce solution in a database. Each product must have descriptive information such as name, description, etc.

I need a product to be localized by x number of languages.

What I have done so far is to make any column that needs to be localized, and nvarchar(MAX)then I store the XML string as follows:

<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 in Dictionary<string, string>, where the key is the culture / language code.

So when I want to display the product name, I do this:

lblName.Text = product.Name["en-us"];

Does anyone have a better solution?

+3
source share
4 answers

- (, singleton), product.Name . , , , .

, singleton 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;
    }
  }
+2

- Rob Conery MVC Storefront ( 5:30). , Product ProductCultureDetail .

+1

+1

, Microsoft Commerce Server 2002. , .

0

Source: https://habr.com/ru/post/1696543/


All Articles