Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mylife: smoother list translation (fixes #4401) #4426

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,14 @@ class AdapterMyLife(private val context: Context, private val myLifeList: List<R
@SuppressLint("ClickableViewAccessibility")
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
if (holder is ViewHolderMyLife) {
holder.title.text = myLifeList[position].title
var translatedText = myLifeList[position].title
try {
var resId = Utilities.getStringIdentifier(translatedText?.lowercase())
translatedText = context.getString(resId)
} catch (e: Exception) {
translatedText = myLifeList[position].title
}
holder.title.text = translatedText
holder.imageView.setImageResource(context.resources.getIdentifier(myLifeList[position].imageId, "drawable", context.packageName))
holder.imageView.contentDescription = context.getString(R.string.icon, myLifeList[position].title)
val fragment = findFragment(myLifeList[position].imageId)
Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/org/ole/planet/myplanet/utilities/Utilities.kt
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,24 @@ object Utilities {
context.startActivity(webIntent)
}
}

fun getStringIdentifier(name: String?): Int {
if (name == "mymessages" || name == "myachievements"){
val modifiedString = name.substring(2)
return context.resources.getIdentifier(modifiedString, "string", context.packageName)
}
else if (name == "mysurvey"){
return context.resources.getIdentifier("my_survey", "string", context.packageName)
}
else if (name == "mysubmissions"){
return context.resources.getIdentifier("submission", "string", context.packageName)
}
else if (name == "help wanted"){
return context.resources.getIdentifier("help_wanted", "string", context.packageName)
}
else {
return context.resources.getIdentifier(name, "string", context.packageName)
}

}
Comment on lines +226 to +244
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mylife items are sourced from the database, and in this implementation, you're passing the title directly to this function for translation. However, this approach may not work if there's an item that isn't hardcoded into this function. We need a more dynamic solution to handle such cases

}