mirror of
https://github.com/nitu2003/T18n
synced 2024-11-21 23:28:49 +00:00
[D] 添加一些神奇的注解
This commit is contained in:
parent
009699b11e
commit
f02dbeabc1
@ -16,6 +16,12 @@ public class I18n {
|
||||
charset = Charset.forName(System.getProperty("file.encoding"));
|
||||
}
|
||||
|
||||
/* *******************************************************
|
||||
*
|
||||
* Settings
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
public static void setLanguageMap(LanguageMap map) {
|
||||
I18n.map = map;
|
||||
}
|
||||
@ -24,6 +30,12 @@ public class I18n {
|
||||
I18n.charset = Charset.forName(charset);
|
||||
}
|
||||
|
||||
/* *******************************************************
|
||||
*
|
||||
* Localization functions
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
/** 自动从语言文件中提取翻译,空翻译时返回原键值 */
|
||||
public static String translate(String key) {
|
||||
return reEncode(getLanguageMapSafe().get(key), charset);
|
||||
@ -75,6 +87,12 @@ public class I18n {
|
||||
return getLanguageMapSafe().containsKey(key);
|
||||
}
|
||||
|
||||
/* *******************************************************
|
||||
*
|
||||
* Utilities
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
/** @see #hasKey(String) */
|
||||
private static boolean canTranslate(String key) {
|
||||
return hasKey(key);
|
||||
@ -97,4 +115,14 @@ public class I18n {
|
||||
return map == null ? new LanguageMap() : map;
|
||||
}
|
||||
|
||||
/* *******************************************************
|
||||
*
|
||||
* For Devlopers
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
public static LanguageMap getLangMap() {
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package cn.glycol.t18n;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
|
||||
public class LanguageMap extends HashMap<String, String> {
|
||||
|
||||
@ -11,7 +12,15 @@ public class LanguageMap extends HashMap<String, String> {
|
||||
return super.getOrDefault(key, key.toString());
|
||||
}
|
||||
|
||||
public ArrayList<String> getAllKeyValuePairs() {
|
||||
/** 返回所有键值对
|
||||
* @see #entrySet()
|
||||
*/
|
||||
public Set<Entry<String, String>> getAllKeyValuePairs() {
|
||||
return this.entrySet();
|
||||
}
|
||||
|
||||
/** 获取所有键值对文字 */
|
||||
public ArrayList<String> getAllKeyValuePairsString() {
|
||||
|
||||
ArrayList<String> list = new ArrayList<String>();
|
||||
for(Entry<String, String> set : this.entrySet()) {
|
||||
@ -28,4 +37,10 @@ public class LanguageMap extends HashMap<String, String> {
|
||||
return list;
|
||||
}
|
||||
|
||||
/** 输出键值对 */
|
||||
public static void printKVPair(LanguageMap langMap) {
|
||||
ArrayList<String> lines = langMap.getAllKeyValuePairsString();
|
||||
lines.forEach(s->System.out.println(s));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -68,7 +68,7 @@ public class T18nUtils {
|
||||
|
||||
try {
|
||||
|
||||
String content = flattenList(map.getAllKeyValuePairs());
|
||||
String content = flattenList(map.getAllKeyValuePairsString());
|
||||
|
||||
if(!file.exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
|
Loading…
Reference in New Issue
Block a user