Merge pull request #898 from hoodie13/local-gedoor-code

修复繁简转换“勐”“十”问题。使用了剥离HanLP简繁代码的民间库。APK减少6M左右。如果后面需要修改其他转换错误,可以自己fork代码改字典部署JitPack。
pull/909/head
kunfei 4 years ago committed by GitHub
commit cf20389add
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      app/build.gradle
  2. 6
      app/src/main/java/io/legado/app/help/ContentProcessor.kt
  3. 6
      app/src/main/java/io/legado/app/service/help/ReadBook.kt
  4. 6
      app/src/main/java/io/legado/app/ui/book/searchContent/SearchContentActivity.kt
  5. 6
      app/src/main/java/io/legado/app/ui/welcome/WelcomeActivity.kt

@ -209,8 +209,7 @@ dependencies {
implementation 'io.noties.markwon:html:4.6.0' implementation 'io.noties.markwon:html:4.6.0'
// //
implementation 'com.hankcs:hanlp:portable-1.7.8' implementation 'com.github.liuyueyi.quick-chinese-transfer:quick-transfer-core:0.1.3'
//epub //epub
implementation('com.positiondev.epublib:epublib-core:3.1') { implementation('com.positiondev.epublib:epublib-core:3.1') {
exclude group: 'org.slf4j' exclude group: 'org.slf4j'

@ -1,6 +1,6 @@
package io.legado.app.help package io.legado.app.help
import com.hankcs.hanlp.HanLP import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.ReplaceRule import io.legado.app.data.entities.ReplaceRule
@ -51,8 +51,8 @@ class ContentProcessor(private val bookName: String, private val bookOrigin: Str
} }
try { try {
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> content1 = HanLP.convertToSimplifiedChinese(content1) 1 -> content1 = ChineseUtils.t2s(content1)
2 -> content1 = HanLP.convertToTraditionalChinese(content1) 2 -> content1 = ChineseUtils.s2t(content1)
} }
} catch (e: Exception) { } catch (e: Exception) {
appCtx.toastOnUi("简繁转换出错") appCtx.toastOnUi("简繁转换出错")

@ -1,7 +1,7 @@
package io.legado.app.service.help package io.legado.app.service.help
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import com.hankcs.hanlp.HanLP import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.constant.BookType import io.legado.app.constant.BookType
import io.legado.app.data.appDb import io.legado.app.data.appDb
import io.legado.app.data.entities.* import io.legado.app.data.entities.*
@ -407,8 +407,8 @@ object ReadBook {
ImageProvider.clearOut(durChapterIndex) ImageProvider.clearOut(durChapterIndex)
if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) { if (chapter.index in durChapterIndex - 1..durChapterIndex + 1) {
chapter.title = when (AppConfig.chineseConverterType) { chapter.title = when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese(chapter.title) 1 -> ChineseUtils.t2s(chapter.title)
2 -> HanLP.convertToTraditionalChinese(chapter.title) 2 -> ChineseUtils.s2t(chapter.title)
else -> chapter.title else -> chapter.title
} }
val contents = contentProcessor!!.getContent(book, chapter.title, content) val contents = contentProcessor!!.getContent(book, chapter.title, content)

@ -5,7 +5,7 @@ import android.content.Intent
import android.os.Bundle import android.os.Bundle
import androidx.activity.viewModels import androidx.activity.viewModels
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import com.hankcs.hanlp.HanLP import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
@ -180,8 +180,8 @@ class SearchContentActivity :
//搜索替换后的正文 //搜索替换后的正文
withContext(Dispatchers.IO) { withContext(Dispatchers.IO) {
chapter.title = when (AppConfig.chineseConverterType) { chapter.title = when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese(chapter.title) 1 -> ChineseUtils.t2s(chapter.title)
2 -> HanLP.convertToTraditionalChinese(chapter.title) 2 -> ChineseUtils.s2t(chapter.title)
else -> chapter.title else -> chapter.title
} }
replaceContents = replaceContents =

@ -2,7 +2,7 @@ package io.legado.app.ui.welcome
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import com.hankcs.hanlp.HanLP import com.github.liuyueyi.quick.transfer.ChineseUtils
import io.legado.app.base.BaseActivity import io.legado.app.base.BaseActivity
import io.legado.app.constant.PreferKey import io.legado.app.constant.PreferKey
import io.legado.app.data.appDb import io.legado.app.data.appDb
@ -61,8 +61,8 @@ open class WelcomeActivity : BaseActivity<ActivityWelcomeBinding>() {
} }
//初始化简繁转换引擎 //初始化简繁转换引擎
when (AppConfig.chineseConverterType) { when (AppConfig.chineseConverterType) {
1 -> HanLP.convertToSimplifiedChinese("初始化") 1 -> ChineseUtils.t2s("初始化")
2 -> HanLP.convertToTraditionalChinese("初始化") 2 -> ChineseUtils.s2t("初始化")
else -> null else -> null
} }
} }

Loading…
Cancel
Save