国际化支持

This commit is contained in:
heavyrain.lee
2020-02-25 15:49:43 +08:00
parent 54ce0d5b51
commit de064aa582
5 changed files with 21 additions and 7 deletions
@@ -0,0 +1,2 @@
Above_Greeting_Message=This's the greeting
Friend_Can_Start_Chat=You're already friend, start chat now.
+2 -2
View File
@@ -1,2 +1,2 @@
greeting=This's the greeting
name=You're already friend, start chat now.
Above_Greeting_Message=This's the greeting
Friend_Can_Start_Chat=You're already friend, start chat now.
@@ -0,0 +1,2 @@
Above_Greeting_Message=\u4ee5\u4e0a\u662f\u6253\u62db\u547c\u4fe1\u606f
Friend_Can_Start_Chat=\u4f60\u4eec\u5df2\u7ecf\u6210\u4e3a\u597d\u53cb\u4e86\uff0c\u73b0\u5728\u53ef\u4ee5\u5f00\u59cb\u804a\u5929\u4e86
+10 -5
View File
@@ -37,21 +37,26 @@ public class I18n {
bundleMap.put(language, bundle);
}
return bundle.getString(key);
try {
return bundle.getString(key);
} catch (Exception e) {
e.printStackTrace();
}
return "糟糕,字符串 " + key + " 没有找到";
}
public static void test() throws MalformedURLException {
// 设置定制的语言国家代码
Locale locale1 = new Locale("zh_CN");
Locale locale2 = new Locale("en_US");
Locale locale1 = new Locale("zh");
Locale locale2 = new Locale("en");
ResourceBundle rb = ResourceBundle.getBundle("messages", locale1, Loader);
// 获得相应的key值
String greeting = rb.getString("greeting");
String userInfo = rb.getString("test");
String greeting = rb.getString("Above_Greeting_Message");
String userInfo = rb.getString("Friend_Can_Start_Chat");
System.out.println(greeting);
System.out.println(userInfo);
@@ -19,6 +19,11 @@
<directory>../broker/migrate/h2/</directory>
<outputDirectory>/migrate/h2</outputDirectory>
</fileSet>
<fileSet>
<directory>../broker/config/i18n/</directory>
<outputDirectory>/config/i18n</outputDirectory>
</fileSet>
</fileSets>
<files>