Internationalization and localization in delite

Locale

Delite supports a locale setting for the page. This affects the language of boilerplate text in widgets as well as localizations such as how numbers and dates are displayed. The setting is based on the browser's locale, and affects all widgets on the page.

Note that the HTML lang attribute set on individual elements is ignored. This is because widgets load messages via the i18n! plugin, which uses the locale of the page.

RTL and BIDI support

Delite and dependent projects like deliteful can render widgets in either LTR or RTL. Support for RTL encompasses features like:

has("bidi") flag

If an application will (or may be) run in RTL locales, it should define the has("bidi") flag as follows:

requirejs.config({
    ...
    config: {
        ...
        "requirejs-dplugins/has": {
            bidi: true
        }
    }
});

The has("bidi") flag enables advanced bidi features such as the textdir property. In addition, for some widgets, has("bidi") is necessary to turn on basic RTL features such as correct keyboard handling and proper GUI layout.

has("inherited-dir") flag

If an application will (or may be) run in RTL locales, it in addition can define the has("inherited-dir") flag as follows:

requirejs.config({
    ...
    config: {
        ...
        "requirejs-dplugins/has": {
            bidi: true,
            inherited-dir: true
        }
    }
});

The has("inherited-dir") flag allows a widget to inherit the initial direction from any ancestor node, rather than just <html> or <body>.

Textdir property

The textdir property is useful in two cases:

  1. When the application boilerplate text is LTR, but the user data contained by the application is RTL (or vice-versa). The typical case is that the application boilerplate text is in English, because it hasn't been translated, but the user data displayed by the application is in an RTL language like Hebrew or Arabic.
  2. When the user data (that widgets display) is bidirectional text, for example a sentence in Hebrew that contains words in English.

In either case, textdir declares the "natural text direction", i.e. whether the text should be written right-to-left or left-to-right. For example, in the text "Hello אר!", "Hello" should appear on the left, but in the text "!Bob שלום", the Hebrew word for "hello" appears on the right.

The allowed values are:

  1. "ltr"
  2. "rtl"
  3. "auto" - contextual - the direction of a text defined by first strong letter (see http://en.wikipedia.org/wiki/Bi-directional_text for an explanation of strong characters vs. weak characters)

Note that the textdir property must be set directly on each widget. Unlike dir, textdir will not be inherited from a setting on <html> or <body>.

Limitations of RTL support

For reasons of performance and practicality, delite has certain restrictions on its RTL and bidi support.

Delite's API is currently optimized to support the following cases:

  1. application GUI layout and user data is LTR text
  2. application GUI layout and user data is RTL text

In either case, delite will do the right thing simply by setting <body dir=ltr> or <body dir=rtl>.

Delite also has limited support for displaying part of the page in RTL but other parts in LTR, by directly setting the dir and textdir properties of individual widgets.

In any case, the application should obey the following rules:

Breaking any of these rules will lead to undefined behavior. Often it will lead to widgets being in a half-way state where, for example, the layout becomes RTL but the keyboard support is still in LTR mode.

Writing widgets

Ibm-js provides two modules that can be used to build widgets with internationalization support:

Please see those respective pages for details.