23
23
public class I18N {
24
24
public static final char PREFIX = '@' ;
25
25
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
+
28
28
private static ResourceBundle i18nWorld ;
29
29
private static ResourceBundle i18nChapter ;
30
-
31
- public static void loadChapter (String i18nChapterFilename ) {
32
- Locale locale = Locale .getDefault ();
30
+ private static Locale locale = Locale .getDefault ();
33
31
32
+ public static void loadChapter (String i18nChapterFilename ) {
34
33
try {
35
- i18nChapter = ResourceBundle .getBundle (i18nChapterFilename , locale ,
36
- new I18NControl (ENCODING ));
34
+ i18nChapter = ResourceBundle .getBundle (i18nChapterFilename , locale , new I18NControl (ENCODING ));
37
35
} catch (Exception e ) {
38
36
EngineLogger .error ("ERROR LOADING BUNDLE: " + i18nChapter );
39
37
}
40
38
}
41
-
39
+
42
40
public static void loadWorld (String i18nWorldFilename ) {
43
- Locale locale = Locale .getDefault ();
44
-
45
41
try {
46
- i18nWorld = ResourceBundle .getBundle (i18nWorldFilename , locale ,
47
- new I18NControl (ENCODING ));
42
+ i18nWorld = ResourceBundle .getBundle (i18nWorldFilename , locale , new I18NControl (ENCODING ));
48
43
} catch (Exception e ) {
49
44
EngineLogger .error ("ERROR LOADING BUNDLE: " + i18nWorld );
50
45
}
51
46
}
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
+
53
61
public static String getString (String key ) {
54
62
try {
55
63
return i18nChapter .getString (key );
@@ -62,4 +70,8 @@ public static String getString(String key) {
62
70
}
63
71
}
64
72
}
73
+
74
+ public static Locale getCurrentLocale () {
75
+ return locale ;
76
+ }
65
77
}
0 commit comments