Commit 786adf11 authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

[Nearby] Provide translations for notification

This adds a new strings file for Nearby UI. Also adds strings and an
icon used in the notifications for Nearby.

Bug: 1102348
Change-Id: Ic5efac87078ad5bd9e26b714952395fcaabad995
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2283306Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarAlex Chau <alexchau@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#786045}
parent 554d6184
......@@ -25,6 +25,8 @@ per-file global_media_controls_strings.grdp=file://chrome/browser/ui/global_medi
per-file media_router_strings.grdp=file://chrome/browser/media/router/OWNERS
per-file nearby_share_strings.grdp=file://chrome/browser/nearby_sharing/OWNERS
per-file welcome_strings.grdp=file://chrome/browser/ui/webui/welcome/OWNERS
per-file printing_strings.grdp=file://printing/OWNERS
......
......@@ -304,6 +304,11 @@ are declared in tools/grit/grit_rule.gni.
<part file="extensions_strings.grdp" />
</if>
<!-- Nearby Share specific strings -->
<if expr="not is_android">
<part file="nearby_share_strings.grdp" />
</if>
<!-- Welcome strings -->
<if expr="not chromeos and not is_android">
<part file="welcome_strings.grdp" />
......
<?xml version="1.0" encoding="utf-8"?>
<!-- Nearby Share specific strings (included from generated_resources.grd). -->
<grit-part>
<!-- Common strings -->
<message name="IDS_NEARBY_FILE_ATTACHMENTS_APPS" desc="Describes one or more apps being transfered via Nearby Share.">
{COUNT, plural, =1 {1 app} other {# apps}}
</message>
<message name="IDS_NEARBY_FILE_ATTACHMENTS_IMAGES" desc="Describes one or more images being transfered via Nearby Share.">
{COUNT, plural, =1 {1 image} other {# images}}
</message>
<message name="IDS_NEARBY_FILE_ATTACHMENTS_UNKNOWN" desc="Describes one or more files being transfered via Nearby Share.">
{COUNT, plural, =1 {1 file} other {# files}}
</message>
<message name="IDS_NEARBY_FILE_ATTACHMENTS_VIDEOS" desc="Describes one or more videos being transfered via Nearby Share.">
{COUNT, plural, =1 {1 video} other {# videos}}
</message>
<message name="IDS_NEARBY_TEXT_ATTACHMENTS_ADDRESSES" desc="Describes one or more addresses being transfered via Nearby Share.">
{COUNT, plural, =1 {1 address} other {# addresses}}
</message>
<message name="IDS_NEARBY_TEXT_ATTACHMENTS_LINKS" desc="Describes one or more web links being transfered via Nearby Share.">
{COUNT, plural, =1 {1 link} other {# links}}
</message>
<message name="IDS_NEARBY_TEXT_ATTACHMENTS_PHONE_NUMBERS" desc="Describes one or more phone numbers being transfered via Nearby Share.">
{COUNT, plural, =1 {1 phone number} other {# phone numbers}}
</message>
<message name="IDS_NEARBY_TEXT_ATTACHMENTS_UNKNOWN" desc="Describes one or more pieces of text being transfered via Nearby Share.">
{COUNT, plural, =1 {1 text} other {# texts}}
</message>
<message name="IDS_NEARBY_UNKNOWN_ATTACHMENTS" desc="Describes one or more items being transfered via Nearby Share.">
{COUNT, plural, =1 {1 item} other {# items}}
</message>
<!-- Notification strings -->
<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>
</message>
<message name="IDS_NEARBY_NOTIFICATION_SOURCE" desc="Text shown as the source of a Nearby Share notification.">
Nearby Share
</message>
</grit-part>
7e868924d1bee00ca3c545815b29124e6d29b984
\ No newline at end of file
8cdb77ee0a567be2df1862f30d67ccd737f1a9d5
\ No newline at end of file
27e8b76038f1e0191851db63cc14312e8d2d0f1e
\ No newline at end of file
60e1e0cc15117fcbb75f336468689daeb96d8ca7
\ No newline at end of file
44c78d2f1bcdb578726cb2a2c44fcb2c097ac946
\ No newline at end of file
886e64dc519320ae2f000cebcb8fd37bc1c8e9b8
\ No newline at end of file
a19296c4969fa5a8bebe72489a7e913a58f2bc69
\ No newline at end of file
1245e337671c186b9d8bd464980479b4664a869e
\ No newline at end of file
d9e0a093819a865be8d1ed030d718257ec94bba4
\ No newline at end of file
8e4b4fe83900097701b24560585c6e0dc2796b14
\ No newline at end of file
1ab6f2550384cad15f8c9c44265d74eb919d3c6b
\ No newline at end of file
file://chrome/browser/nearby_sharing/OWNERS
# COMPONENT: UI>Browser>Sharing>Nearby
This directory of image SHA-1 hashes is used to improve translations of UI
strings through context images for translators.
See also: [Chrome Translation Screenshots - Instructions & FAQ
](https://docs.google.com/document/d/1nwYWDny20icMSpLUuV_LgrlbWKrYpbXOERUIZNH636o/edit#heading=h.2t7lc4cxo2au)
......@@ -190,6 +190,10 @@ aggregate_vector_icons("chrome_vector_icons") {
]
}
if (!is_android) {
icons += [ "nearby_share.icon" ]
}
if (enable_vr && !is_android) {
# Used on desktop VR headsets and Linux unit tests.
icons += [ "open_in_browser.icon" ]
......
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 20,
PATH_COLOR_ARGB, 0xFF, 0x1A, 0x73, 0xE8,
MOVE_TO, 2.89f, 12.31f,
R_CUBIC_TO, 1.05f, 0, 1.89f, -0.85f, 1.89f, -1.89f,
CUBIC_TO_SHORTHAND, 3.94f, 8.52f, 2.89f, 8.52f,
CUBIC_TO, 1.85f, 8.52f, 1, 9.37f, 1, 10.42f,
R_CUBIC_TO, 0, 1.05f, 0.85f, 1.89f, 1.89f, 1.89f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0xD9, 0x30, 0x25,
MOVE_TO, 17.11f, 12.31f,
R_CUBIC_TO, 1.05f, 0, 1.89f, -0.85f, 1.89f, -1.89f,
R_CUBIC_TO, 0, -1.04f, -0.85f, -1.89f, -1.89f, -1.89f,
R_CUBIC_TO, -1.05f, 0, -1.89f, 0.85f, -1.89f, 1.89f,
R_CUBIC_TO, 0, 1.04f, 0.85f, 1.89f, 1.89f, 1.89f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0x1A, 0x73, 0xE8,
MOVE_TO, 9.57f, 6.11f,
LINE_TO, 6.13f, 2.67f,
R_ARC_TO, 0.95f, 0.95f, 0, 0, 0, -1.34f, 1.34f,
LINE_TO, 8.23f, 7.45f,
R_LINE_TO, 1.34f, -1.34f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0xD9, 0x30, 0x25,
MOVE_TO, 8.12f, 8.41f,
R_ARC_TO, 2.84f, 2.84f, 0, 0, 0, 0, 4.02f,
R_LINE_TO, 0.13f, 0.13f,
R_LINE_TO, 1.37f, -1.34f,
R_LINE_TO, -0.13f, -0.13f,
R_ARC_TO, 0.93f, 0.93f, 0, 0, 1, -0.3f, -0.67f,
R_ARC_TO, 0.95f, 0.95f, 0, 0, 1, 0.28f, -0.67f,
R_LINE_TO, 5.74f, -5.74f,
R_ARC_TO, 0.95f, 0.95f, 0, 0, 0, 0, -1.34f,
R_ARC_TO, 0.95f, 0.95f, 0, 0, 0, -1.34f, 0,
LINE_TO, 8.12f, 8.41f,
CLOSE,
MOVE_TO, 11.73f, 13.34f,
R_LINE_TO, -1.34f, 1.34f,
R_LINE_TO, 3.48f, 3.48f,
R_ARC_TO, 0.95f, 0.95f, 0, 1, 0, 1.34f, -1.34f,
R_LINE_TO, -3.48f, -3.48f,
CLOSE,
NEW_PATH,
PATH_COLOR_ARGB, 0xFF, 0x1A, 0x73, 0xE8,
MOVE_TO, 11.88f, 12.43f,
R_ARC_TO, 2.84f, 2.84f, 0, 0, 0, 0.62f, -3.1f,
R_ARC_TO, 2.84f, 2.84f, 0, 0, 0, -0.62f, -0.92f,
R_LINE_TO, -0.13f, -0.13f,
R_LINE_TO, -1.34f, 1.34f,
R_LINE_TO, 0.13f, 0.13f,
R_ARC_TO, 0.93f, 0.93f, 0, 0, 1, 0.27f, 0.67f,
R_ARC_TO, 0.94f, 0.94f, 0, 0, 1, -0.28f, 0.67f,
R_LINE_TO, -5.74f, 5.74f,
R_ARC_TO, 0.95f, 0.95f, 0, 0, 0, 0, 1.34f,
R_CUBIC_TO, 0.37f, 0.37f, 0.97f, 0.37f, 1.34f, 0,
R_LINE_TO, 5.75f, -5.74f,
CLOSE
......@@ -46,40 +46,48 @@ TextAttachment::Type GetCommonTextAttachmentType(
return type;
}
base::string16 GetUnknownAttachmentsString(size_t count) {
// TODO(crbug.com/1102348): Provide translated string.
return base::string16();
}
base::string16 GetFileAttachmentsString(
const std::vector<FileAttachment>& files) {
// TODO(crbug.com/1102348): Add translated special cases for file types.
int GetFileAttachmentsStringId(const std::vector<FileAttachment>& files) {
switch (GetCommonFileAttachmentType(files)) {
case FileAttachment::Type::kApp:
return IDS_NEARBY_FILE_ATTACHMENTS_APPS;
case FileAttachment::Type::kImage:
return IDS_NEARBY_FILE_ATTACHMENTS_IMAGES;
case FileAttachment::Type::kUnknown:
return IDS_NEARBY_FILE_ATTACHMENTS_UNKNOWN;
case FileAttachment::Type::kVideo:
return IDS_NEARBY_FILE_ATTACHMENTS_VIDEOS;
default:
return GetUnknownAttachmentsString(files.size());
return IDS_NEARBY_UNKNOWN_ATTACHMENTS;
}
}
base::string16 GetTextAttachmentsString(
const std::vector<TextAttachment>& texts) {
// TODO(crbug.com/1102348): Add translated special cases for text types.
int GetTextAttachmentsStringId(const std::vector<TextAttachment>& texts) {
switch (GetCommonTextAttachmentType(texts)) {
case TextAttachment::Type::kAddress:
return IDS_NEARBY_TEXT_ATTACHMENTS_ADDRESSES;
case TextAttachment::Type::kPhoneNumber:
return IDS_NEARBY_TEXT_ATTACHMENTS_PHONE_NUMBERS;
case TextAttachment::Type::kText:
return IDS_NEARBY_TEXT_ATTACHMENTS_UNKNOWN;
case TextAttachment::Type::kUrl:
return IDS_NEARBY_TEXT_ATTACHMENTS_LINKS;
default:
return GetUnknownAttachmentsString(texts.size());
return IDS_NEARBY_UNKNOWN_ATTACHMENTS;
}
}
base::string16 GetAttachmentsString(const ShareTarget& share_target) {
size_t file_count = share_target.file_attachments().size();
size_t text_count = share_target.text_attachments().size();
int resource_id = IDS_NEARBY_UNKNOWN_ATTACHMENTS;
if (file_count > 0 && text_count == 0)
return GetFileAttachmentsString(share_target.file_attachments());
resource_id = GetFileAttachmentsStringId(share_target.file_attachments());
if (text_count > 0 && file_count == 0)
return GetTextAttachmentsString(share_target.text_attachments());
resource_id = GetTextAttachmentsStringId(share_target.text_attachments());
return GetUnknownAttachmentsString(file_count + text_count);
return l10n_util::GetPluralStringFUTF16(resource_id, text_count + file_count);
}
} // namespace
......@@ -99,19 +107,20 @@ void NearbyNotificationManager::ShowProgress(
message_center::Notification notification(
message_center::NOTIFICATION_TYPE_PROGRESS, kNearbyNotificationId,
// TODO(crbug.com/1102348): Provide translated title.
/*title=*/GetAttachmentsString(share_target),
l10n_util::GetStringFUTF16(
IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE,
GetAttachmentsString(share_target),
base::ASCIIToUTF16(share_target.device_name())),
/*message=*/base::string16(),
/*icon=*/gfx::Image(),
// TODO(crbug.com/1102348): Provide translated source.
/*display_source=*/base::string16(),
l10n_util::GetStringUTF16(IDS_NEARBY_NOTIFICATION_SOURCE),
/*origin_url=*/GURL(),
message_center::NotifierId(message_center::NotifierType::SYSTEM_COMPONENT,
kNearbyNotifier),
rich_notification_data,
/*delegate=*/nullptr);
// TODO(crbug.com/1102348): Set Nearby Share icon.
notification.set_vector_small_image(kNearbyShareIcon);
notification.set_progress(100.0 * transfer_metadata.progress());
std::vector<message_center::ButtonInfo> notification_actions;
......
......@@ -7,11 +7,14 @@
#include <memory>
#include <vector>
#include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h"
#include "chrome/app/vector_icons/vector_icons.h"
#include "chrome/browser/browser_features.h"
#include "chrome/browser/nearby_sharing/share_target.h"
#include "chrome/browser/nearby_sharing/transfer_metadata.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/grit/generated_resources.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gtest/include/gtest/gtest.h"
......@@ -76,6 +79,17 @@ class TransferMetadataBuilder {
double progress_ = 0;
};
TextAttachment CreateTextAttachment(TextAttachment::Type type) {
return TextAttachment("text body", type, /*size=*/9);
}
FileAttachment CreateFileAttachment(FileAttachment::Type type) {
return FileAttachment(/*file_name=*/"file.jpg", type,
/*size=*/10,
/*file_path=*/base::nullopt,
/*mime_type=*/"example");
}
class NearbyNotificationManagerTest : public testing::Test {
public:
NearbyNotificationManagerTest() {
......@@ -100,6 +114,54 @@ class NearbyNotificationManagerTest : public testing::Test {
NearbyNotificationManager manager_{&profile_};
};
struct ProgressNotificationTestParam {
std::vector<TextAttachment::Type> text_attachments;
std::vector<FileAttachment::Type> file_attachments;
int expected_resource_id;
};
ProgressNotificationTestParam kProgressNotificationTestParams[] = {
// No attachments.
{{}, {}, IDS_NEARBY_UNKNOWN_ATTACHMENTS},
// Mixed attachments.
{{TextAttachment::Type::kText},
{FileAttachment::Type::kUnknown},
IDS_NEARBY_UNKNOWN_ATTACHMENTS},
// Text attachments.
{{TextAttachment::Type::kUrl}, {}, IDS_NEARBY_TEXT_ATTACHMENTS_LINKS},
{{TextAttachment::Type::kText}, {}, IDS_NEARBY_TEXT_ATTACHMENTS_UNKNOWN},
{{TextAttachment::Type::kAddress},
{},
IDS_NEARBY_TEXT_ATTACHMENTS_ADDRESSES},
{{TextAttachment::Type::kPhoneNumber},
{},
IDS_NEARBY_TEXT_ATTACHMENTS_PHONE_NUMBERS},
{{TextAttachment::Type::kAddress, TextAttachment::Type::kAddress},
{},
IDS_NEARBY_TEXT_ATTACHMENTS_ADDRESSES},
{{TextAttachment::Type::kAddress, TextAttachment::Type::kUrl},
{},
IDS_NEARBY_TEXT_ATTACHMENTS_UNKNOWN},
// File attachments.
{{}, {FileAttachment::Type::kApp}, IDS_NEARBY_FILE_ATTACHMENTS_APPS},
{{}, {FileAttachment::Type::kImage}, IDS_NEARBY_FILE_ATTACHMENTS_IMAGES},
{{}, {FileAttachment::Type::kUnknown}, IDS_NEARBY_FILE_ATTACHMENTS_UNKNOWN},
{{}, {FileAttachment::Type::kVideo}, IDS_NEARBY_FILE_ATTACHMENTS_VIDEOS},
{{},
{FileAttachment::Type::kApp, FileAttachment::Type::kApp},
IDS_NEARBY_FILE_ATTACHMENTS_APPS},
{{},
{FileAttachment::Type::kApp, FileAttachment::Type::kImage},
IDS_NEARBY_FILE_ATTACHMENTS_UNKNOWN},
};
class NearbyNotificationManagerProgressNotificationTest
: public NearbyNotificationManagerTest,
public testing::WithParamInterface<ProgressNotificationTestParam> {};
} // namespace
TEST_F(NearbyNotificationManagerTest, ShowProgress_ShowsNotification) {
......@@ -119,6 +181,9 @@ TEST_F(NearbyNotificationManagerTest, ShowProgress_ShowsNotification) {
EXPECT_EQ(GURL(), notification.origin_url());
EXPECT_TRUE(notification.never_timeout());
EXPECT_FALSE(notification.renotify());
EXPECT_EQ(&kNearbyShareIcon, &notification.vector_small_image());
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_NEARBY_NOTIFICATION_SOURCE),
notification.display_source());
const std::vector<message_center::ButtonInfo>& buttons =
notification.buttons();
......@@ -137,7 +202,11 @@ TEST_F(NearbyNotificationManagerTest, ShowProgress_ShowsProgress) {
manager()->ShowProgress(share_target, transfer_metadata);
message_center::Notification notification = GetDisplayedNotifications()[0];
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications();
ASSERT_EQ(1u, notifications.size());
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(100.0 * progress, notification.progress());
}
......@@ -159,3 +228,37 @@ TEST_F(NearbyNotificationManagerTest, ShowProgress_UpdatesProgress) {
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(100.0 * progress, notification.progress());
}
TEST_P(NearbyNotificationManagerProgressNotificationTest, Test) {
const ProgressNotificationTestParam& param = GetParam();
std::string device_name = "device";
ShareTargetBuilder share_target_builder;
share_target_builder.set_device_name(device_name);
for (TextAttachment::Type type : param.text_attachments)
share_target_builder.add_attachment(CreateTextAttachment(type));
for (FileAttachment::Type type : param.file_attachments)
share_target_builder.add_attachment(CreateFileAttachment(type));
ShareTarget share_target = share_target_builder.build();
TransferMetadata transfer_metadata = TransferMetadataBuilder().build();
manager()->ShowProgress(share_target, transfer_metadata);
size_t total = param.text_attachments.size() + param.file_attachments.size();
base::string16 expected = l10n_util::GetStringFUTF16(
IDS_NEARBY_NOTIFICATION_SEND_PROGRESS_TITLE,
l10n_util::GetPluralStringFUTF16(param.expected_resource_id, total),
base::ASCIIToUTF16(device_name));
std::vector<message_center::Notification> notifications =
GetDisplayedNotifications();
ASSERT_EQ(1u, notifications.size());
const message_center::Notification& notification = notifications[0];
EXPECT_EQ(expected, notification.title());
}
INSTANTIATE_TEST_SUITE_P(NearbyNotificationManagerProgressNotificationTest,
NearbyNotificationManagerProgressNotificationTest,
testing::ValuesIn(kProgressNotificationTestParams));
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