mirror of
https://github.com/nitu2003/T18n
synced 2024-11-13 02:38:46 +00:00
调整部分方法
将设置和开发相关方法移动到T18n类中
This commit is contained in:
parent
7e91fa3d4c
commit
b9d5915cda
18
.classpath
18
.classpath
@ -1,18 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/java">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" output="bin/main" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="gradle_scope" value="main"/>
|
||||
<attribute name="gradle_used_by_scope" value="main,test"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
6
.gitignore
vendored
6
.gitignore
vendored
@ -3,3 +3,9 @@
|
||||
|
||||
# Ignore Gradle build output directory
|
||||
build
|
||||
|
||||
# eclipse
|
||||
bin/
|
||||
.settings/
|
||||
.classpath
|
||||
.project
|
23
.project
23
.project
@ -1,23 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>T18n</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,2 +0,0 @@
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
@ -1,13 +0,0 @@
|
||||
#
|
||||
#Tue Jun 25 20:09:41 CST 2019
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.source=1.8
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
2
bin/.gitignore
vendored
2
bin/.gitignore
vendored
@ -1,2 +0,0 @@
|
||||
/main/
|
||||
/test/
|
@ -4,15 +4,16 @@ import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
|
||||
public class I18n {
|
||||
|
||||
private static LanguageMap map;
|
||||
private static Charset charset;
|
||||
protected static LanguageMap map;
|
||||
protected static Charset charset;
|
||||
|
||||
public static final int LOOP_MAX_COUNT = 1000;
|
||||
protected static final int LOOP_MAX_COUNT = 32767;
|
||||
|
||||
static {
|
||||
map = new LanguageMap();
|
||||
charset = Charset.forName(System.getProperty("file.encoding"));
|
||||
}
|
||||
|
||||
@ -22,10 +23,12 @@ public class I18n {
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
@Deprecated
|
||||
public static void setLanguageMap(LanguageMap map) {
|
||||
I18n.map = map;
|
||||
T18n.set(map);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void setEncoding(String charset) {
|
||||
I18n.charset = Charset.forName(charset);
|
||||
}
|
||||
@ -37,8 +40,9 @@ public class I18n {
|
||||
* *******************************************************/
|
||||
|
||||
/** 自动从语言文件中提取翻译,空翻译时返回原键值 */
|
||||
@Deprecated
|
||||
public static String translate(String key) {
|
||||
return reEncode(getLanguageMapSafe().get(key), charset);
|
||||
return reEncode(map.get(key), charset);
|
||||
}
|
||||
|
||||
/** 自动翻译(translate)后再执行格式化(format) */
|
||||
@ -52,6 +56,7 @@ public class I18n {
|
||||
* 连续读取翻译(translate)。
|
||||
* @param keyRegular 翻译键值表达式,需要填入一个“%s”用于替换为行数。行数从0开始。例如“welcome.%s”,则程序会依次向列表中添加“welcome.0”,“welcome.1”...的翻译,直到获取到空值。
|
||||
*/
|
||||
@Deprecated
|
||||
public static List<String> translateList(String keyRegular) {
|
||||
|
||||
List<String> vlist = new ArrayList<String>();
|
||||
@ -78,13 +83,13 @@ public class I18n {
|
||||
* @see #translateList(String)
|
||||
*/
|
||||
public static String formatList(String keyRegular, Object...format) {
|
||||
|
||||
|
||||
return tryFormat(T18nUtils.flattenList(translateList(keyRegular)), format);
|
||||
|
||||
}
|
||||
|
||||
public static boolean hasKey(String key) {
|
||||
return getLanguageMapSafe().containsKey(key);
|
||||
return map.containsKey(key);
|
||||
}
|
||||
|
||||
/* *******************************************************
|
||||
@ -93,13 +98,6 @@ public class I18n {
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
/** @see #hasKey(String) */
|
||||
private static boolean canTranslate(String key) {
|
||||
return hasKey(key);
|
||||
}
|
||||
|
||||
private static final Charset DEFAULT_CHARSET = Charset.forName("unicode");
|
||||
|
||||
private static String reEncode(String bef, Charset charset) {
|
||||
byte[] bytes = bef.getBytes(charset);
|
||||
return new String(bytes, charset);
|
||||
@ -113,16 +111,13 @@ public class I18n {
|
||||
}
|
||||
}
|
||||
|
||||
private static LanguageMap getLanguageMapSafe() {
|
||||
return map == null ? new LanguageMap() : map;
|
||||
}
|
||||
|
||||
/* *******************************************************
|
||||
*
|
||||
* For Devlopers
|
||||
*
|
||||
* *******************************************************/
|
||||
|
||||
@Deprecated
|
||||
public static LanguageMap getLangMap() {
|
||||
return map;
|
||||
}
|
||||
|
42
src/main/java/cn/glycol/t18n/T18n.java
Normal file
42
src/main/java/cn/glycol/t18n/T18n.java
Normal file
@ -0,0 +1,42 @@
|
||||
package cn.glycol.t18n;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Objects;
|
||||
|
||||
public class T18n {
|
||||
|
||||
/**
|
||||
* 设置本地化对照表
|
||||
* @param map 本地化对照表
|
||||
*/
|
||||
public static void set(LanguageMap map) {
|
||||
Objects.requireNonNull(map, "map cannot be null");
|
||||
I18n.map = map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加额外的本地化对照表
|
||||
* @param map 本地化对照表
|
||||
*/
|
||||
public static void add(LanguageMap map) {
|
||||
Objects.requireNonNull(map, "map cannot be null");
|
||||
I18n.map.putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置输出的编码
|
||||
* @param charset 编码
|
||||
*/
|
||||
public static void charset(Charset charset) {
|
||||
Objects.requireNonNull(charset, "charset cannot be null");
|
||||
I18n.charset = charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取本地化对照表
|
||||
*/
|
||||
public static LanguageMap map() {
|
||||
return I18n.map;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user