easy-i18n provides a simple i18n integration for Java project. It is just a copy of Spring Message from spring-context.
See ResourceBundleMessageSourceTest
A simple usage:
Maven for instance.
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
For the latest release code:
<dependency>
<groupId>com.github.Ryan-Miao</groupId>
<artifactId>easy-i18n</artifactId>
<version>1.0</version>
</dependency>
For the latest code:
<dependency>
<groupId>com.github.Ryan-Miao</groupId>
<artifactId>easy-i18n</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
接下来就可以愉快的玩耍了。
private final ResourceBundleMessageSource messageSource = new ResourceBundleMessageSource();
messageSource.setBasenames("message", "another");
messageSource.setDefaultEncoding("UTF-8");
messageSource.setFallbackToSystemLocale(false);
String english = messageSource.getMessage(USER_NAME, null, Locale.US);
String chinese = messageSource.getMessage(USER_NAME, null, Locale.SIMPLIFIED_CHINESE);
Assert.assertEquals("username-us", english);
Assert.assertEquals("用户名", chinese);