Skip to content

Commit

Permalink
Localization of user tabs (#563)
Browse files Browse the repository at this point in the history
* added missing translations for sections in headers

* fixed formatting

* fixed and changed NL translations
  • Loading branch information
kuro-codes authored Jun 13, 2023
1 parent e4923c9 commit 89325fc
Show file tree
Hide file tree
Showing 8 changed files with 113 additions and 3 deletions.
33 changes: 33 additions & 0 deletions app/src/main/java/com/jerboa/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import com.jerboa.datatypes.api.GetUnreadCountResponse
import com.jerboa.db.Account
import com.jerboa.ui.components.home.HomeViewModel
import com.jerboa.ui.components.home.SiteViewModel
import com.jerboa.ui.components.person.UserTab
import com.jerboa.ui.theme.SMALL_PADDING
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -907,3 +908,35 @@ fun Modifier.onAutofill(vararg autofillType: AutofillType, onFill: (String) -> U
fun convertSpToPx(sp: TextUnit, context: Context): Int {
return (sp.value * context.resources.displayMetrics.scaledDensity).toInt()
}

/**
* Returns localized Strings for SortingType Enum
*/

fun getLocalizedSortingTypeName(context: Context, sortingType: SortType): String {
val returnString = when (sortingType) {
SortType.Active -> context.getString(R.string.sorttype_active)
SortType.Hot -> context.getString(R.string.sorttype_hot)
SortType.New -> context.getString(R.string.sorttype_new)
SortType.Old -> context.getString(R.string.sorttype_old)
SortType.TopDay -> context.getString(R.string.sorttype_topday)
SortType.TopWeek -> context.getString(R.string.sorttype_topweek)
SortType.TopMonth -> context.getString(R.string.sorttype_topmonth)
SortType.TopYear -> context.getString(R.string.sorttype_topyear)
SortType.TopAll -> context.getString(R.string.sorttype_topall)
SortType.MostComments -> context.getString(R.string.sorttype_mostcomments)
SortType.NewComments -> context.getString(R.string.sorttype_newcomments)
else -> "Missing String Localization for Enum SortType"
}
return returnString
}

fun getLocalizedStringForUserTab(ctx: Context, tab: UserTab): String {
val returnString = when (tab) {
UserTab.About -> ctx.getString(R.string.person_profile_activity_about)
UserTab.Posts -> ctx.getString(R.string.person_profile_activity_posts)
UserTab.Comments -> ctx.getString(R.string.person_profile_activity_comments)
else -> "Missing String Localization for Enum UserTab"
}
return returnString
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.tooling.preview.Preview
import androidx.navigation.NavController
Expand All @@ -35,6 +36,7 @@ import com.jerboa.R
import com.jerboa.datatypes.PersonViewSafe
import com.jerboa.datatypes.SortType
import com.jerboa.datatypes.samplePersonView
import com.jerboa.getLocalizedSortingTypeName
import com.jerboa.personNameShown
import com.jerboa.ui.components.common.DotSpacer
import com.jerboa.ui.components.common.IconAndTextDrawerItem
Expand Down Expand Up @@ -255,7 +257,7 @@ fun PersonProfileHeaderTitle(
style = MaterialTheme.typography.titleLarge,
)
Text(
text = selectedSortType.toString(),
text = getLocalizedSortingTypeName(LocalContext.current, selectedSortType),
style = MaterialTheme.typography.titleMedium,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import com.jerboa.commentsToFlatNodes
import com.jerboa.db.Account
import com.jerboa.db.AccountViewModel
import com.jerboa.db.AppSettingsViewModel
import com.jerboa.getLocalizedStringForUserTab
import com.jerboa.isScrolledToEnd
import com.jerboa.loginFirstToast
import com.jerboa.openLink
Expand Down Expand Up @@ -206,9 +207,12 @@ fun UserTabs(
showAvatar: Boolean,
) {
val tabTitles = if (savedMode) {
listOf(UserTab.Posts.name, UserTab.Comments.name)
listOf(
getLocalizedStringForUserTab(ctx, UserTab.Posts),
getLocalizedStringForUserTab(ctx, UserTab.Comments),
)
} else {
UserTab.values().map { it.toString() }
UserTab.values().map { getLocalizedStringForUserTab(ctx, it) }
}
val pagerState = rememberPagerState()

Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,7 @@
<string name="look_and_feel_post_view_small_card">Small Card</string>
<string name="look_and_feel_post_view_list">List</string>
<string name="look_and_feel_show_navigation_bar">Zeige Navigationsleiste</string>
<string name="look_and_feel_use_custom_tabs">Angepasste Tabs nutzen</string>
<string name="settings_activity_settings">Einstellungen</string>
<string name="settings_activity_look_and_feel">Look and feel</string>
<string name="settings_activity_account_settings">%1$s Einstellungen</string>
Expand All @@ -207,4 +208,18 @@
<string name="post_listing_permalink_copied">Permalink kopiert</string>
<string name="comment_node_block">Blockiere %1$s</string>
<string name="comment_reply_node_copy_permalink">Kopiere Permalink</string>
<string name="person_profile_activity_about">Über</string>
<string name="person_profile_activity_posts">Beiträge</string>
<string name="person_profile_activity_comments">Kommentare</string>
<string name="sorttype_active">Aktiv</string>
<string name="sorttype_hot">Heiß</string>
<string name="sorttype_new">Neu</string>
<string name="sorttype_old">Alt</string>
<string name="sorttype_topday">Top des Tages</string>
<string name="sorttype_topweek">Top der Woche</string>
<string name="sorttype_topmonth">Top des Monats</string>
<string name="sorttype_topyear">Top des Jahres</string>
<string name="sorttype_topall">Top über alles</string>
<string name="sorttype_mostcomments">Meiste Kommentare</string>
<string name="sorttype_newcomments">Neue Kommentare</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,18 @@
<string name="post_listing_permalink_copied">Permalink copiato</string>
<string name="comment_node_block">Blocca %1$s</string>
<string name="comment_reply_node_copy_permalink">Copia permalink</string>
<string name="person_profile_activity_about">About</string>
<string name="person_profile_activity_posts">Posts</string>
<string name="person_profile_activity_comments">Comments</string>
<string name="sorttype_active">Attivi</string>
<string name="sorttype_hot">Di tendenza</string>
<string name="sorttype_old">Old</string>
<string name="sorttype_new">Nuovi</string>
<string name="sorttype_topday">Top giorno</string>
<string name="sorttype_topweek">Top settimana</string>
<string name="sorttype_topmonth">Top mese</string>
<string name="sorttype_topyear">Top anno</string>
<string name="sorttype_topall">Top di tutti i tempi</string>
<string name="sorttype_mostcomments">Più commenti</string>
<string name="sorttype_newcomments">Nuovi commenti</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -208,4 +208,18 @@
<string name="post_listing_permalink_copied">Permalink gekopieerd</string>
<string name="comment_node_block">%1$s blokkeren</string>
<string name="comment_reply_node_copy_permalink">Permalink kopiëren</string>
<string name="person_profile_activity_about">Over</string>
<string name="person_profile_activity_posts">Berichten</string>
<string name="person_profile_activity_comments">Reacties</string>
<string name="sorttype_active">Actief</string>
<string name="sorttype_hot">Populair</string>
<string name="sorttype_new">Nieuw</string>
<string name="sorttype_old">Oud</string>
<string name="sorttype_topday">TopDag</string>
<string name="sorttype_topweek">TopWeek</string>
<string name="sorttype_topmonth">TopMaand</string>
<string name="sorttype_topyear">TopJaar</string>
<string name="sorttype_topall">TopAlles</string>
<string name="sorttype_mostcomments">Meeste reacties</string>
<string name="sorttype_newcomments">Nieuwste reacties</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,18 @@
<string name="post_listing_permalink_copied">Link da Publicação Copiado</string>
<string name="comment_node_block">Bloquear %1$s</string>
<string name="comment_reply_node_copy_permalink">Copiar Link do Comentário</string>
<string name="person_profile_activity_about">About</string>
<string name="person_profile_activity_posts">Posts</string>
<string name="person_profile_activity_comments">Comments</string>
<string name="sorttype_active">Active</string>
<string name="sorttype_hot">Hot</string>
<string name="sorttype_new">New</string>
<string name="sorttype_old">Old</string>
<string name="sorttype_topday">TopDay</string>
<string name="sorttype_topweek">TopWeek</string>
<string name="sorttype_topmonth">TopMonth</string>
<string name="sorttype_topyear">TopYear</string>
<string name="sorttype_topall">TopAll</string>
<string name="sorttype_mostcomments">MostComments</string>
<string name="sorttype_newcomments">NewComments</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,18 @@
<string name="privateMessage_reply">Reply to message</string>
<string name="voteToggle">Toggle vote</string>
<string name="topAppBar_back">Back</string>
<string name="person_profile_activity_about">About</string>
<string name="person_profile_activity_posts">Posts</string>
<string name="person_profile_activity_comments">Comments</string>
<string name="sorttype_active">Active</string>
<string name="sorttype_hot">Hot</string>
<string name="sorttype_new">New</string>
<string name="sorttype_old">Old</string>
<string name="sorttype_topday">TopDay</string>
<string name="sorttype_topweek">TopWeek</string>
<string name="sorttype_topmonth">TopMonth</string>
<string name="sorttype_topyear">TopYear</string>
<string name="sorttype_topall">TopAll</string>
<string name="sorttype_mostcomments">MostComments</string>
<string name="sorttype_newcomments">NewComments</string>
</resources>

0 comments on commit 89325fc

Please sign in to comment.