format code

Signed-off-by: Sola <dev@sola.love>
This commit is contained in:
Sola
2017-12-15 08:57:51 +08:00
parent 529b36d9e3
commit 0bdcf031b5
69 changed files with 1988 additions and 1988 deletions

View File

@@ -29,29 +29,29 @@ import java.util.Map;
*/
public class Lang {
public static Map<String, String> messages;
public static Map<String, MessageFormat> format_cache = new HashMap<>(32);
public static Map<String, String> messages;
public static Map<String, MessageFormat> format_cache = new HashMap<>(32);
static {
InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
//noinspection unchecked
messages = new Yaml().loadAs(in, Map.class);
}
static {
InputStream in = Lang.class.getClassLoader().getResourceAsStream("lang.yml");
//noinspection unchecked
messages = new Yaml().loadAs(in, Map.class);
}
public static String lang(String key) {
String value = messages.get(key);
return value == null ? "!!" + key + "!!" : value;
}
public static String lang(String key) {
String value = messages.get(key);
return value == null ? "!!" + key + "!!" : value;
}
public static String format(String key, Object... args) {
MessageFormat cache = format_cache.get(key);
if (cache != null) {
return cache.format(args);
} else {
cache = new MessageFormat(lang(key));
format_cache.put(key, cache);
return cache.format(args);
}
}
public static String format(String key, Object... args) {
MessageFormat cache = format_cache.get(key);
if (cache != null) {
return cache.format(args);
} else {
cache = new MessageFormat(lang(key));
format_cache.put(key, cache);
return cache.format(args);
}
}
}