I18nInterceptor
I18nInterceptor interceptor is an international component provided for web applications. The following is an example used in the freemarker template:
//First configure I18nInterceptor as a global interceptor
public void configInterceptor(Interceptors me) { me.add(new I18nInterceptor());
}
// Then you can get the internationalized data through the _res object in freemarker
${_res.get("msg")}
public void configInterceptor(Interceptors me) { me.add(new I18nInterceptor());
}
// Then you can get the internationalized data through the _res object in freemarker
${_res.get("msg")}
The above code is configured with I18nInterceptor to intercept the action request, and then the internationalized data can be obtained through the object named _res in the freemarker template file , The specific workflow of I18nInterceptor is as follows:
- l attempts to obtain the locale parameter from the request through controller.getPara("_locale"), If obtained, save it to cookie
- If controller.getPara("_locale") does not obtain the parameter value, try Obtain the locale parameter through controller.getCookie("_locale")
- If the locale parameter value is still not obtained in the above two steps, use the value of I18n.defaultLocale. Use the locale value
- ##Use the locale value obtained in the previous three steps, get the Res object through I18n.use(locale), and passcontroller.setAttr(“_res”, res) passes the Res object to the page for use
- If I18nInterceptor.isSwitchView is true, the view value of render will also be changed to implement the overall template file Switch, please view the source code for details.