Skip to content

Commit 40c8391

Browse files
committed
I18N language runtime change support.
1 parent 83e0dc5 commit 40c8391

File tree

1 file changed

+25
-13
lines changed
  • blade-engine/src/com/bladecoder/engine/i18n

1 file changed

+25
-13
lines changed

blade-engine/src/com/bladecoder/engine/i18n/I18N.java

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,33 +23,41 @@
2323
public class I18N {
2424
public static final char PREFIX = '@';
2525
public static final String ENCODING = "UTF-8";
26-
// public static final String ENCODING = "ISO-8859-1";
27-
26+
// public static final String ENCODING = "ISO-8859-1";
27+
2828
private static ResourceBundle i18nWorld;
2929
private static ResourceBundle i18nChapter;
30-
31-
public static void loadChapter(String i18nChapterFilename) {
32-
Locale locale = Locale.getDefault();
30+
private static Locale locale = Locale.getDefault();
3331

32+
public static void loadChapter(String i18nChapterFilename) {
3433
try {
35-
i18nChapter = ResourceBundle.getBundle(i18nChapterFilename, locale,
36-
new I18NControl(ENCODING));
34+
i18nChapter = ResourceBundle.getBundle(i18nChapterFilename, locale, new I18NControl(ENCODING));
3735
} catch (Exception e) {
3836
EngineLogger.error("ERROR LOADING BUNDLE: " + i18nChapter);
3937
}
4038
}
41-
39+
4240
public static void loadWorld(String i18nWorldFilename) {
43-
Locale locale = Locale.getDefault();
44-
4541
try {
46-
i18nWorld = ResourceBundle.getBundle(i18nWorldFilename, locale,
47-
new I18NControl(ENCODING));
42+
i18nWorld = ResourceBundle.getBundle(i18nWorldFilename, locale, new I18NControl(ENCODING));
4843
} catch (Exception e) {
4944
EngineLogger.error("ERROR LOADING BUNDLE: " + i18nWorld);
5045
}
5146
}
52-
47+
48+
public static void setLocale(Locale l) {
49+
locale = l;
50+
51+
// RELOAD TRANSLATIONS
52+
if (i18nWorld != null) {
53+
loadWorld(i18nWorld.getBaseBundleName());
54+
}
55+
56+
if (i18nChapter != null) {
57+
loadChapter(i18nChapter.getBaseBundleName());
58+
}
59+
}
60+
5361
public static String getString(String key) {
5462
try {
5563
return i18nChapter.getString(key);
@@ -62,4 +70,8 @@ public static String getString(String key) {
6270
}
6371
}
6472
}
73+
74+
public static Locale getCurrentLocale() {
75+
return locale;
76+
}
6577
}

0 commit comments

Comments
 (0)