你的位置:首页 > Java教程

[Java教程]spring international


1.beans.

<bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">    <property name="basenames">      <list>      <!-- 其中一个资源文件,如放在com.nyan包则写com.nyan.message -->
          <value>message</value>         </list> </property> </bean>

@src建立properties资源文件

hello,now是键名

value 的值跟properties的文件对应:<value>notice</value> --- >notice_en_US.properties>

hello=welcome,{0}now=now is,{0}

@命名格式:message_语言_国家

message_en_US.properties

message_zh_CN.properties

@applicationContext.getMessage("键名","参数","区域")

   public void messageTest(){    ClassPath= new ClassPath);    String [] a= {"读者"};    String hello = context.getMessage("hello", a, Locale.getDefault());    System.out.println("default.....");    Object [] b ={ new Date()};    String now = context.getMessage("now", b, Locale.getDefault());        hello = context.getMessage("hello", a, Locale.US);    now = context.getMessage("now", b, Locale.US);        hello = context.getMessage("hello", a, Locale.CHINESE);    now = context.getMessage("now", b, Locale.CHINESE);        context.close();  }