Skip to content

Commit

Permalink
Changed word/minutes to plural strings
Browse files Browse the repository at this point in the history
  • Loading branch information
spacecowboy committed Nov 25, 2023
1 parent d1d7b1a commit 8433be8
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.style.TextOverflow
Expand Down Expand Up @@ -289,12 +290,14 @@ fun RowScope.FeedItemText(
}
if (readTimeSecs > 0) {
CompositionLocalProvider(LocalContentAlpha provides ContentAlpha.medium) {
val readTimeText = stringResource(
id = R.string.n_reading_time,
readTimeSecs / 60,
readTimeSecs % 60,
)
val wordCountText = stringResource(id = R.string.n_words_short, item.wordCount)
val readTimeText =
pluralStringResource(id = R.plurals.n_minutes, count = readTimeSecs / 60)
.format(
"${readTimeSecs / 60}:${readTimeSecs % 60}",
)
val wordCountText =
pluralStringResource(id = R.plurals.n_words, count = item.wordCount)
.format(item.wordCount)
Row(
horizontalArrangement = Arrangement.spacedBy(4.dp),
modifier = Modifier
Expand Down Expand Up @@ -343,7 +346,7 @@ private fun Preview() {
feedImageUrl = null,
primarySortTime = Instant.EPOCH,
rawPubDate = null,
wordCount = 900,
wordCount = 588,
),
showThumbnail = true,
onMarkAboveAsRead = {},
Expand Down Expand Up @@ -381,7 +384,7 @@ private fun PreviewWithImageUnread() {
feedImageUrl = URL("https://foo/bar.png"),
primarySortTime = Instant.EPOCH,
rawPubDate = null,
wordCount = 900,
wordCount = 939,
),
showThumbnail = true,
onMarkAboveAsRead = {},
Expand Down Expand Up @@ -420,7 +423,7 @@ private fun PreviewWithImageRead() {
feedImageUrl = null,
primarySortTime = Instant.EPOCH,
rawPubDate = null,
wordCount = 900,
wordCount = 950,
),
showThumbnail = true,
onMarkAboveAsRead = {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.pluralStringResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.CustomAccessibilityAction
import androidx.compose.ui.semantics.clearAndSetSemantics
Expand Down Expand Up @@ -193,11 +194,11 @@ fun ReaderView(
imageVector = Icons.Outlined.Timelapse,
contentDescription = null,
)
val readTimeText = stringResource(
id = R.string.n_reading_time,
readTimeSecs / 60,
readTimeSecs % 60,
)
val readTimeText =
pluralStringResource(id = R.plurals.n_minutes, count = readTimeSecs / 60)
.format(
"${readTimeSecs / 60}:${readTimeSecs % 60}",
)
WithBidiDeterminedLayoutDirection(paragraph = readTimeText) {
val interactionSource =
remember { MutableInteractionSource() }
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,5 @@
<string name="theme_e_ink">Läsplatta</string>
<string name="add_anyway">Lägg till ändå</string>
<string name="open_browser_in_split_screen">Öppna webbläsare i delad skärm</string>
<string name="n_words_short">%1$d ord</string>
<string name="n_reading_time">%1$d minuter %2$d sekunder</string>
<string name="show_reading_time">Visa uppskattad lästid</string>
</resources>
16 changes: 16 additions & 0 deletions app/src/main/res/values/plural_strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,20 @@
<item quantity="many">@string/many_tags</item>
<item quantity="other">@string/other_tags</item>
</plurals>
<plurals name="n_words">
<item quantity="zero">@string/zero_words</item>
<item quantity="one">@string/one_word</item>
<item quantity="two">@string/two_words</item>
<item quantity="few">@string/few_words</item>
<item quantity="many">@string/many_words</item>
<item quantity="other">@string/other_words</item>
</plurals>
<plurals name="n_minutes">
<item quantity="zero">@string/zero_minutes</item>
<item quantity="one">@string/one_minute</item>
<item quantity="two">@string/two_minutes</item>
<item quantity="few">@string/few_minutes</item>
<item quantity="many">@string/many_minutes</item>
<item quantity="other">@string/other_minutes</item>
</plurals>
</resources>
14 changes: 12 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,17 @@
<string name="no_url">No URL</string>
<string name="add_anyway">Add anyway</string>
<string name="open_browser_in_split_screen">Open browser in split screen</string>
<string name="n_words_short">%1$d words</string>
<string name="n_reading_time">%1$d minutes %2$d seconds</string>
<string name="show_reading_time">Show estimated reading time</string>
<string name="zero_words">%1$s words</string>
<string name="one_word">%1$s word</string>
<string name="two_words">%1$s words</string>
<string name="few_words">%1$s words</string>
<string name="many_words">%1$s words</string>
<string name="other_words">%1$s words</string>
<string name="zero_minutes">%1$s minutes</string>
<string name="one_minute">%1$s minute</string>
<string name="two_minutes">%1$s minutes</string>
<string name="few_minutes">%1$s minutes</string>
<string name="many_minutes">%1$s minutes</string>
<string name="other_minutes">%1$s minutes</string>
</resources>

0 comments on commit 8433be8

Please sign in to comment.