目录

Multi-Language Capability

Applications designed based on the JS UI framework apply to different countries and regions. With the multi-language capability, you do not need to develop application versions in different languages, and your users can switch between various locales. This also facilitates project maintenance.

You only need to perform operations in Defining Resource Files and Referencing Resources to use the multi-language capability of this framework.

Defining Resource Files

Resource files store application content in multiple languages. This framework uses JSON files to store resource definitions.

Place the resource file of each locale in the i18n directory described in File Organization. Resource files are named in language-region.json format. For example, the resource file for English (United States) is named en-US.json. If there is no resource file of the locale that matches the system language, content in the en-US.json file will be used by default.

Different languages have different matching rules for singular and plural forms. In the resource file, zero, one, two, few, many, and other are used to define the string content in different singular and plural forms. For example, there is only the other scenario in Chinese since the language does not have singular and plural forms. One and other scenarios are applicable to English. All the preceding six scenarios are needed for Arabic.

The following example takes en-US.json and ar-AE.json as examples:

{
    "strings": {
        "hello": "Hello world!",
        "symbol": "@#$%^&*()_+-={}[]\\|:;\"'<>,./?",
        "plurals": {
            "one": "one person",
            "other": "other people"
        }
    },

    "files": {
        "image": "image/en_picture.PNG"
    }
}
{
    "strings": {
        "plurals": {
            "zero": "لا أحد",
            "one": "وحده",
            "two": "اثنان",
            "few": "ستة اشخاص",
            "many": "خمسون شخص",
            "other": "مائة شخص"
        }
    }
}

Referencing Resources

Multi-language syntax used on application development pages (including simple formatting and singular-plural formatting) can be used in .hml or .js files.