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

Localization of user tabs #563

Merged
merged 4 commits into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
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 @@ -247,7 +249,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 @@ -204,9 +205,12 @@ fun UserTabs(
enableDownVotes: 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 @@ -208,4 +208,18 @@
<string name="post_listing_permalink_copied">Permalink Copied</string>
<string name="comment_node_block">Block %1$s</string>
<string name="comment_reply_node_copy_permalink">Copy 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">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>