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
#####2. Use customized IBundleMessageType//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");
//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/";
### Locale change in application ###### Use class I18nApplicationLocale
} //get default locale message String message = I18n.getMessage(CustomizedMessageType.LOG, "1000"); //get special locale message message = I18n.getMessage(CustomizedMessageType.LOG,Locale.UK, "1000");
//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
Recommend Projects
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
TensorFlow
An Open Source Machine Learning Framework for Everyone
Django
The Web framework for perfectionists with deadlines.
Laravel
A PHP framework for web artisans
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.
Visualization
Some thing interesting about visualization, use data art
Game
Some thing interesting about game, make everyone happy.
Recommend Org
We are working to build community through open source technology. NB: members must have two-factor auth.
Microsoft
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba
Alibaba Open Source for everyone
D3
Data-Driven Documents codes.
Tencent
China tencent open source team.