`

understant and use I18N

    博客分类:
  • java
 
阅读更多

首先介绍几个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"));

	}

}

 

通过上面这段代码我们就可以轻松的切换语言。

 

分享到:
评论

相关推荐

    Successful Lisp How to Understand and Use Common Lisp - David B. Lamkins

    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 ...

    成功的Lisp:如何理解和使用Common LispSuccessful Lisp: How to Understand and Use Common Lisp

    本书是为专业程序员而写的。 它采用动手方法引入了ANSI Common Lisp标准。

    Jenkins 2--Up and Running

    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

    Mastering Data Analysis with R(PACKT,2015)

    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 ...

    Cloud Native: Using Containers, Functions, and Data

    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 ...

    understand4+注册机

    《理解并掌握Understand 4+ 注册机:超越Source Insight的强大工具》 在软件开发领域,代码理解和分析工具是开发者的重要辅助。本文将详细探讨Understand 4.08.11版本,一个被赞誉为完爆Source Insight的跨平台神器...

    Understand代码阅读带注册码

    《深入理解代码阅读工具——Understand》 在软件开发领域,理解和分析代码是日常工作中不可或缺的部分,无论是维护现有的项目,还是学习新的代码库,都离不开有效的代码阅读工具。本文将聚焦于一款名为“Understand...

    Getting started with IntelliJ IDEA

    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, understand5.1.1029, linux

    《深入探索:Scitools Understand 5.1.1029 在 Linux 平台的应用》 Scitools Understand 是一款强大的源代码分析工具,它为开发者提供了对代码的全面理解,帮助他们进行代码审查、复杂性分析、依赖关系可视化等任务...

    PMI's Organizational Project Management Maturity Model (OPM3™)

    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...

    SharePoint 2013 User's Guide 4th Edition

    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 ...

Global site tag (gtag.js) - Google Analytics