diff --git a/composeApp/src/commonMain/composeResources/values/strings-common.xml b/composeApp/src/commonMain/composeResources/values/strings-common.xml index 93e37d50..ca858feb 100644 --- a/composeApp/src/commonMain/composeResources/values/strings-common.xml +++ b/composeApp/src/commonMain/composeResources/values/strings-common.xml @@ -238,48 +238,42 @@ Collapse Expand %1$s ago - - %1$d minute - %1$d minutes - - - %1$d hour - %1$d hours - + %1$d minute + %1$d minutes + %1$d hour + %1$d hours %1$dh %1$dm %1$ds - - January - February - March - April - May - June - July - August - September - October - November - December - + + January + February + March + April + May + June + July + August + September + October + November + December Correct answer Incorrect answer Last updated %1$s - - Run %1$d test - Run %1$d tests - + + Run %1$d test + Run %1$d tests Unsupported URL Measurement - - %1$d measurement - %1$d measurements - + + %1$d measurement + %1$d measurements + Failed OK Anomaly diff --git a/composeApp/src/commonMain/composeResources/values/untraslatable.xml b/composeApp/src/commonMain/composeResources/values/untraslatable.xml index d4ff1224..fea55471 100644 --- a/composeApp/src/commonMain/composeResources/values/untraslatable.xml +++ b/composeApp/src/commonMain/composeResources/values/untraslatable.xml @@ -2,4 +2,38 @@ bugs@openobservatory.org [bug-report] OONI Probe %1$s %1$s: %2$s + + + @string/Common_Minutes_One + @string/Common_Minutes_Other + + + @string/Common_Hour_One + @string/Common_Hour_Other + + + + @string/Dashboard_RunTests_RunButton_Label_One + @string/Dashboard_RunTests_RunButton_Label_Other + + + + @string/Measurements_Count_One + @string/Measurements_Count_Other + + + + @string/Common_Months_January + @string/Common_Months_February + @string/Common_Months_March + @string/Common_Months_April + @string/Common_Months_May + @string/Common_Months_June + @string/Common_Months_July + @string/Common_Months_August + @string/Common_Months_September + @string/Common_Months_October + @string/Common_Months_November + @string/Common_Months_December + diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt new file mode 100644 index 00000000..5453e18b --- /dev/null +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/shared/ResourceExt.kt @@ -0,0 +1,67 @@ +package org.ooni.probe.shared + +import androidx.compose.runtime.Composable +import ooniprobe.composeapp.generated.resources.Common_Hour_One +import ooniprobe.composeapp.generated.resources.Common_Hour_Other +import ooniprobe.composeapp.generated.resources.Common_Minutes_One +import ooniprobe.composeapp.generated.resources.Common_Minutes_Other +import ooniprobe.composeapp.generated.resources.Common_Months_April +import ooniprobe.composeapp.generated.resources.Common_Months_August +import ooniprobe.composeapp.generated.resources.Common_Months_December +import ooniprobe.composeapp.generated.resources.Common_Months_February +import ooniprobe.composeapp.generated.resources.Common_Months_January +import ooniprobe.composeapp.generated.resources.Common_Months_July +import ooniprobe.composeapp.generated.resources.Common_Months_June +import ooniprobe.composeapp.generated.resources.Common_Months_March +import ooniprobe.composeapp.generated.resources.Common_Months_May +import ooniprobe.composeapp.generated.resources.Common_Months_November +import ooniprobe.composeapp.generated.resources.Common_Months_October +import ooniprobe.composeapp.generated.resources.Common_Months_September +import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_RunButton_Label_One +import ooniprobe.composeapp.generated.resources.Dashboard_RunTests_RunButton_Label_Other +import ooniprobe.composeapp.generated.resources.Measurements_Count_One +import ooniprobe.composeapp.generated.resources.Measurements_Count_Other +import ooniprobe.composeapp.generated.resources.Res +import org.jetbrains.compose.resources.PluralStringResource +import org.jetbrains.compose.resources.pluralStringResource +import org.jetbrains.compose.resources.stringResource + +val stringMap = mapOf( + "@string/Common_Minutes_One" to Res.string.Common_Minutes_One, + "@string/Common_Minutes_Other" to Res.string.Common_Minutes_Other, + "@string/Common_Hour_One" to Res.string.Common_Hour_One, + "@string/Common_Hour_Other" to Res.string.Common_Hour_Other, + "@string/Dashboard_RunTests_RunButton_Label_One" to Res.string.Dashboard_RunTests_RunButton_Label_One, + "@string/Dashboard_RunTests_RunButton_Label_Other" to Res.string.Dashboard_RunTests_RunButton_Label_Other, + "@string/Measurements_Count_One" to Res.string.Measurements_Count_One, + "@string/Measurements_Count_Other" to Res.string.Measurements_Count_Other, +) + +@Composable +fun stringMonthArrayResource(): List { + return listOf( + stringResource(Res.string.Common_Months_January), + stringResource(Res.string.Common_Months_February), + stringResource(Res.string.Common_Months_March), + stringResource(Res.string.Common_Months_April), + stringResource(Res.string.Common_Months_May), + stringResource(Res.string.Common_Months_June), + stringResource(Res.string.Common_Months_July), + stringResource(Res.string.Common_Months_August), + stringResource(Res.string.Common_Months_September), + stringResource(Res.string.Common_Months_October), + stringResource(Res.string.Common_Months_November), + stringResource(Res.string.Common_Months_December), + ) +} + +@Composable +fun pluralStringResourceItem( + resource: PluralStringResource, + quantity: Int, + vararg formatArgs: Any, +): String { + return stringMap[pluralStringResource(resource, quantity, formatArgs)]?.let { + return stringResource(it, *formatArgs) + } ?: "" +} diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultCell.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultCell.kt index f8dcdb1d..0ed90f10 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultCell.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultCell.kt @@ -27,10 +27,10 @@ import ooniprobe.composeapp.generated.resources.TaskOrigin_Manual import ooniprobe.composeapp.generated.resources.TestResults_UnknownASN import ooniprobe.composeapp.generated.resources.ic_cloud_off import org.jetbrains.compose.resources.painterResource -import org.jetbrains.compose.resources.pluralStringResource import org.jetbrains.compose.resources.stringResource import org.ooni.engine.models.TaskOrigin import org.ooni.probe.data.models.ResultListItem +import org.ooni.probe.shared.pluralStringResourceItem import org.ooni.probe.ui.dashboard.TestDescriptorLabel import org.ooni.probe.ui.shared.relativeDateTime @@ -115,7 +115,7 @@ fun ResultCell( ) if (!hasError) { Text( - pluralStringResource( + pluralStringResourceItem( Res.plurals.Measurements_Count, item.measurementsCount.toInt(), item.measurementsCount, diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultsScreen.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultsScreen.kt index 59d10032..3053b1ea 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultsScreen.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/results/ResultsScreen.kt @@ -42,7 +42,6 @@ import kotlinx.datetime.LocalDate.Companion.Format import kotlinx.datetime.format import kotlinx.datetime.format.MonthNames import kotlinx.datetime.format.char -import ooniprobe.composeapp.generated.resources.Common_Months import ooniprobe.composeapp.generated.resources.Modal_Cancel import ooniprobe.composeapp.generated.resources.Modal_Delete import ooniprobe.composeapp.generated.resources.Modal_DoYouWantToDeleteAllTests @@ -63,8 +62,8 @@ import ooniprobe.composeapp.generated.resources.ic_download import ooniprobe.composeapp.generated.resources.ic_upload import ooniprobe.composeapp.generated.resources.ooni_empty_state import org.jetbrains.compose.resources.painterResource -import org.jetbrains.compose.resources.stringArrayResource import org.jetbrains.compose.resources.stringResource +import org.ooni.probe.shared.stringMonthArrayResource import org.ooni.probe.ui.shared.TopBar import org.ooni.probe.ui.shared.formatDataUsage import org.ooni.probe.ui.shared.isHeightCompact @@ -316,7 +315,7 @@ private fun Summary(summary: ResultsViewModel.Summary?) { @Composable private fun ResultDateHeader(date: LocalDate) { - val monthNames = stringArrayResource(Res.array.Common_Months) + val monthNames = stringMonthArrayResource() Text( date.format( Format { diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt index 151def90..054ba640 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/run/RunScreen.kt @@ -63,13 +63,13 @@ import ooniprobe.composeapp.generated.resources.ic_keyboard_arrow_down import ooniprobe.composeapp.generated.resources.ic_keyboard_arrow_up import ooniprobe.composeapp.generated.resources.ic_timer import org.jetbrains.compose.resources.painterResource -import org.jetbrains.compose.resources.pluralStringResource import org.jetbrains.compose.resources.stringResource import org.ooni.engine.models.TestType import org.ooni.probe.config.OrganizationConfig import org.ooni.probe.config.TestDisplayMode import org.ooni.probe.data.models.Descriptor import org.ooni.probe.data.models.NetTest +import org.ooni.probe.shared.pluralStringResourceItem import org.ooni.probe.ui.dashboard.TestDescriptorLabel import org.ooni.probe.ui.dashboard.TestDescriptorSection import org.ooni.probe.ui.shared.ParentSelectableItem @@ -189,7 +189,7 @@ fun RunScreen( .padding(WindowInsets.navigationBars.asPaddingValues()), ) { Text( - text = pluralStringResource( + text = pluralStringResourceItem( Res.plurals.Dashboard_RunTests_RunButton_Label, selectedTestsCount, selectedTestsCount, diff --git a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/shared/DateFormats.kt b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/shared/DateFormats.kt index 15eccc41..e37f1172 100644 --- a/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/shared/DateFormats.kt +++ b/composeApp/src/commonMain/kotlin/org/ooni/probe/ui/shared/DateFormats.kt @@ -15,8 +15,8 @@ import ooniprobe.composeapp.generated.resources.Common_Minutes import ooniprobe.composeapp.generated.resources.Common_Minutes_Abbreviated import ooniprobe.composeapp.generated.resources.Common_Seconds_Abbreviated import ooniprobe.composeapp.generated.resources.Res -import org.jetbrains.compose.resources.pluralStringResource import org.jetbrains.compose.resources.stringResource +import org.ooni.probe.shared.pluralStringResourceItem import org.ooni.probe.shared.today import kotlin.time.Duration @@ -44,9 +44,9 @@ fun LocalDateTime.relativeDateTime(): String = val diff = (Clock.System.now() - toInstant(TimeZone.currentSystemDefault())) val diffString = diff.toComponents { hours, minutes, _, _ -> if (hours > 0) { - pluralStringResource(Res.plurals.Common_Hours, hours.toInt(), hours.toInt()) + pluralStringResourceItem(Res.plurals.Common_Hours, hours.toInt(), hours.toInt()) } else { - pluralStringResource(Res.plurals.Common_Minutes, minutes, minutes) + pluralStringResourceItem(Res.plurals.Common_Minutes, minutes, minutes) } } stringResource(Res.string.Common_Ago, diffString)