-
-
Notifications
You must be signed in to change notification settings - Fork 173
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix OCR command when using it in images that are in Chinese
- Loading branch information
1 parent
494e36c
commit 4bb5f78
Showing
7 changed files
with
203 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
...src/main/kotlin/net/perfectdreams/loritta/cinnamon/discord/utils/google/GoogleAPIUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package net.perfectdreams.loritta.cinnamon.discord.utils.google | ||
|
||
import net.dv8tion.jda.api.interactions.DiscordLocale | ||
|
||
object GoogleAPIUtils { | ||
val DISCORD_LOCALE_TO_LANGUAGE_MAP = DiscordLocale.values().map { | ||
it to when (it) { | ||
DiscordLocale.PORTUGUESE_BRAZILIAN -> GoogleVisionLanguage.PORTUGUESE | ||
DiscordLocale.BULGARIAN -> GoogleVisionLanguage.BULGARIAN | ||
DiscordLocale.CHINESE_CHINA -> GoogleVisionLanguage.SIMPLIFIED_CHINESE | ||
DiscordLocale.CHINESE_TAIWAN -> GoogleVisionLanguage.TRADITIONAL_CHINESE | ||
DiscordLocale.CROATIAN -> GoogleVisionLanguage.CROATIAN | ||
DiscordLocale.CZECH -> GoogleVisionLanguage.CZECH | ||
DiscordLocale.DANISH -> GoogleVisionLanguage.DANISH | ||
DiscordLocale.DUTCH -> GoogleVisionLanguage.DUTCH | ||
DiscordLocale.FINNISH -> GoogleVisionLanguage.FINNISH | ||
DiscordLocale.FRENCH -> GoogleVisionLanguage.FRENCH | ||
DiscordLocale.GERMAN -> GoogleVisionLanguage.GERMAN | ||
DiscordLocale.GREEK -> GoogleVisionLanguage.GREEK | ||
DiscordLocale.HINDI -> GoogleVisionLanguage.HINDI | ||
DiscordLocale.HUNGARIAN -> GoogleVisionLanguage.HUNGARIAN | ||
DiscordLocale.ITALIAN -> GoogleVisionLanguage.ITALIAN | ||
DiscordLocale.JAPANESE -> GoogleVisionLanguage.JAPANESE | ||
DiscordLocale.KOREAN -> GoogleVisionLanguage.KOREAN | ||
DiscordLocale.LITHUANIAN -> GoogleVisionLanguage.LITHUANIAN | ||
DiscordLocale.NORWEGIAN -> GoogleVisionLanguage.NORWEGIAN | ||
DiscordLocale.POLISH -> GoogleVisionLanguage.POLISH | ||
DiscordLocale.ROMANIAN_ROMANIA -> GoogleVisionLanguage.ROMANIAN | ||
DiscordLocale.RUSSIAN -> GoogleVisionLanguage.RUSSIAN | ||
DiscordLocale.SPANISH -> GoogleVisionLanguage.SPANISH | ||
DiscordLocale.SWEDISH -> GoogleVisionLanguage.SWEDISH | ||
DiscordLocale.THAI -> GoogleVisionLanguage.THAI | ||
DiscordLocale.TURKISH -> GoogleVisionLanguage.TURKISH | ||
DiscordLocale.UKRAINIAN -> GoogleVisionLanguage.UKRAINIAN | ||
DiscordLocale.VIETNAMESE -> GoogleVisionLanguage.VIETNAMESE | ||
DiscordLocale.ENGLISH_UK -> GoogleVisionLanguage.ENGLISH | ||
else -> GoogleVisionLanguage.ENGLISH | ||
} | ||
}.toMap() | ||
|
||
// This is a bit of a hack | ||
fun fromVisionLanguageToTranslateLanguage(visionLanguage: GoogleVisionLanguage) = GoogleTranslateLanguage.valueOf(visionLanguage.name) | ||
} |
128 changes: 128 additions & 0 deletions
128
...kotlin/net/perfectdreams/loritta/cinnamon/discord/utils/google/GoogleTranslateLanguage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package net.perfectdreams.loritta.cinnamon.discord.utils.google | ||
|
||
import net.perfectdreams.i18nhelper.core.keydata.StringI18nData | ||
import net.perfectdreams.i18nhelper.core.keys.StringI18nKey | ||
import net.perfectdreams.loritta.common.utils.text.TextUtils | ||
|
||
enum class GoogleTranslateLanguage(val code: String) { | ||
AUTO_DETECT("auto"), // Not a "real language" | ||
UNDETERMINED("und"), | ||
AFRIKAANS("af"), | ||
ALBANIAN("sq"), | ||
AMHARIC("am"), | ||
ARABIC("ar"), | ||
ARMENIAN("hy"), | ||
AZERBAIJANI("az"), | ||
BASQUE("eu"), | ||
BELARUSIAN("be"), | ||
BENGALI("bn"), | ||
BOSNIAN("bs"), | ||
BULGARIAN("bg"), | ||
CATALAN("ca"), | ||
CEBUANO("ceb"), | ||
SIMPLIFIED_CHINESE("zh-CN"), // Google Translate uses "zh-CN" for simplified chinese, however Google Vision uses only "zh" | ||
TRADITIONAL_CHINESE("zh-TW"), | ||
CORSICAN("co"), | ||
CROATIAN("hr"), | ||
CZECH("cs"), | ||
DANISH("da"), | ||
DUTCH("nl"), | ||
ENGLISH("en"), | ||
ESPERANTO("eo"), | ||
ESTONIAN("et"), | ||
FINNISH("fi"), | ||
FRENCH("fr"), | ||
FRISIAN("fy"), | ||
GALICIAN("gl"), | ||
GEORGIAN("ka"), | ||
GERMAN("de"), | ||
GREEK("el"), | ||
GUJARATI("gu"), | ||
HAITIAN_CREOLE("ht"), | ||
HAUSA("ha"), | ||
HAWAIIAN("haw"), | ||
HEBREW("he"), | ||
HINDI("hi"), | ||
HMONG("hmn"), | ||
HUNGARIAN("hu"), | ||
ICELANDIC("is"), | ||
IGBO("ig"), | ||
INDONESIAN("id"), | ||
IRISH("ga"), | ||
ITALIAN("it"), | ||
JAPANESE("ja"), | ||
JAVANESE("jv"), | ||
KANNADA("kn"), | ||
KAZAKH("kk"), | ||
KHMER("km"), | ||
KINYARWANDA("rw"), | ||
KOREAN("ko"), | ||
KURDISH("ku"), | ||
KYRGYZ("ky"), | ||
LAO("lo"), | ||
LATIN("la"), | ||
LATVIAN("lv"), | ||
LITHUANIAN("lt"), | ||
LUXEMBOURGISH("lb"), | ||
MACEDONIAN("mk"), | ||
MALAGASY("mg"), | ||
MALAY("ms"), | ||
MALAYALAM("ml"), | ||
MALTESE("mt"), | ||
MAORI("mi"), | ||
MARATHI("mr"), | ||
MONGOLIAN("mn"), | ||
MYANMAR("my"), | ||
NEPALI("ne"), | ||
NORWEGIAN("no"), | ||
NYANJA("ny"), | ||
ODIA("or"), | ||
PASHTO("ps"), | ||
PERSIAN("fa"), | ||
POLISH("pl"), | ||
PORTUGUESE("pt"), | ||
PUNJABI("pa"), | ||
ROMANIAN("ro"), | ||
RUSSIAN("ru"), | ||
SAMOAN("sm"), | ||
SCOTS_GAELIC("gd"), | ||
SERBIAN("sr"), | ||
SESOTHO("st"), | ||
SHONA("sn"), | ||
SINDHI("sd"), | ||
SINHALA("si"), | ||
SLOVAK("sk"), | ||
SLOVENIAN("sl"), | ||
SOMALI("so"), | ||
SPANISH("es"), | ||
SUNDANESE("su"), | ||
SWAHILI("sw"), | ||
SWEDISH("sv"), | ||
TAGALOG("tl"), | ||
TAJIK("tg"), | ||
TAMIL("ta"), | ||
TATAR("tt"), | ||
TELUGU("te"), | ||
THAI("th"), | ||
TURKISH("tr"), | ||
TURKMEN("tk"), | ||
UKRAINIAN("uk"), | ||
URDU("ur"), | ||
UYGHUR("ug"), | ||
UZBEK("uz"), | ||
VIETNAMESE("vi"), | ||
WELSH("cy"), | ||
XHOSA("xh"), | ||
YIDDISH("yi"), | ||
YORUBA("yo"), | ||
ZULU("zu"); | ||
|
||
// It would be better if it was a "when" clause, to avoid any languages missing their translation | ||
// But alas, that would be too big and too boring to fill up | ||
val languageNameI18nKey: StringI18nData | ||
get() = StringI18nData(StringI18nKey("commands.command.translate.languages.${TextUtils.snakeToLowerCamelCase(this.name.lowercase())}"), emptyMap()) | ||
|
||
companion object { | ||
fun fromLanguageCode(code: String) = GoogleTranslateLanguage.values().first { it.code == code } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
loritta-bot-discord/src/test/kotlin/net/perfectdreams/loritta/utils/GoogleAPIUtilsTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package net.perfectdreams.loritta.utils | ||
|
||
import net.perfectdreams.loritta.cinnamon.discord.utils.google.GoogleAPIUtils | ||
import net.perfectdreams.loritta.cinnamon.discord.utils.google.GoogleVisionLanguage | ||
import org.junit.jupiter.api.Test | ||
|
||
class GoogleAPIUtilsTest { | ||
@Test | ||
fun `vision language to translate language conversion`() { | ||
for (visionLanguage in GoogleVisionLanguage.values()) { | ||
val language = GoogleAPIUtils.fromVisionLanguageToTranslateLanguage(visionLanguage) | ||
} | ||
} | ||
} |