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

chore: update translation strings #320

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -238,48 +238,42 @@
<string name="Common_Collapse">Collapse</string>
<string name="Common_Expand">Expand</string>
<string name="Common_Ago">%1$s ago</string>
<plurals name="Common_Minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<plurals name="Common_Hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d hours</item>
</plurals>
<string name="Common_Minutes_One">%1$d minute</string>
<string name="Common_Minutes_Other">%1$d minutes</string>
<string name="Common_Hour_One">%1$d hour</string>
<string name="Common_Hour_Other">%1$d hours</string>
<string name="Common_Hours_Abbreviated">%1$dh</string>
<string name="Common_Minutes_Abbreviated">%1$dm</string>
<string name="Common_Seconds_Abbreviated">%1$ds</string>
<string-array name="Common_Months">
<item>January</item>
<item>February</item>
<item>March</item>
<item>April</item>
<item>May</item>
<item>June</item>
<item>July</item>
<item>August</item>
<item>September</item>
<item>October</item>
<item>November</item>
<item>December</item>
</string-array>

<string name="Common_Months_January">January</string>
<string name="Common_Months_February">February</string>
<string name="Common_Months_March">March</string>
<string name="Common_Months_April">April</string>
<string name="Common_Months_May">May</string>
<string name="Common_Months_June">June</string>
<string name="Common_Months_July">July</string>
<string name="Common_Months_August">August</string>
<string name="Common_Months_September">September</string>
<string name="Common_Months_October">October</string>
<string name="Common_Months_November">November</string>
<string name="Common_Months_December">December</string>

<string name="Onboarding_QuizAnswer_Correct">Correct answer</string>
<string name="Onboarding_QuizAnswer_Incorrect">Incorrect answer</string>

<string name="Dashboard_Runv2_Overview_LastUpdated">Last updated %1$s</string>
<plurals name="Dashboard_RunTests_RunButton_Label">
<item quantity="one">Run %1$d test</item>
<item quantity="other">Run %1$d tests</item>
</plurals>

<string name="Dashboard_RunTests_RunButton_Label_One">Run %1$d test</string>
<string name="Dashboard_RunTests_RunButton_Label_Other">Run %1$d tests</string>

<string name="AddDescriptor_Toasts_Unsupported_Url">Unsupported URL</string>

<string name="Measurement_Title">Measurement</string>
<plurals name="Measurements_Count">
<item quantity="one">%1$d measurement</item>
<item quantity="other">%1$d measurements</item>
</plurals>

<string name="Measurements_Count_One">%1$d measurement</string>
<string name="Measurements_Count_Other">%1$d measurements</string>

<string name="Measurements_Failed">Failed</string>
<string name="Measurements_Ok">OK</string>
<string name="Measurements_Anomaly">Anomaly</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,38 @@
<string name="shareEmailTo" translatable="false">[email protected]</string>
<string name="shareSubject" translatable="false">[bug-report] OONI Probe %1$s</string>
<string name="version" translatable="false">%1$s: %2$s</string>

<plurals name="Common_Minutes" translatable="false">
<item quantity="one">@string/Common_Minutes_One</item>
<item quantity="other">@string/Common_Minutes_Other</item>
</plurals>
<plurals name="Common_Hours" translatable="false">
<item quantity="one">@string/Common_Hour_One</item>
<item quantity="other">@string/Common_Hour_Other</item>
</plurals>

<plurals name="Dashboard_RunTests_RunButton_Label" translatable="false">
<item quantity="one">@string/Dashboard_RunTests_RunButton_Label_One</item>
<item quantity="other">@string/Dashboard_RunTests_RunButton_Label_Other</item>
</plurals>

<plurals name="Measurements_Count" translatable="false">
<item quantity="one">@string/Measurements_Count_One</item>
<item quantity="other">@string/Measurements_Count_Other</item>
</plurals>

<string-array name="Common_Months" translatable="false">
<item>@string/Common_Months_January</item>
<item>@string/Common_Months_February</item>
<item>@string/Common_Months_March</item>
<item>@string/Common_Months_April</item>
<item>@string/Common_Months_May</item>
<item>@string/Common_Months_June</item>
<item>@string/Common_Months_July</item>
<item>@string/Common_Months_August</item>
<item>@string/Common_Months_September</item>
<item>@string/Common_Months_October</item>
<item>@string/Common_Months_November</item>
<item>@string/Common_Months_December</item>
</string-array>
</resources>
Original file line number Diff line number Diff line change
@@ -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<String> {
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)
} ?: ""
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -115,7 +115,7 @@ fun ResultCell(
)
if (!hasError) {
Text(
pluralStringResource(
pluralStringResourceItem(
Res.plurals.Measurements_Count,
item.measurementsCount.toInt(),
item.measurementsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -189,7 +189,7 @@ fun RunScreen(
.padding(WindowInsets.navigationBars.asPaddingValues()),
) {
Text(
text = pluralStringResource(
text = pluralStringResourceItem(
Res.plurals.Dashboard_RunTests_RunButton_Label,
selectedTestsCount,
selectedTestsCount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down