MCPcopy Create free account
hub / github.com/5zig/The-5zig-Mod / I18n

Class I18n

The 5zig Mod/src/eu/the5zig/mod/I18n.java:25–386  ·  view source on GitHub ↗

Created by 5zig. All rights reserved © 2015

Source from the content-addressed store, hash-verified

23 * All rights reserved © 2015
24 */
25public class I18n {
26
27 private static final String PRE = "lang/" + Version.LANGVERSION + "/", MID = "language", END = ".properties";
28 private static final Locale[] defaultLocales = new Locale[]{Locale.US, Locale.GERMANY, new Locale("es", "ES"), new Locale("nl", "NL"), Locale.CHINA, new Locale("pt", "BR")};
29
30 private static List<Locale> languages = Lists.newArrayList();
31 private static Locale currentLanguage;
32 private static ResourceBundle resourceBundle;
33 private static ResourceBundle defaultBundle;
34
35 static {
36 The5zigMod.logger.info("Loading Language files...");
37
38 try {
39 defaultBundle = ResourceBundle.getBundle(PRE + MID, Locale.US);
40 } catch (Exception e) {
41 The5zigMod.logger.error("Could not load fallback resource bundle!", e);
42 }
43
44 try {
45 extractLocales();
46 loadLocales();
47 } catch (Exception e) {
48 The5zigMod.logger.error("Could not load extracted resource bundles!", e);
49 }
50
51 Collections.sort(languages, new Comparator<Locale>() {
52 @Override
53 public int compare(Locale l1, Locale l2) {
54 return l1.toString().compareTo(l2.toString());
55 }
56 });
57
58 currentLanguage = get(The5zigMod.getConfig().getString("language"));
59 if (currentLanguage == null) {
60 setLanguage(Locale.US);
61 } else {
62 try {
63 loadPropertyBundle();
64 } catch (Exception e) {
65 The5zigMod.logger.error("Could not load property bundle " + currentLanguage + "!", e);
66 }
67 }
68 The5zigMod.logger.info("Loaded {} languages! Using Language {}!", languages.size(), currentLanguage);
69
70 checkUpdates();
71 }
72
73 private static Locale get(String code) {
74 for (Locale language : languages) {
75 if (language.toString().equals(code))
76 return language;
77 }
78 return null;
79 }
80
81 private static void loadResourceBundle() {
82 The5zigMod.logger.debug("Reloading Resource Bundle {}...", currentLanguage);

Callers

nothing calls this directly

Calls 12

extractLocalesMethod · 0.95
loadLocalesMethod · 0.95
getMethod · 0.95
getConfigMethod · 0.95
setLanguageMethod · 0.95
loadPropertyBundleMethod · 0.95
checkUpdatesMethod · 0.95
getBundleMethod · 0.80
sizeMethod · 0.80
errorMethod · 0.45
sortMethod · 0.45
getStringMethod · 0.45

Tested by

no test coverage detected