Internationalization (I18N)


The I18N service is initialized when the YMP framework starts. It performs language configuration according to ymp.i18n_default_locale and adopts the language setting of the system operating environment by default;

  • International resource management The main methods provided by the server:

    • Get the current language setting

      I18N.current();
    • Set the current language

      // 变更当前语言设置且不触发事件
      I18N.current(Locale.ENGLISH);
      
      或者
      
      // 将触发监听处理器onChanged事件
      I18N.change(Locale.ENGLISH);
    • According to the current language settings, load the specified attribute value in the resource file with the specified name

      I18N.load("resources", "home_title");
      
      或者
      
      I18N.load("resources", "home_title", "首页");
    • Format message string and bind parameters

      // 加载指定名称资源文件内指定的属性并使用格式化参数绑定
      I18N.formatMessage("resources", "site_title", "Welcome {0}, {1}","YMP",“GoodLuck!”);
      
      // 使用格式化参数绑定
      I18N.formatMessage("Hello, {0}, {1}", "YMP",“GoodLuck!”);
  • The international resource manager event listening processor implements the II18NEventHandler interface and sets it in the i18n_event_handler_class parameter in the YMP configuration file. The listener can complete the following operations:

    • Customized resource file loading process
    • Customized acquisition of current language settings
    • Event processing process of language setting changes