Coder Social home page Coder Social logo

daileyet / openlibs.i18n Goto Github PK

View Code? Open in Web Editor NEW
3.0 2.0 0.0 449 KB

The lib of java internationalization, includes resource bundle and db implementation

Home Page: http://daileyet.github.io/openlibs.i18n

License: Apache License 2.0

Java 100.00%
java i18n i18n-tool

openlibs.i18n's Introduction

openlibs.i18n

The lib of java internationalization, includes resource bundle and db implementation.

###Get it by Maven

<dependency>
  <groupId>com.openthinks.libs</groupId>
  <artifactId>utilities</artifactId>
  <version>1.0</version>
</dependency>

@see http://daileyet.github.io/openlibs.i18n.

###Quick useage for the implementation java.util.ResourceBundle: #####1. Directly use pack name

//resource pack dir and pack name; 
//put your resource bundle file Log.properties 
//under your project path "openthinks/libs/i18n/resource/i18n/"
String BASE_PACK_DIR = "openthinks/libs/i18n/resource/i18n/";
String LOG_PACK_NAME = "Log";
//get internationalization message by the properties key in bundle properties file
//get default locale message
String message = I18n.getMessage(BASE_PACK_DIR + LOG_PACK_NAME, "1000");
//get special locale message
message = I18n.getMessage(BASE_PACK_DIR + LOG_PACK_NAME,Locale.UK, "1000");
#####2. Use customized IBundleMessageType
//define a customized message type, here is a enum;
//it also can be normal class just implement interface IBundleMessageType
public enum CustomizedMessageType implements IBundleMessageType{
	LOG, EXCEPTION, UI;
	@Override
	public String value() {
		return name() + ":" + BASE_PACK_DIR + name();
	}
	@Override
	public String getPackName() {
		//openthinks/libs/i18n/resource/i18n/LOG
		//openthinks/libs/i18n/resource/i18n/EXCEPTION
		//openthinks/libs/i18n/resource/i18n/UI
		return BASE_PACK_DIR + name();
	}
	@Override
	public String getMessageType() {
		return name();
	}
public static final String BASE_PACK_DIR = "openthinks/libs/i18n/resource/i18n/"; 

} //get default locale message String message = I18n.getMessage(CustomizedMessageType.LOG, "1000"); //get special locale message message = I18n.getMessage(CustomizedMessageType.LOG,Locale.UK, "1000");

### Locale change in application ###### Use class I18nApplicationLocale
//example for Swing UI, make it as Observer and regiester to I18nApplicationLocale
class UI extends JFrame implements Observer{
 		private JButton button;
 		private JLabel label;
	public UI(){
		//initialize component
		//register to I18nApplicationLocale
		I18nApplicationLocale.getInstance().addObserver(this);
	}
	
	// Overrides Observer
	public void update(Observable o, Object argument) {
		setLocaleMessage();
	}
	
	public void setLocaleMessage(){
		button.setText(I18n.getMessage(CustomizedMessageType.UI,"2000"));
		label.setText(I18n.getMessage(CustomizedMessageType.UI,"2001"));
	}

} // when the application locale changed, call the following statement I18nApplicationLocale.getInstance().changeCurrentLocale(Locale.UK);

openlibs.i18n's People

Contributors

daileyet avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.