spring国际化支持

       Spring对国际化的支持是beanFactory的子接口ApplicationContext所增加的新功能,主要是因为ApplicationContext接口继承了MessageSource接口,MessageSource接口的getMessage(String code,Object[] obj,Locale locale)方法用于对国际化的支持。

      在Spring对国际化的支持中我们需要在应用上下文中配置:

    <bean  id="messageSource" class="org.springframework.context.support.RegourceBundleMessageSource">

          <property name="basenames">

                  <list>

                           <value>message</value>//表示我们资源文件的basename为message,资源文件的默认路径是在src路径下,  如果我们想把资源文件放在test下,那么<value>test/message</value>

                   </list>

        </property>

    </bean>

       建立资源文件message_zh_CN.properties     hello=你好{0}

                           message_en_US.properties      hello=hello{0}


     我们就可以通过ApplicationContext ac=new ClassPathXmlApplicationContext(.....);

                  String hello=ac.getMessage("hello",new String[]{"hi"},Locale.getDefault(Category.FORMAT));

           就可以获取该语言环境下的hello的值



           

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值