Skip to content

Commit

Permalink
Fix issues with translations menu button
Browse files Browse the repository at this point in the history
 - it is not inflated for user's own posts but we didn't check for that
 - some servers return language codes in uppercase and it wasn't
matching Java's lowercase code when it should have
  • Loading branch information
charlag committed Mar 9, 2024
1 parent 1444466 commit 16a5dc6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -328,10 +328,13 @@ class SearchStatusesFragment : SearchFragment<StatusViewData.Concrete>(), Status
)
}

val translateItem = popup.menu.findItem(R.id.status_translate)
translateItem.isVisible =
status.language != Locale.getDefault().language && viewModel.supportsTranslation()
translateItem.setTitle(if (statusViewData.translation != null) R.string.action_show_original else R.string.action_translate)
// translation not there for your own posts
popup.menu.findItem(R.id.status_translate)?.let { translateItem ->
translateItem.isVisible =
!status.language.equals(Locale.getDefault().language, ignoreCase = true) &&
viewModel.supportsTranslation()
translateItem.setTitle(if (statusViewData.translation != null) R.string.action_show_original else R.string.action_translate)
}

popup.setOnMenuItemClickListener { item ->
when (item.itemId) {
Expand Down
11 changes: 7 additions & 4 deletions app/src/main/java/com/keylesspalace/tusky/fragment/SFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,13 @@ abstract class SFragment : Fragment(), Injectable {
)
}

val translateItem = menu.findItem(R.id.status_translate)
translateItem.isVisible =
onMoreTranslate != null && status.language != Locale.getDefault().language && instanceInfoRepository.cachedInstanceInfoOrFallback.translationEnabled == true
translateItem.setTitle(if (translation != null) R.string.action_show_original else R.string.action_translate)
// translation not there for your own posts
menu.findItem(R.id.status_translate)?.let { translateItem ->
translateItem.isVisible = onMoreTranslate != null &&
!status.language.equals(Locale.getDefault().language, ignoreCase = true) &&
instanceInfoRepository.cachedInstanceInfoOrFallback.translationEnabled == true
translateItem.setTitle(if (translation != null) R.string.action_show_original else R.string.action_translate)
}

popup.setOnMenuItemClickListener { item: MenuItem ->
when (item.itemId) {
Expand Down

0 comments on commit 16a5dc6

Please sign in to comment.