1
0
mirror of https://github.com/nitu2003/T18n synced 2024-11-13 02:38:46 +00:00

[+] 很多注解

This commit is contained in:
Taskeren 2019-07-12 13:55:18 +08:00
parent 240bc0cd0b
commit d87eb146d4
2 changed files with 47 additions and 0 deletions

View File

@ -11,20 +11,43 @@ import java.util.List;
public class LanguageMapBuilder {
/**
* 从文件读取语言包
* @param langFile 语言文件
* @return 语言包
*/
public static LanguageMap fromFile(File langFile) {
return fromFile(langFile, LanguageMapConfiguration.DEFAULT);
}
/**
* 从文件读取语言包
* @param langFile 语言文件
* @param config 读取配置
* @return 语言包
*/
public static LanguageMap fromFile(File langFile, LanguageMapConfiguration config) {
List<String> lines = T18nUtils.getLocalContent(langFile);
return processFinal(config, lines);
}
/**
* UTF8 为编码读取Jar包里的资源
* @param path 资源地址
* @return 语言包
*/
public static LanguageMap fromJarResource(String path) {
return fromJarResource(path, "UTF8", LanguageMapConfiguration.DEFAULT);
}
/**
* 用设定编码读取Jar包里的资源
* @param path 资源地址
* @param encode 编码名称例如<code>UTF-8</code><code>GBK</code><code>Unicode</code>等等
* @param config 读取配置
* @return 语言包
*/
public static LanguageMap fromJarResource(String path, String encode, LanguageMapConfiguration config) {
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path);
@ -53,10 +76,21 @@ public class LanguageMapBuilder {
}
/**
* 从在线页面读取语言包
* @param url 页面地址
* @return 语言包
*/
public static LanguageMap fromURL(String url) {
return fromURL(url, LanguageMapConfiguration.DEFAULT);
}
/**
* 从在线页面读取语言包
* @param url 页面地址
* @param config 读取配置
* @return 语言包
*/
public static LanguageMap fromURL(String url, LanguageMapConfiguration config) {
return processFinal(config, T18nUtils.getOnlineContent(url));
}

View File

@ -2,7 +2,20 @@ package cn.glycol.t18n;
public interface LanguageMapConfiguration {
/**
* 获取分割符<br>
* 用于将键和值分割开来
* @param s 每行文字
* @return 分隔符
*/
public String getSplitter(String s);
/**
* 检测是否是注解<br>
* 如果是注解则忽略本行
* @param s 每行文字
* @return 是否是注解<code>true</code>则忽略读取
*/
public boolean isAnnotation(String s);
public static final LanguageMapConfiguration DEFAULT = new LanguageMapConfiguration() {