Skip to content

Commit

Permalink
added papago.com translation engine, fixed #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff committed Jun 14, 2022
1 parent 7feac86 commit b43241a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
17 changes: 10 additions & 7 deletions app/src/main/java/site/leos/setter/TranslationActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,23 @@ class TranslationActivity : AppCompatActivity() {
val defaultLocale = Locale.getDefault()
val query = intent.getStringExtra(KEY_QUERY)
var deepLURL = getString(R.string.url_deepl)
var googleURL = getString(R.string.url_google_tranlation)
var googleURL = getString(R.string.url_google_translation)
val papagoURL = getString(R.string.url_papago_translation) + query
val udURL = getString(R.string.url_urban_dictionary) + query
val jikiURL = getString(R.string.url_jikipedia) + query

deepLURL = "$deepLURL${defaultLocale.language}/$query"
googleURL = if (defaultLocale.language.equals("zh")) googleURL + defaultLocale.language + "-" + defaultLocale.country + "&text=" else googleURL + defaultLocale.language + "&text="
googleURL += query

viewPager.adapter = ViewStateAdapter(supportFragmentManager, lifecycle, deepLURL, googleURL, udURL, jikiURL)
viewPager.adapter = ViewStateAdapter(supportFragmentManager, lifecycle, deepLURL, googleURL, papagoURL, udURL, jikiURL)
TabLayoutMediator(tabs, viewPager) {tab, position ->
when (position) {
0 -> {tab.text = "DeepL"}
1 -> {tab.text = "Google"}
2 -> {tab.text = "Urban Dictionary"}
3 -> {tab.text = getString(R.string.jikiName)}
2 -> {tab.text = "Papago"}
3 -> {tab.text = "Urban Dictionary"}
4 -> {tab.text = getString(R.string.jikiName)}
}
}.attach()
viewPager.recyclerView.enforceSingleScrollDirection()
Expand Down Expand Up @@ -89,16 +91,17 @@ class TranslationActivity : AppCompatActivity() {
}
}

private class ViewStateAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle, val url0:String, val url1:String, val url2:String, val url3:String)
private class ViewStateAdapter(fragmentManager: FragmentManager, lifecycle: Lifecycle, val url0:String, val url1:String, val url2:String, val url3:String, val url4:String)
: FragmentStateAdapter(fragmentManager, lifecycle) {
override fun getItemCount(): Int = 4
override fun getItemCount(): Int = 5

override fun createFragment(position: Int): Fragment {
return when (position) {
0 -> TextSearchFragment.newInstance(url0)
1 -> TextSearchFragment.newInstance(url1)
2 -> TextSearchFragment.newInstance(url2)
else -> TextSearchFragment.newInstance(url3)
3 -> TextSearchFragment.newInstance(url3)
else -> TextSearchFragment.newInstance(url4)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<string name="colordict_not_installed">Install ColorDict app</string>
<string name="colordict_intro">An offline dictionary app, respect privacy. Support stardict format dictionaries.</string>
<string name="url_deepl" translatable="false">https://www.deepl.com/translator#en/</string>
<string name="url_google_tranlation" translatable="false">https://translate.google.com/#view=home&amp;op=translate&amp;sl=auto&amp;tl=</string>
<string name="url_google_translation" translatable="false">https://translate.google.com/#view=home&amp;op=translate&amp;sl=auto&amp;tl=</string>
<string name="url_papago_translation" translatable="false">https://papago.naver.com/?sk=auto&amp;tk=ko&amp;hn=0&amp;st=</string>
<string name="url_urban_dictionary" translatable="false">https://www.urbandictionary.com/define.php?term=</string>
<string name="url_jikipedia" translatable="false">https://jikipedia.com/search?phrase=</string>
<string name="jikiName">jikipedia</string>
Expand Down

0 comments on commit b43241a

Please sign in to comment.