struts2的国际化 i18n 使用简介

作者 做棵大树 日期 2018-05-06
struts2的国际化 i18n 使用简介

struts2的国际化 i18n

  1. struts.xml配置文件中使用资源文件
  2. src目录下建立资源文件,文件名与中value的值相同

messsage.properties默认语言环境下使用的资源文件

messsage_en_EN.properties en:语言 EN:国家(可省略),特定的环境下使用的资源文件

messsage_zh_CN.properties zh:语言 CN:国家(可省略),特定的环境下使用的资源文件

  1. package_xx_XX.properties
  2. XxxAction_xx_XX.properties

设置本地语言

访问Action之前,会被i18n拦截器拦截,读取request_locale参数,如果没有,使用默认的,如果有,则将其作为默认locale对象设置到ActionContext中,并且保存到session中