Skip to content

Commit

Permalink
fix: mozhi engine error 500 when source or target lang has more than …
Browse files Browse the repository at this point in the history
…2 chars
  • Loading branch information
GitGitro committed Oct 22, 2024
1 parent c19f800 commit a162872
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/migrations.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 12 additions & 2 deletions app/src/main/java/com/bnyro/translate/api/mh/MhEngine.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package com.bnyro.translate.api.mh

import android.util.Log
import com.bnyro.translate.const.ApiKeyState
import com.bnyro.translate.db.obj.Language
import com.bnyro.translate.ext.concatenate
import com.bnyro.translate.obj.Translation
import com.bnyro.translate.util.RetrofitHelper
import com.bnyro.translate.util.TranslationEngine
Expand Down Expand Up @@ -59,9 +61,17 @@ class MhEngine : TranslationEngine(
override suspend fun translate(query: String, source: String, target: String): Translation {
val response = api.translate(
engine = getSelectedEngine(),
source = sourceOrAuto(source),
source = (if(sourceOrAuto(source).length==3){
sourceOrAuto(source).dropLast(1)
} else {
sourceOrAuto(source)
}).toString(),
query = query,
target = target
target = (if(target.length==3){
target.dropLast(1)
} else {
target
}).toString()
)
return Translation(
translatedText = response.translatedText,
Expand Down

0 comments on commit a162872

Please sign in to comment.