首先介绍几个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标准。
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 4+ 注册机:超越Source Insight的强大工具》 在软件开发领域,代码理解和分析工具是开发者的重要辅助。本文将详细探讨Understand 4.08.11版本,一个被赞誉为完爆Source Insight的跨平台神器...
《深入理解代码阅读工具——Understand》 在软件开发领域,理解和分析代码是日常工作中不可或缺的部分,无论是维护现有的项目,还是学习新的代码库,都离不开有效的代码阅读工具。本文将聚焦于一款名为“Understand...
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...
《深入探索:Scitools Understand 5.1.1029 在 Linux 平台的应用》 Scitools Understand 是一款强大的源代码分析工具,它为开发者提供了对代码的全面理解,帮助他们进行代码审查、复杂性分析、依赖关系可视化等任务...
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 ...