mirror of
https://github.com/ZSCNetSupportDept/WechatTicketSystem.git
synced 2025-10-30 01:46:18 +08:00
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user