You can use resource bundles along with the {{format}} helper to display localized text in published content. This deployment requires a single template file, a resource bundle for each locale, and an optional data file.

At runtime, Brightspot displays localized text using the following logic:

  1. Extract the site from the received URL.
  2. Determine the site’s locale.
  3. Retrieve the template file for the requested item.
  4. Populate the template file’s helpers using the standard ViewModel logic. However, when processing {{format}} helpers:
    1. Look up the properties file for the site’s locale.
    2. Within the properties file, look up the string to evaluate and return.

The following snippets provide an example for localization with the {{format}} helper. All of the snippets in this example are in the same directory.

  "_template": "AuthorPage.hbs"

In the previous snippet, line 2 provides the name of the corresponding template file.

{{!-- File name AuthorPage.hbs --}}
    <h3 class="author-headline">{{format "aboutme"}}</h3>

In the previous snippet, line 3 performs a call to message formatter aboutme in a locale-specific properties file. The default properties file has a name AuthorPage.properties, and the localized properties file has a name AuthorPage_xx.properties.

  • The literal AuthorPage is mandatory because it must match the name of the template file.
  • The two letters before .properties must be a language code that Java recognizes. For a list of two-letter language codes, see Codes for the Representation of Names of Languages.
  • Example: AuthorPage_fr.properties
# File name AuthorPage.properties
aboutme=My Recent History

The previous snippet is in a file AuthorPage.properties. This is the default properties file for localization. If there is no locale associated with the site, or if there is no properties file for the site’s locale, Brightspot renders the output using this file.

# File name AuthorPage_fr.properties
aboutme=Mon Histoire Récente

The previous snippet is in a file AuthorPage_fr.properties. When Brightspot detects that the published site’s locale is French, it looks up the value for {{format "aboutme"}} in this file.

    <h3 class="author-headline">Mon Histoire Récente</h3>

The previous snippet shows the resulting HTML output for localized text from the {{format "aboutme"}} helper.

See also: