Commit 07a00e11 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

[Nearby] Add ICU syntax to notification titles

Some languages need a different translation if the attachments part of
the message is plural vs singular. This changes those messages to use
ICU syntax to allow different translations based on the count.

Skipping screenshot check as there are no changes to the current ones.

Bug: b/162851946, b/162948024, b/162872467
Change-Id: I892bae4766dc4cb727a7b6b319e456eabaae9dc8
Skip-Translation-Screenshots-Check: True
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2343064Reviewed-by: default avatarMichael van Ouwerkerk <mvanouwerkerk@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#795878}
parent 2c48b988
...@@ -35,7 +35,9 @@ ...@@ -35,7 +35,9 @@
<!-- Notification strings --> <!-- Notification strings -->
<message name="IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_MESSAGE" desc="Text shown as the message of a notfication when a nearby device requests a connection via Nearby Share."> <message name="IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_MESSAGE" desc="Text shown as the message of a notfication when a nearby device requests a connection via Nearby Share.">
<ph name="DEVICE_NAME">$1<ex>Ted's Pixel 2</ex></ph> is sharing <ph name="ATTACHMENTS">$2<ex>3 items</ex></ph> with you. {COUNT, plural,
=1 {<ph name="DEVICE_NAME">$1<ex>Ted's Pixel 2</ex></ph> is sharing <ph name="ATTACHMENTS">$2<ex>1 item</ex></ph> with you.}
other {<ph name="DEVICE_NAME">$1<ex>Ted's Pixel 2</ex></ph> is sharing <ph name="ATTACHMENTS">$2<ex>3 items</ex></ph> with you.}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_TITLE" desc="Text shown as the title of a notfication when a nearby device requests a connection via Nearby Share."> <message name="IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_TITLE" desc="Text shown as the title of a notfication when a nearby device requests a connection via Nearby Share.">
Receive with Nearby Share? Receive with Nearby Share?
...@@ -53,22 +55,34 @@ ...@@ -53,22 +55,34 @@
Receive Receive
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE" desc="Text shown as the title of a notfication when receiving data via Nearby Share failed."> <message name="IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE" desc="Text shown as the title of a notfication when receiving data via Nearby Share failed.">
Failed to receive <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph> {COUNT, plural,
=1 {Failed to receive <ph name="ATTACHMENTS">$1<ex>1 item</ex></ph> from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}
other {Failed to receive <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_RECEIVE_PROGRESS_TITLE" desc="Text shown as the title of a notfication when receiving data via Nearby Share."> <message name="IDS_NEARBY_NOTIFICATION_RECEIVE_PROGRESS_TITLE" desc="Text shown as the title of a notfication when receiving data via Nearby Share.">
Receiving <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph> {COUNT, plural,
=1 {Receiving <ph name="ATTACHMENTS">$1<ex>1 item</ex></ph> from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}
other {Receiving <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_RECEIVE_SUCCESS_TITLE" desc="Text shown as the title of a notfication when data was sucessfully received via Nearby Share."> <message name="IDS_NEARBY_NOTIFICATION_RECEIVE_SUCCESS_TITLE" desc="Text shown as the title of a notfication when data was sucessfully received via Nearby Share.">
<ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> received from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph> {COUNT, plural,
=1 {<ph name="ATTACHMENTS">$1<ex>1 item</ex></ph> received from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}
other {<ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> received from <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE" desc="Text shown as the title of a notfication when sending data via Nearby Share failed."> <message name="IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE" desc="Text shown as the title of a notfication when sending data via Nearby Share failed.">
Failed to send <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph> {COUNT, plural,
=1 {Failed to send <ph name="ATTACHMENTS">$1<ex>1 item</ex></ph> to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}
other {Failed to send <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE" desc="Text shown as the title of a notfication when sending data via Nearby Share."> <message name="IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE" desc="Text shown as the title of a notfication when sending data via Nearby Share.">
Sending <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph> {COUNT, plural,
=1 {Sending <ph name="ATTACHMENTS">$1<ex>1 item</ex></ph> to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}
other {Sending <ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_SEND_SUCCESS_TITLE" desc="Text shown as the title of a notfication when data was successfully sent via Nearby Share."> <message name="IDS_NEARBY_NOTIFICATION_SEND_SUCCESS_TITLE" desc="Text shown as the title of a notfication when data was successfully sent via Nearby Share.">
<ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> successfully sent to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph> {COUNT, plural,
=1 {<ph name="ATTACHMENTS">$1<ex>1 item</ex></ph> successfully sent to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}
other {<ph name="ATTACHMENTS">$1<ex>3 items</ex></ph> successfully sent to <ph name="DEVICE_NAME">$2<ex>Ted's Pixel 2</ex></ph>}}
</message> </message>
<message name="IDS_NEARBY_NOTIFICATION_SOURCE" desc="Text shown as the source of a Nearby Share notification."> <message name="IDS_NEARBY_NOTIFICATION_SOURCE" desc="Text shown as the source of a Nearby Share notification.">
Nearby Share Nearby Share
......
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "base/notreached.h" #include "base/notreached.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string16.h" #include "base/strings/string16.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "build/build_config.h" #include "build/build_config.h"
#include "chrome/app/vector_icons/vector_icons.h" #include "chrome/app/vector_icons/vector_icons.h"
...@@ -123,34 +124,37 @@ base::string16 GetAttachmentsString(const ShareTarget& share_target) { ...@@ -123,34 +124,37 @@ base::string16 GetAttachmentsString(const ShareTarget& share_target) {
return l10n_util::GetPluralStringFUTF16(resource_id, text_count + file_count); return l10n_util::GetPluralStringFUTF16(resource_id, text_count + file_count);
} }
base::string16 GetProgressNotificationTitle(const ShareTarget& share_target) { base::string16 FormatNotificationTitle(const ShareTarget& share_target,
int resource_id = share_target.is_incoming int resource_id) {
? IDS_NEARBY_NOTIFICATION_RECEIVE_PROGRESS_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE;
base::string16 attachments = GetAttachmentsString(share_target); base::string16 attachments = GetAttachmentsString(share_target);
base::string16 device_name = base::ASCIIToUTF16(share_target.device_name); base::string16 device_name = base::ASCIIToUTF16(share_target.device_name);
size_t attachment_count = share_target.file_attachments.size() +
share_target.text_attachments.size();
return base::ReplaceStringPlaceholders(
l10n_util::GetPluralStringFUTF16(resource_id, attachment_count),
{attachments, device_name}, /*offsets=*/nullptr);
}
return l10n_util::GetStringFUTF16(resource_id, attachments, device_name); base::string16 GetProgressNotificationTitle(const ShareTarget& share_target) {
return FormatNotificationTitle(
share_target, share_target.is_incoming
? IDS_NEARBY_NOTIFICATION_RECEIVE_PROGRESS_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE);
} }
base::string16 GetSuccessNotificationTitle(const ShareTarget& share_target) { base::string16 GetSuccessNotificationTitle(const ShareTarget& share_target) {
int resource_id = share_target.is_incoming return FormatNotificationTitle(
share_target, share_target.is_incoming
? IDS_NEARBY_NOTIFICATION_RECEIVE_SUCCESS_TITLE ? IDS_NEARBY_NOTIFICATION_RECEIVE_SUCCESS_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_SUCCESS_TITLE; : IDS_NEARBY_NOTIFICATION_SEND_SUCCESS_TITLE);
base::string16 attachments = GetAttachmentsString(share_target);
base::string16 device_name = base::ASCIIToUTF16(share_target.device_name);
return l10n_util::GetStringFUTF16(resource_id, attachments, device_name);
} }
base::string16 GetFailureNotificationTitle(const ShareTarget& share_target) { base::string16 GetFailureNotificationTitle(const ShareTarget& share_target) {
int resource_id = share_target.is_incoming return FormatNotificationTitle(
share_target, share_target.is_incoming
? IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE ? IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE; : IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE);
base::string16 attachments = GetAttachmentsString(share_target);
base::string16 device_name = base::ASCIIToUTF16(share_target.device_name);
return l10n_util::GetStringFUTF16(resource_id, attachments, device_name);
} }
base::string16 GetConnectionRequestNotificationMessage( base::string16 GetConnectionRequestNotificationMessage(
...@@ -159,9 +163,12 @@ base::string16 GetConnectionRequestNotificationMessage( ...@@ -159,9 +163,12 @@ base::string16 GetConnectionRequestNotificationMessage(
base::string16 attachments = GetAttachmentsString(share_target); base::string16 attachments = GetAttachmentsString(share_target);
base::string16 device_name = base::ASCIIToUTF16(share_target.device_name); base::string16 device_name = base::ASCIIToUTF16(share_target.device_name);
base::string16 message = l10n_util::GetStringFUTF16( size_t attachment_count = share_target.file_attachments.size() +
IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_MESSAGE, device_name, share_target.text_attachments.size();
attachments); base::string16 message = base::ReplaceStringPlaceholders(
l10n_util::GetPluralStringFUTF16(
IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_MESSAGE, attachment_count),
{device_name, attachments}, /*offsets=*/nullptr);
if (transfer_metadata.token()) { if (transfer_metadata.token()) {
base::string16 token = l10n_util::GetStringFUTF16( base::string16 token = l10n_util::GetStringFUTF16(
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <vector> #include <vector>
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
...@@ -158,6 +159,18 @@ class NearbyNotificationManagerConnectionRequestTest ...@@ -158,6 +159,18 @@ class NearbyNotificationManagerConnectionRequestTest
: public NearbyNotificationManagerTest, : public NearbyNotificationManagerTest,
public testing::WithParamInterface<ConnectionRequestTestParam> {}; public testing::WithParamInterface<ConnectionRequestTestParam> {};
base::string16 FormatNotificationTitle(
int resource_id,
const AttachmentsTestParamInternal& param,
const std::string& device_name) {
size_t total = param.text_attachments.size() + param.file_attachments.size();
return base::ReplaceStringPlaceholders(
l10n_util::GetPluralStringFUTF16(resource_id, total),
{l10n_util::GetPluralStringFUTF16(param.expected_resource_id, total),
base::ASCIIToUTF16(device_name)},
/*offsets=*/nullptr);
}
} // namespace } // namespace
TEST_F(NearbyNotificationManagerTest, RegistersAsBackgroundSurfaces) { TEST_F(NearbyNotificationManagerTest, RegistersAsBackgroundSurfaces) {
...@@ -277,14 +290,10 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowProgress) { ...@@ -277,14 +290,10 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowProgress) {
TransferMetadata transfer_metadata = TransferMetadataBuilder().build(); TransferMetadata transfer_metadata = TransferMetadataBuilder().build();
manager()->ShowProgress(share_target, transfer_metadata); manager()->ShowProgress(share_target, transfer_metadata);
int expected_resource_id = base::string16 expected = FormatNotificationTitle(
is_incoming ? IDS_NEARBY_NOTIFICATION_RECEIVE_PROGRESS_TITLE is_incoming ? IDS_NEARBY_NOTIFICATION_RECEIVE_PROGRESS_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE; : IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE,
size_t total = param.text_attachments.size() + param.file_attachments.size(); param, device_name);
base::string16 expected = l10n_util::GetStringFUTF16(
expected_resource_id,
l10n_util::GetPluralStringFUTF16(param.expected_resource_id, total),
base::ASCIIToUTF16(device_name));
std::vector<message_center::Notification> notifications = std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(); GetDisplayedNotifications();
...@@ -311,14 +320,10 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowSuccess) { ...@@ -311,14 +320,10 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowSuccess) {
manager()->ShowSuccess(share_target); manager()->ShowSuccess(share_target);
int expected_resource_id = is_incoming base::string16 expected = FormatNotificationTitle(
? IDS_NEARBY_NOTIFICATION_RECEIVE_SUCCESS_TITLE is_incoming ? IDS_NEARBY_NOTIFICATION_RECEIVE_SUCCESS_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_SUCCESS_TITLE; : IDS_NEARBY_NOTIFICATION_SEND_SUCCESS_TITLE,
size_t total = param.text_attachments.size() + param.file_attachments.size(); param, device_name);
base::string16 expected = l10n_util::GetStringFUTF16(
expected_resource_id,
l10n_util::GetPluralStringFUTF16(param.expected_resource_id, total),
base::ASCIIToUTF16(device_name));
std::vector<message_center::Notification> notifications = std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(); GetDisplayedNotifications();
...@@ -345,14 +350,10 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowFailure) { ...@@ -345,14 +350,10 @@ TEST_P(NearbyNotificationManagerAttachmentsTest, ShowFailure) {
manager()->ShowFailure(share_target); manager()->ShowFailure(share_target);
int expected_resource_id = is_incoming base::string16 expected = FormatNotificationTitle(
? IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE is_incoming ? IDS_NEARBY_NOTIFICATION_RECEIVE_FAILURE_TITLE
: IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE; : IDS_NEARBY_NOTIFICATION_SEND_FAILURE_TITLE,
size_t total = param.text_attachments.size() + param.file_attachments.size(); param, device_name);
base::string16 expected = l10n_util::GetStringFUTF16(
expected_resource_id,
l10n_util::GetPluralStringFUTF16(param.expected_resource_id, total),
base::ASCIIToUTF16(device_name));
std::vector<message_center::Notification> notifications = std::vector<message_center::Notification> notifications =
GetDisplayedNotifications(); GetDisplayedNotifications();
...@@ -397,11 +398,14 @@ TEST_P(NearbyNotificationManagerConnectionRequestTest, ...@@ -397,11 +398,14 @@ TEST_P(NearbyNotificationManagerConnectionRequestTest,
base::string16 expected_title = l10n_util::GetStringUTF16( base::string16 expected_title = l10n_util::GetStringUTF16(
IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_TITLE); IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_TITLE);
base::string16 plural_message = l10n_util::GetPluralStringFUTF16(
base::string16 expected_message = l10n_util::GetStringFUTF16( IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_MESSAGE, 1);
IDS_NEARBY_NOTIFICATION_CONNECTION_REQUEST_MESSAGE,
base::ASCIIToUTF16(device_name), base::string16 expected_message = base::ReplaceStringPlaceholders(
l10n_util::GetPluralStringFUTF16(IDS_NEARBY_FILE_ATTACHMENTS_IMAGES, 1)); plural_message,
{base::ASCIIToUTF16(device_name),
l10n_util::GetPluralStringFUTF16(IDS_NEARBY_FILE_ATTACHMENTS_IMAGES, 1)},
/*offsets=*/nullptr);
if (with_token) { if (with_token) {
expected_message = base::StrCat( expected_message = base::StrCat(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment