Added options for localization

This commit is contained in:
huangyuhui
2016-02-01 15:11:03 +08:00
parent 05382a0354
commit ac7f025952
25 changed files with 563 additions and 424 deletions

View File

@@ -30,20 +30,6 @@ public final class C {
public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create();
public static final ResourceBundle I18N;
static {
ResourceBundle rb = null;
try {
rb = ResourceBundle.getBundle("org/jackhuang/hellominecraft/launcher/I18N");
} catch (Throwable t) {
rb = null;
System.out.println("Did you delete I18N.properties?");
t.printStackTrace();
}
I18N = rb;
}
//http://repo1.maven.org/maven2
public static final String URL_PUBLISH = "http://www.mcbbs.net/thread-142335-1-1.html";
public static final String URL_TIEBA = "http://tieba.baidu.com/f?kw=hellominecraftlauncher";
@@ -61,12 +47,7 @@ public final class C {
}
public static String i18n(String a, Object... format) {
try {
return String.format(C.I18N.getString(a), format);
} catch (Exception e) {
HMCLog.warn("Failed to read localization key: " + a, e);
return a;
}
return SupportedLocales.NOW_LOCALE.translate(a, format);
}
}

View File

@@ -0,0 +1,64 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2013 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hellominecraft.util;
import java.util.Locale;
import java.util.ResourceBundle;
/**
*
* @author huangyuhui
*/
public enum SupportedLocales {
def(Locale.getDefault(), "lang.default"), en(Locale.ENGLISH, null), zh_TW(Locale.TRADITIONAL_CHINESE, null), zh_CN(Locale.SIMPLIFIED_CHINESE, null);
public Locale self;
private String showString, customized;
private ResourceBundle bundle;
private SupportedLocales(Locale self, String customized) {
this.self = self;
try {
bundle = ResourceBundle.getBundle("org/jackhuang/hellominecraft/lang/I18N", self);
showString = bundle.getString("lang");
this.customized = customized;
} catch (Throwable t) {
showString = self.toString();
t.printStackTrace();
}
}
public String showString() {
if (customized == null)
return showString;
else
return NOW_LOCALE.translate(customized);
}
public static SupportedLocales NOW_LOCALE = def;
public String translate(String key, Object... format) {
try {
return bundle.getString(key);
} catch (Exception ex) {
ex.printStackTrace();
return key;
}
}
}

View File

@@ -192,7 +192,7 @@ public class IOUtils {
return path + "java";
}
public static byte[] readFully(InputStream stream) throws IOException {
public static ByteArrayOutputStream readFully(InputStream stream) throws IOException {
byte[] data = new byte[4096];
ByteArrayOutputStream entryBuffer = new ByteArrayOutputStream();
int len;
@@ -203,7 +203,7 @@ public class IOUtils {
entryBuffer.write(data, 0, len);
} while (len != -1);
return entryBuffer.toByteArray();
return entryBuffer;
}
public static void closeQuietly(Reader input) {