Commit fc832dd2 authored by 张永's avatar 张永

增加ICU4J 简转繁体包

parent 780e8b2c
...@@ -136,7 +136,7 @@ ...@@ -136,7 +136,7 @@
<version>2.0.10</version> <version>2.0.10</version>
</dependency> </dependency>
<!-- 简体转繁体 --> <!-- 简体转繁体 start 以下为两种 https://blog.51cto.com/u_16213408/6959812 -->
<dependency> <dependency>
<groupId>com.github.houbb</groupId> <groupId>com.github.houbb</groupId>
<artifactId>opencc4j</artifactId> <artifactId>opencc4j</artifactId>
...@@ -144,6 +144,13 @@ ...@@ -144,6 +144,13 @@
</dependency> </dependency>
<dependency>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
<version>74.1</version>
</dependency>
<!-- 简体转繁体end -->
</dependencies> </dependencies>
<build> <build>
......
...@@ -39,7 +39,8 @@ import com.egolm.common.exception.PluginException; ...@@ -39,7 +39,8 @@ import com.egolm.common.exception.PluginException;
import com.egolm.common.exception.ReflectException; import com.egolm.common.exception.ReflectException;
import com.egolm.common.exception.SHA1Exception; import com.egolm.common.exception.SHA1Exception;
import com.github.houbb.opencc4j.util.ZhConverterUtil; import com.github.houbb.opencc4j.util.ZhConverterUtil;
import com.ibm.icu.text.Transliterator;
import net.sourceforge.pinyin4j.PinyinHelper; import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType; import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat; import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
...@@ -1207,18 +1208,33 @@ public class StringUtil { ...@@ -1207,18 +1208,33 @@ public class StringUtil {
/** /**
* 简体中文转繁体 * 简体中文转繁体
* https://www.jianshu.com/p/ebb471c39fb8 * https://www.jianshu.com/p/ebb471c39fb8
*
* https://blog.51cto.com/u_16213408/6959812
* <p>Title: </p> * <p>Title: </p>
* <p>Description: </p> * <p>Description: </p>
* @return * @return
*/ */
public static String znChineseToTraditional(String znStr) { public static String znChineseToTraditional(String znStr) {
return ZhConverterUtil.toTraditional(znStr); //return ZhConverterUtil.toTraditional(znStr); //这个为opencc 繁体在转繁体会出现在错误
return ICU4JConverter(znStr);
} }
public static void main(String[] args) { public static void main(String[] args) {
String original = "综合平效-实面"; String original = "萬里行有限公司";
String result = ZhConverterUtil.toTraditional(original); String result = ZhConverterUtil.toTraditional(original);
//Assert.assertEquals("生命不息,奮鬥不止", result); System.out.println("opecc : "+result);
System.out.println(result); String result1 = ICU4JConverter(original);
System.out.println("icu4j : "+result1);
}
//ibm提供的 转换方式 简--转繁体
public static String ICU4JConverter(String original) {
Transliterator converter = Transliterator.getInstance("Simplified-Traditional");
String traditional = converter.transliterate(original);
return traditional;
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment