JeeSite 4.x Internationalization (i18n), Multilingualism, Localization

Keywords: encoding Java Session Mobile

1. When login is supported, specify the language, or switch the language after login (param_lang=en)

2. Support Cookie Storage Language Settings, Use Session Storage without Cookie, Support Mobile

3. Support property files and databases to store translations and facilitate the management of translated data.

4. Translatable: Fixed data (e.g. page title, label, message prompt), dynamic data (e.g. menu data, dictionary data, etc.)

5. Chinese free zh_CN translation, such as: text('Hello'), can not find the corresponding key directly output the original "Hello"

6. Support kay and translation parameters, such as text('Today's Day {0}, 3), output "Today's Day 3"

Language file

Backend language file

Fixed Data Language

Text translations that do not change, such as a prompt, field label, list title, button text, etc., need to be put in properties.

File directory structure, supporting modular categorization language file structure, as follows:

/ src/main/resources/messages/module encoding/i18n_language encoding.

For example: msg module en translation configuration:

/src/main/resources/messages/msg/i18n_en.properties

Document content:

  • File content is stored in key=value mode, such as: Hello = Hello
  • If the Key contains spaces, you can use the "escape, such as Ti intersection = Submit
  • Parametric translations, such as today's {0} day. = Today is the {0} day.

Maintain the newly added language in the system dictionary: sys_lang_type, which is coded as language coding;

Dynamic Data Language

Business or administrator can modify or configure some text translation through database, such as menu name, dictionary name, dictionary value, etc.

These can be logged in through the system account, enter the menu "System Management - > System Settings - > Internationalization Management" to add translations.

Front-end language file

Expand language files according to requirements, such as:

<script src="${ctxStatic}/modules/i18n/i18n_${lang()}.js" ></script>

Examples are as follows:

window.jeesiteMessage = $.extend({}, window.jeesiteMessage, {
    'Hello' : 'Hello',
    'Today's first {0} day' : ' Today is the {0} day.'
});

Language Call Method

Java

1. Get the language name: Global.getLang()

Return: en, zh_CN

2. Obtain the translation of language coding: Global.getText(code)

For example: Global.getText("Hello")

3. Obtain the translation of language coding and support parameters: Global.getText(code, params...)

For example: Global.getText("Today's {0} Day", 3)

4. In the class that integrates BaseController and BaseService, it can be directly passed through

For example: text(code) or text(code, params...)

Beetl view

1. Get the language name: ${lang()}

Return: en, zh_CN

2. Obtain the translation of language coding: ${text(code)}

For example: ${text("Hello")}

3. Obtain the translation of language coding and support parameters: ${text(code, params...)}

For example: ${text("today's {0} day, 3)}

JavaScript

1. Get the language name: window.lang | |'zh_CN'

Return: en, zh_CN

2. Acquiring Language Coding Translation: text(code)

For example: text("Hello")

3. Obtain the translation of language coding and support parameters: text(code, params...)

For example: text("today's {0} day", 3)

Common Language Coding

java.util.Locale :

public static final Locale ENGLISH = createConstant("en", "");
public static final Locale FRENCH = createConstant("fr", "");
public static final Locale GERMAN = createConstant("de", "");
public static final Locale ITALIAN = createConstant("it", "");
public static final Locale JAPANESE = createConstant("ja", "");
public static final Locale KOREAN = createConstant("ko", "");
public static final Locale CHINESE = createConstant("zh", "");
public static final Locale SIMPLIFIED_CHINESE = createConstant("zh", "CN");
public static final Locale TRADITIONAL_CHINESE = createConstant("zh", "TW");
public static final Locale FRANCE = createConstant("fr", "FR");
public static final Locale GERMANY = createConstant("de", "DE");
public static final Locale ITALY = createConstant("it", "IT");
public static final Locale JAPAN = createConstant("ja", "JP");
public static final Locale KOREA = createConstant("ko", "KR");
public static final Locale CHINA = SIMPLIFIED_CHINESE;
public static final Locale PRC = SIMPLIFIED_CHINESE;
public static final Locale TAIWAN = TRADITIONAL_CHINESE;
public static final Locale UK = createConstant("en", "GB");
public static final Locale US = createConstant("en", "US");
public static final Locale CANADA = createConstant("en", "CA");
public static final Locale CANADA_FRENCH = createConstant("fr", "CA");

Language code table: http://www.lingoes.cn/zh/translator/langcode.htm

Posted by nephish on Thu, 09 May 2019 17:34:38 -0700