Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. The Developer Center continues to support Commerce 6.13.0 through 7.4.1.Visit new site

Localizing Structured Messages

Localizing Structured Messages

The front-end developer is responsible for localizing and presenting structured messages to the user. The debug-message field is povided as a developer convenience and is not suitable for presentation to end users.

To localize a structured message:

  1. Use the message id and the user's locale to lookup a localized message template.
  2. Localize values in the data field if required.
  3. Substitute placeholders in the localized message template with the localized values from the data field.

Localization Example

Let's use the following message as an example of localization into English.

  {
    "type": "error",
    "id": "field.required",
    "debug-message": "given-name attribute is required",
    "data": {
      "field-name": "given-name"
    }
  }      
  1. Lookup a localized message template for id=field.required and locale=en. For example, the template might be:
      localized-template = "{field-name} is required"
  2. Localize the field-name data value of given-name to match what the field in called in the user interface (e.g. "First name")
      localized-field-name = "First name"
  3. Substitute the {field-name} placeholder with the localized data value.
      localized-message = "First name is required"