arrow-down
    1. Widgets
  1. IAM
    1. Virtual apps
    1. Projects
    2. Layers
        1. AttachmentUploader
        2. Checkbox
        3. Combobox
        4. ContentSelector
        5. ContentTypeFilter
        6. CustomSelector
        7. Date
        8. DateTime
        9. Double
        10. GeoPoint
        11. HtmlArea
        12. ImageSelector
        13. Long
        14. MediaSelector
        15. Radiobutton
        16. Tag
        17. TextArea
        18. TextLine
        19. Time
      1. Field set
      2. Item set
      3. Option set
      4. Mixins
      5. Localization
    3. Content Types
    4. X-data
    5. Macros
    6. Custom styles
    7. Sites
      1. Regions
      2. Part component
      3. Layout component
      4. Text component
      5. Fragments
      6. Filtering
      7. Component indexing
      8. Visual editor
    8. Page templates
    1. Sandboxes
    2. Code
    3. Building
    4. Configuration
    1. Globals
    2. HTTP
    3. Controllers
    4. Filters
    5. Events
    6. Websocket
    7. Error handler
    8. ID provider
    9. Tasks
    10. Localization
    11. Mappings
    12. Components
    13. Processors
    14. Contributions
    15. Templating
    16. Main controller
    17. Java bridge
      1. Webapp Engine
        1. Image service
        2. Component service
      2. Admin Engine
      3. Asset service
      4. HTTP service
      5. IDprovider service
    1. Task engine
    2. Management Endpoint
    3. Statistics Endpoint
    1. Nodes and repos
    2. Properties
    3. Indexing
    4. Branches
    5. Queries (NoQL)
    6. Queries (DSL)
    7. Filters
    8. Aggregations
    9. Highlighting
    10. Editors
    1. Strategies
    2. Distributions
    3. Docker image
    4. Vhosts
    5. Configuration
    6. Backup & restore
    7. Systemd
    8. Clustering
    1. Admin API
    2. Application API
    3. Auditlog API
    4. Authentication API
    5. Cluster API
    6. Common API
    7. Content API
    8. Context API
    9. Event API
    10. Export API
    11. Grid API
    12. I18N API
    13. IO API
    14. Mail API
    15. Node API
    16. Portal API
    17. Project API
    18. Repo API
    19. Scheduler API
    20. Schema API
    21. Tasks API
    22. Value API
    23. VHost API
    24. Websocket API
  2. Audit Logs
    1. Upgrade Notes
    2. Upgrading Apps

Localization

Contents

Localizing your projects

Use cases

This section applies to code level localization, not multi-lingual content and websites.

Any project targeting users with different languages, you may want to localize the interface.

The XP framework provides localization for the following use-cases:

CMS/Sites

Use the the localization API to dynamically localize any text phrases in your app. The framework will attempt to apply the locale specified in the site’s language property.

Admin Console

Localise labels and texts in schemas such as content types. The framework will attempt to use the locale derived from the browser’s "accept-language" settings.

Webapps and more

The the localization API may also be used for any other purpose. In these cases, the developer must control and explicitly specify locale.

Localization files

The localization files are plain text files, using the properties format (key = value). The files must be placed in a specific project folder: /src/main/resources/i18n/.

Imagine, making an app that should support the following localizations.

  • 'English' (en)

  • 'English US' (en-US)

  • 'New Norwegian' (nn)

  • 'New Norwegian Norway' (nn-NO)

Each locale then needs to have a matching localization file, in the format:

phrases[_LOCALE].properties
The API’s country codes use - as separator but the files use _.
Sample localization bundle
i18n/phrases.properties
i18n/phrases_en_US.properties
i18n/phrases_no.properties

This format and packaging is commonly known as "property bundles".

The filenames are case sensitive!

Locale format

A locale is composed of two-letter codes for language, country and variant. Language is required, country and variant are optional.

For the property files, all codes are case sensitive and separated by and underscore (_).

The string-representation of a locale is

la[_CO][_VA]

where

  • la= two letter language code as specified by ISO-639

  • CO = optional two-letter country code as specified by ISO-3166

  • VA = two letter rarely used variant-code.

A sample locale including vendor specific variant:

es_ES_Traditional_WIN"..
Variants are rarely used in XP, and can pretty much be discarded.

Best match resolving

Based on the requested locale to be used, the framework applies the best matching pattern to find the optimal localization file.

If the requested locale is "en-US", the XP framework will look for localization files in the following order:

  • phrases_en_US.properties

  • phrases_en.properties

  • phrases.properties

As such, if the locale for a request was en, the phrases_en.properties file would be used.

If the locale does not match any specific file, the default phrases.properties will be used as fallback.

If no matching localization key is found in any of the files in a bundle, a default NOT_TRANSLATED will be displayed.

Encoding and special characters

Property keys

Must be in the ISO-8859-1 range, also known as Latin-1 characters. Non-Latin-1 characters use Unicode escape characters, e.g \u00E6 for the Norwegian letter 'æ'.

Property values

Supports any unicode characters

We always recommend saving property files using the UTF charset.

Sample

Below is an example of what a property file might look like

phrases.properties
user.greeting = Hello there!
message = Good to see you. How are you doing?
with_\u00e6_\u00f8_\u00e5 = This key contains norwegian characters æ, ø and å

Placeholders

The properties format also supports parameter values that can be merged into the localized strings. Below is an example of what this might look like:

phrases.properties
user.greeting = Hello, {0}!
message_url = http://localhost:8080/{0}
message_multi_placeholder = My name is {0} and I live in {1}
message_placeholder = Hello, my name is {0}.

Placeholders are marked with {<number>}. The given number corresponds with the function argument named values and the position of the parameter.

See documentation for MessageFormat for advanced use of placeholders.

XP XP 7.8.0 7.8.0 Placeholders get formatted according to requested locale

Contents

Contents

AI-powered search

Juke AI