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

Prepare new strings #318

Merged
merged 2 commits 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 @@ -7,7 +7,6 @@ import androidx.compose.ui.test.assertIsNotDisplayed
import androidx.compose.ui.test.hasText
import androidx.compose.ui.test.isDisplayed
import androidx.compose.ui.test.junit4.createEmptyComposeRule
import androidx.compose.ui.test.onAllNodesWithText
import androidx.compose.ui.test.onLast
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import kotlinx.coroutines.flow.first
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Running
import ooniprobe.composeapp.generated.resources.Notification_ChannelName
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.notification_channel_name
import org.jetbrains.compose.resources.getString
import org.ooni.probe.AndroidApplication
import org.ooni.probe.R
Expand Down Expand Up @@ -79,7 +79,7 @@ class DescriptorUpdateWorker(
notificationManager.createNotificationChannel(
NotificationChannel(
NOTIFICATION_CHANNEL_ID,
getString(Res.string.notification_channel_name),
getString(Res.string.Notification_ChannelName),
NotificationManager.IMPORTANCE_DEFAULT,
),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import kotlinx.serialization.encodeToString
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Running
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Stopping_Notice
import ooniprobe.composeapp.generated.resources.Dashboard_Running_Stopping_Title
import ooniprobe.composeapp.generated.resources.Notification_ChannelName
import ooniprobe.composeapp.generated.resources.Notification_StopTest
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.UploadingMissingResults
import ooniprobe.composeapp.generated.resources.notification_channel_name
import ooniprobe.composeapp.generated.resources.Results_UploadingMissing
import org.jetbrains.compose.resources.getString
import org.ooni.probe.AndroidApplication
import org.ooni.probe.MainActivity
Expand Down Expand Up @@ -130,7 +130,7 @@ class RunWorker(
notificationManager.createNotificationChannel(
NotificationChannel(
NOTIFICATION_CHANNEL_ID,
getString(Res.string.notification_channel_name),
getString(Res.string.Notification_ChannelName),
NotificationManager.IMPORTANCE_LOW,
),
)
Expand All @@ -143,7 +143,7 @@ class RunWorker(
val progress = state.uploaded + state.failedToUpload + 1
setContentText(
getString(
Res.string.UploadingMissingResults,
Res.string.Results_UploadingMissing,
"$progress/${state.total}",
),
)
Expand Down
120 changes: 61 additions & 59 deletions composeApp/src/commonMain/composeResources/values/strings-common.xml
Original file line number Diff line number Diff line change
Expand Up @@ -232,69 +232,71 @@
<string name="Modal_Autorun_BatteryOptimization">OONI Probe cannot run automatically without battery optimization. Do you want to try again?</string>

<!-- New Strings -->
<string name="Dashboard_Runv2_Overview_LastUpdatd">Last updated %1$s</string>
<string name="back">Back</string>
<string name="refresh">refresh</string>
<string name="measurement">Measurement</string>
<plurals name="measurements_count">
<item quantity="one">%1$d measurement</item>
<item quantity="other">%1$d measurements</item>
</plurals>
<string-array name="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="ago">%1$s ago</string>
<plurals name="minutes">
<item quantity="one">%1$d minute</item>
<item quantity="other">%1$d minutes</item>
</plurals>
<plurals name="hours">
<item quantity="one">%1$d hour</item>
<item quantity="other">%1$d hours</item>
</plurals>
<string name="hours_abbreviated">%1$dh</string>
<string name="minutes_abbreviated">%1$dm</string>
<string name="seconds_abbreviated">%1$ds</string>
<string name="notification_channel_name">Testing</string>
<string name="task_origin_manual">Manual Run</string>
<string name="task_origin_auto_run">Auto Run</string>
<string name="collapse">Collapse</string>
<string name="expand">Expand</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="test_type_all">All Types</string>
<string name="task_origin_all">All Sources</string>
<string name="vpn">VPN</string>
<string name="disable_vpn_instructions">Go to Settings > General > VPN and disconnect from your VPN.</string>
<string name="measurement_failed">Failed</string>
<string name="measurement_ok">OK</string>
<string name="measurement_anomaly">Anomaly</string>
<string name="quiz_answer_correct">Correct answer</string>
<string name="quiz_answer_incorrect">Incorrect answer</string>
<string name="logs">Logs</string>
<string name="share_logs">Share Logs</string>
<string name="share_logs_error">Error sharing logs</string>
<string name="filter_logs">Filter Logs</string>
<string name="results_limited_notice">Only the last %1$d results are shown</string>
<string name="auto_test_not_uploaded_limit">Skip after this amount of results failed to upload</string>

<string name="Common_Back">Back</string>
<string name="Common_Refresh">refresh</string>
<string name="Common_Collapse">Collapse</string>
<string name="Common_Expand">Expand</string>
<string name="Common_Ago">%1$s ago</string>
<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 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>

<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>

<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>

<string name="Results_TestType_All">All Types</string>
<string name="Results_TaskOrigin_All">All Sources</string>
<string name="Results_LimitedNotice">Only the last %1$d results are shown</string>
<string name="Results_UploadingMissing">Uploading missing results %1$s</string>

<string name="Settings_Logs">Logs</string>
<string name="Settings_ShareLogs">Share Logs</string>
<string name="Settings_ShareLogs_Error">Error sharing logs</string>
<string name="Settings_FilterLogs">Filter Logs</string>
<string name="Settings_DisableVpnInstructions">Go to Settings > General > VPN and disconnect from your VPN.</string>
<string name="Settings_AutoTest_NotUploadedLimit">Skip after this amount of results failed to upload</string>
<string name="Settings_Sharing_UploadResults_Description">Results are automatically uploaded to OONI explorer</string>
<string name="Settings_Websites_MaxRuntimeEnabled_New">Limit Websites test duration</string>
<string name="Settings_Websites_MaxRuntime_New">Maximum Websites test duration</string>
<string name="Settings_AutomatedTesting_RunAutomatically_Description">Tests will run every hour in the background</string>
<string name="Settings_Websites_MaxRuntimeEnabled_Description">Only for manual runs</string>
<string name="UploadingMissingResults">Uploading missing results %1$s</string>

<string name="Notification_ChannelName">Testing</string>
<string name="TaskOrigin_Manual">Manual Run</string>
<string name="TaskOrigin_AutoRun">Auto Run</string>
<string name="NetworkType_Vpn">VPN</string>
</resources>
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
Expand Up @@ -2,24 +2,24 @@ package org.ooni.probe.data.models

import co.touchlab.kermit.Logger
import kotlinx.datetime.LocalDateTime
import kotlinx.datetime.LocalDateTime.Companion.Format
import kotlinx.datetime.format
import kotlinx.datetime.format.MonthNames
import kotlinx.datetime.format.char
import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import ooniprobe.composeapp.generated.resources.Common_Months
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_Description
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_LastUpdated
import ooniprobe.composeapp.generated.resources.Res
import org.jetbrains.compose.resources.stringResource
import kotlinx.datetime.LocalDateTime.Companion.Format
import kotlinx.datetime.format
import kotlinx.datetime.format.MonthNames
import kotlinx.datetime.format.char
import ooniprobe.composeapp.generated.resources.Dashboard_Runv2_Overview_LastUpdatd
import ooniprobe.composeapp.generated.resources.months
import ooniprobe.composeapp.generated.resources.test_circumvention
import ooniprobe.composeapp.generated.resources.test_experimental
import ooniprobe.composeapp.generated.resources.test_instant_messaging
import ooniprobe.composeapp.generated.resources.test_performance
import ooniprobe.composeapp.generated.resources.test_websites
import org.jetbrains.compose.resources.stringArrayResource
import org.jetbrains.compose.resources.stringResource
import org.ooni.probe.data.TestDescriptor
import org.ooni.probe.shared.InstalledDescriptorIcons
import org.ooni.probe.shared.hexToColor
Expand Down Expand Up @@ -65,15 +65,15 @@ fun InstalledTestDescriptorModel.toDescriptor(updateStatus: UpdateStatus = Updat
shortDescription = { shortDescriptionIntl?.getCurrent() ?: shortDescription },
description = { descriptionIntl?.getCurrent() ?: description },
metadata = {
val monthNames = stringArrayResource(Res.array.months)
val monthNames = stringArrayResource(Res.array.Common_Months)
val formattedDate = { date: LocalDateTime? -> date?.format(dateTimeFormat(monthNames)) }
formattedDate(dateCreated)?.let { formattedDateCreated ->
stringResource(
Res.string.Dashboard_Runv2_Overview_Description,
author.orEmpty(),
formattedDateCreated,
) + ". " + formattedDate(dateUpdated)?.let {
stringResource(Res.string.Dashboard_Runv2_Overview_LastUpdatd, it)
stringResource(Res.string.Dashboard_Runv2_Overview_LastUpdated, it)
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import ooniprobe.composeapp.generated.resources.Settings_About_Label
import ooniprobe.composeapp.generated.resources.Settings_Advanced_DebugLogs
import ooniprobe.composeapp.generated.resources.Settings_Advanced_Label
import ooniprobe.composeapp.generated.resources.Settings_Advanced_RecentLogs
import ooniprobe.composeapp.generated.resources.Settings_AutoTest_NotUploadedLimit
import ooniprobe.composeapp.generated.resources.Settings_AutomatedTesting_RunAutomatically
import ooniprobe.composeapp.generated.resources.Settings_AutomatedTesting_RunAutomatically_ChargingOnly
import ooniprobe.composeapp.generated.resources.Settings_AutomatedTesting_RunAutomatically_Description
Expand All @@ -49,7 +50,6 @@ import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntimeEnab
import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntimeEnabled_New
import ooniprobe.composeapp.generated.resources.Settings_Websites_MaxRuntime_New
import ooniprobe.composeapp.generated.resources.advanced
import ooniprobe.composeapp.generated.resources.auto_test_not_uploaded_limit
import ooniprobe.composeapp.generated.resources.ic_settings
import ooniprobe.composeapp.generated.resources.notifications
import ooniprobe.composeapp.generated.resources.outline_info
Expand Down Expand Up @@ -179,7 +179,7 @@ class GetSettings(
indentation = 1,
),
SettingsItem(
title = Res.string.auto_test_not_uploaded_limit,
title = Res.string.Settings_AutoTest_NotUploadedLimit,
key = SettingsKey.AUTOMATED_TESTING_NOT_UPLOADED_LIMIT,
type = PreferenceItemType.INT,
enabled = autoRunEnabled && uploadResultsEnabled,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package org.ooni.probe.domain

import okio.Path
import ooniprobe.composeapp.generated.resources.Res
import ooniprobe.composeapp.generated.resources.logs
import ooniprobe.composeapp.generated.resources.Settings_Logs
import org.jetbrains.compose.resources.getString
import org.ooni.probe.data.models.PlatformAction

Expand All @@ -13,7 +13,7 @@ class ShareLogFile(
suspend operator fun invoke(): Boolean =
shareFile(
PlatformAction.FileSharing(
title = getString(Res.string.logs),
title = getString(Res.string.Settings_Logs),
filePath = getAppLoggerFile(),
),
)
Expand Down
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)
} ?: ""
}
Loading