首先介绍几个api:
1、Locale:对象表示了特定的地理、政治和文化地区
其有三种创建方式: Locale(String language)
Locale(String language, String country)
Locale(String language, String country, String variant)
2、ResourceBundle:资源包包含特定于语言环境的对象
通过这两个对象可以实现国际化,下面我们来看一段代码:
1、定义一个message.properties文件:
com.name=cainwise
2、定义message_zh_CN.properties文件:
com.name=cainwise zhong wen
3、定义message_en_US.properties文件:
com.name=cainwise english
这三个都放在src目录下, 好了接下来我们来写段测试代码:
package com.I18n;
import java.util.Locale;
import java.util.ResourceBundle;
public class TestI18n {
public static void main(String[] args) {
Locale lo = new Locale(Locale.ENGLISH.getLanguage(), Locale.US
.getCountry());
Locale lou = new Locale(Locale.CHINESE.getLanguage(), Locale.CHINA
.getCountry());
ResourceBundle rs = ResourceBundle.getBundle("message", lou);
System.out.println(rs.getObject("com.name"));
}
}
通过上面这段代码我们就可以轻松的切换语言。
分享到:
相关推荐
Describes format, typical use, and possible drawbacks of all important Lisp constructs. Provides practical advice for the construction of Common Lisp programs. Shows examples of how Common Lisp is ...
本书是为专业程序员而写的。 它采用动手方法引入了ANSI Common Lisp标准。
what are milkruns? Building Milkruns. The Impact of Variability.
Understand and use the new Blue Ocean graphical interface Take advantage of the capabilities of the underlying OS in your pipeline Integrate analysis tools, artifact management, and containers
MIT科研团队在2020年isscc上有关深度学习处理器的教程,包含视频和文档资料,欢迎下载学习
Understand and use the new Blue Ocean graphical interface Take advantage of the capabilities of the underlying OS in your pipeline Integrate analysis tools, artifact management, and containers
Bridging the gap between theory and practice, this book will help you to understand and use data for a competitive advantage. Beginning with taking you through essential data mining and management ...
This comprehensive guide helps developers and architects understand current cloud-native technologies, with recommendations that explain when you need to use each one. Authors Boris Scholl, Trent ...
Understand and use the intentions and smart code completion features Create web services using the IntelliJ tools Install and use third party plugins Approach A practical, fast-paced guide with clear...
OPM3 is designed to be easy to understand and use, as well as to be scalable, flexible, and customizable, in order to accommodate the wide range of individual needs and objectives of organizations of...
That said, in many situations where SharePoint is introduced, people struggle to understand and use the platform. In other situations people have difficulty expanding their use of SharePoint from a ...