android字体类型(使用android-opencc来处理汉字的简繁转换)

android-opencc是一个比较强大的汉字简繁转换库,今天小编就来说说关于android字体类型?下面更多详细答案一起来看看吧!

android字体类型(使用android-opencc来处理汉字的简繁转换)

android字体类型

android-opencc是一个比较强大的汉字简繁转换库。

首先在项目根目录的build.gradle中添加如下内容:

repositories { ... maven { url 'http://jitpack.io' } }

然后添加依赖:

dependencies { ... //简繁体转换 implementation 'com.github.qichuan:android-opencc:1.2.0' }

咱先小小的封装一下:

/** * 描 述: <汉字简繁体转换> */ class HyConverter private constructor(val context: Context) { companion object { fun it(context: Context): HyConverter { return HyConverter(context) } } /** * HK2S, Traditional Chinese (Hong Kong Standard) to Simplified * 香港繁体(香港小学学习字词表标准)到简体 */ fun doHK2S(origin: String): String { return ChineseConverter.convert(origin, ConversionType.HK2S, context) } /** * HK2T, Traditional Chinese (Hong Kong variant) to Traditional Chinese * 香港繁体(香港小学学习字词表标准)到繁体 */ fun doHK2T(origin: String): String { return ChineseConverter.convert(origin, ConversionType.HK2T, context) } /** * JP2T, New Japanese Kanji (Shinjitai) to Traditional Chinese Characters (Kyūjitai) * 日本汉字到繁体 */ fun doJP2T(origin: String): String { return ChineseConverter.convert(origin, ConversionType.JP2T, context) } /** * S2HK, Simplified Chinese to Traditional Chinese (Hong Kong Standard) * 简体到香港繁体(香港小学学习字词表标准) */ fun doS2HK(origin: String): String { return ChineseConverter.convert(origin, ConversionType.S2HK, context) } /** * S2T, Simplified Chinese to Traditional Chinese * 简体到繁体 */ fun doS2T(origin: String): String { return ChineseConverter.convert(origin, ConversionType.S2T, context) } /** * S2TW, Simplified Chinese to Traditional Chinese (Taiwan Standard) * 简体到台湾正体 */ fun doS2TW(origin: String): String { return ChineseConverter.convert(origin, ConversionType.S2TW, context) } /** * S2TWP, Simplified Chinese to Traditional Chinese (Taiwan Standard) with Taiwanese idiom * 简体到台湾正体,并转换为台湾常用词汇 */ fun doS2TWP(origin: String): String { return ChineseConverter.convert(origin, ConversionType.S2TWP, context) } /** * T2HK, Traditional Chinese to Traditional Chinese (Hong Kong Standard) * 繁体到香港繁体(香港小学学习字词表标准) */ fun doT2HK(origin: String): String { return ChineseConverter.convert(origin, ConversionType.T2HK, context) } /** * T2S, Traditional Chinese to Simplified Chinese * 繁体到简体 */ fun doT2S(origin: String): String { return ChineseConverter.convert(origin, ConversionType.T2S, context) } /** * T2TW, Traditional Chinese to Traditional Chinese (Taiwan Standard) * 繁体到台湾正体 */ fun doT2TW(origin: String): String { return ChineseConverter.convert(origin, ConversionType.T2TW, context) } /** * TW2S, Traditional Chinese (Taiwan Standard) to Simplified Chinese * 台湾正体到简体 */ fun doTW2S(origin: String): String { return ChineseConverter.convert(origin, ConversionType.TW2S, context) } /** * T2JP, Traditional Chinese Characters (Kyūjitai) to New Japanese Kanji (Shinjitai) * 繁体到日本汉字 */ fun doT2JP(origin: String): String { return ChineseConverter.convert(origin, ConversionType.T2JP, context) } /** * TW2T, Traditional Chinese (Taiwan standard) to Traditional Chinese * 台湾正体到繁体 */ fun doTW2T(origin: String): String { return ChineseConverter.convert(origin, ConversionType.TW2T, context) } /** * TW2SP, Traditional Chinese (Taiwan Standard) to Simplified Chinese with Mainland Chinese idiom * 台湾正体到简体并转换为中国大陆常用词汇 */ fun doTW2SP(origin: String): String { return ChineseConverter.convert(origin, ConversionType.TW2SP, context) } }

使用例子:

//简体到繁体 val fanti = HyConverter.it(context).doS2T("这里输入一个简体的字符串")

免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com

    分享
    投诉
    首页