0

Localize the disambiguation text for date search.

Using placeholders may not work for every language, but should
work for most languages since all days of the week will have
consistent gender etc.

Bug: b:357763895
Change-Id: I804f20f53e545c0abc209bfdb1e28bbfe9a08308
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5782721
Reviewed-by: Michelle Chen <michellegc@google.com>
Commit-Queue: Darren Shen <shend@chromium.org>
Reviewed-by: Jing Wang <jiwan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1341357}
This commit is contained in:
Darren Shen
2024-08-13 23:47:36 +00:00
committed by Chromium LUCI CQ
parent 6e8d66b771
commit ec105a40af
7 changed files with 54 additions and 22 deletions

@ -7595,6 +7595,22 @@ New install
desc="This string is read out by a screen reader when the user selects a search result to insert into an input field. The contents are the search results are read out before this announcement.">
Inserting selected result
</message>
<message name="IDS_PICKER_DATE_DISAMBIGUATION_THIS_COMING_DAY"
desc="In sentence case: This string appears as a subtitle to a calendar date. The placeholder is the name of a day of the week (e.g. Monday) and is capitalized when appropriate for the locale. This string indicates that the date is in the future. For example, suppose today is Tuesday. If the placeholder is Monday, then this string refers to the upcoming Monday (6 days from now), as opposed to the Monday that just passed (1 day ago). The whole string (including placeholder) should be in sentence case.">
This coming <ph name="DAY_OF_WEEK">$1<ex>Monday</ex></ph>
</message>
<message name="IDS_PICKER_DATE_DISAMBIGUATION_THIS_PAST_DAY"
desc="In sentence case: This string appears as a subtitle to a calendar date. The placeholder is the name of a day of the week (e.g. Monday) and is capitalized when appropriate for the locale. This string indicates that the date is in the past. For example, suppose today is Tuesday. If the placeholder is Monday, then this string refers to the Monday that just passed (1 day ago), as opposed to upcoming Monday (6 days from now).">
This past <ph name="DAY_OF_WEEK">$1<ex>Monday</ex></ph>
</message>
<message name="IDS_PICKER_DATE_DISAMBIGUATION_NEXT_WEEK"
desc="In sentence case: This string appears as a subtitle to a calendar date. The placeholder is the name of a day of the week (e.g. Wednesday) and is capitalized when appropriate for the locale. This string indicates that the date is in the next week. For example, suppose today is Tuesday. If the placeholder is Wednesday, then this string refers to the Wednesday next week (8 days from now), as opposed to upcoming Wednesday in this week (1 day from now).">
<ph name="DAY_OF_WEEK">$1<ex>Wednesday</ex></ph> next week
</message>
<message name="IDS_PICKER_DATE_DISAMBIGUATION_LAST_WEEK"
desc="In sentence case: This string appears as a subtitle to a calendar date. The placeholder is the name of a day of the week (e.g. Monday) and is capitalized when appropriate for the locale. This string indicates that the date is in the previous week. For example, suppose today is Tuesday. If the placeholder is Monday, then this string refers to the Monday last week (8 days from ago), as opposed to the Monday that just passed (1 day from now).">
<ph name="DAY_OF_WEEK">$1<ex>Monday</ex></ph> last week
</message>
<!-- WM -->
<message name="IDS_ENTER_PIP_A11Y_NOTIFICATION" is_accessibility_with_no_ui="true" desc="Accessibility text read by chromevox when a window starts picture-in-picture mode.">

@ -0,0 +1 @@
827d87e83e9d882b767b6db773f027a2e20f4008

@ -0,0 +1 @@
01f75ef08a10496eca404088473bad2b27bf7cdf

@ -0,0 +1 @@
4ebe2bbb899a45e6d0ce800c67d5778f8c82ba9a

@ -0,0 +1 @@
4ebe2bbb899a45e6d0ce800c67d5778f8c82ba9a

@ -16,14 +16,15 @@
#include "ash/public/cpp/picker/picker_search_result.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/strings/grit/ash_strings.h"
#include "base/containers/fixed_flat_map.h"
#include "base/i18n/case_conversion.h"
#include "base/i18n/time_formatting.h"
#include "base/strings/strcat.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/time/time.h"
#include "third_party/re2/src/re2/re2.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/chromeos/styles/cros_tokens_color_mappings.h"
namespace ash {
@ -63,9 +64,6 @@ constexpr auto kDayOfWeekToNumber =
{"friday", 5},
{"saturday", 6},
});
constexpr std::u16string_view kNumberToDayOfWeek[] = {
u"Sunday", u"Monday", u"Tuesday", u"Wednesday",
u"Thursday", u"Friday", u"Saturday"};
constexpr std::u16string_view kSuggestedDates[] = {
{u"Today"},
@ -73,6 +71,10 @@ constexpr std::u16string_view kSuggestedDates[] = {
{u"2 weeks from now"},
};
std::u16string GetLocalizedDayOfWeek(const base::Time& time) {
return base::LocalizedTimeFormatWithPattern(time, "EEEE");
}
// The result of parsing a date expression query.
struct ResolvedDate {
base::Time time;
@ -153,30 +155,37 @@ void HandleDayOfWeekQueries(const base::Time& now,
int day_diff = target_day_of_week - current_day_of_week;
if (prefix.empty() || prefix == "this ") {
if (target_day_of_week < current_day_of_week) {
std::u16string localized_day_of_week =
GetLocalizedDayOfWeek(now + base::Days(day_diff));
resolved_dates.push_back({
.time = now + base::Days(day_diff + kDaysPerWeek),
.disambiguation_text = base::StrCat(
{u"this coming ", kNumberToDayOfWeek[target_day_of_week]}),
.disambiguation_text = l10n_util::GetStringFUTF16(
IDS_PICKER_DATE_DISAMBIGUATION_THIS_COMING_DAY,
localized_day_of_week),
});
resolved_dates.push_back({
.time = now + base::Days(day_diff),
.disambiguation_text = base::StrCat(
{u"this past ", kNumberToDayOfWeek[target_day_of_week]}),
.disambiguation_text = l10n_util::GetStringFUTF16(
IDS_PICKER_DATE_DISAMBIGUATION_THIS_PAST_DAY,
std::move(localized_day_of_week)),
});
} else {
resolved_dates.push_back({.time = now + base::Days(day_diff)});
}
} else if (prefix == "next ") {
if (target_day_of_week > current_day_of_week) {
std::u16string localized_day_of_week =
GetLocalizedDayOfWeek(now + base::Days(day_diff));
resolved_dates.push_back({
.time = now + base::Days(day_diff + kDaysPerWeek),
.disambiguation_text = base::StrCat(
{kNumberToDayOfWeek[target_day_of_week], u" next week"}),
.disambiguation_text = l10n_util::GetStringFUTF16(
IDS_PICKER_DATE_DISAMBIGUATION_NEXT_WEEK, localized_day_of_week),
});
resolved_dates.push_back({
.time = now + base::Days(day_diff),
.disambiguation_text = base::StrCat(
{u"this coming ", kNumberToDayOfWeek[target_day_of_week]}),
.disambiguation_text = l10n_util::GetStringFUTF16(
IDS_PICKER_DATE_DISAMBIGUATION_THIS_COMING_DAY,
std::move(localized_day_of_week)),
});
} else {
resolved_dates.push_back(
@ -184,15 +193,18 @@ void HandleDayOfWeekQueries(const base::Time& now,
}
} else if (prefix == "last ") {
if (target_day_of_week < current_day_of_week) {
std::u16string localized_day_of_week =
GetLocalizedDayOfWeek(now + base::Days(day_diff));
resolved_dates.push_back({
.time = now + base::Days(day_diff - kDaysPerWeek),
.disambiguation_text = base::StrCat(
{kNumberToDayOfWeek[target_day_of_week], u" last week"}),
.disambiguation_text = l10n_util::GetStringFUTF16(
IDS_PICKER_DATE_DISAMBIGUATION_LAST_WEEK, localized_day_of_week),
});
resolved_dates.push_back({
.time = now + base::Days(day_diff),
.disambiguation_text = base::StrCat(
{u"this past ", kNumberToDayOfWeek[target_day_of_week]}),
.disambiguation_text = l10n_util::GetStringFUTF16(
IDS_PICKER_DATE_DISAMBIGUATION_THIS_PAST_DAY,
std::move(localized_day_of_week)),
});
} else {
resolved_dates.push_back(

@ -140,7 +140,7 @@ INSTANTIATE_TEST_SUITE_P(
.query = u"next Friday",
.expected_results =
{MakeResult(u"Mar 29", u"Friday next week"),
MakeResult(u"Mar 22", u"this coming Friday")},
MakeResult(u"Mar 22", u"This coming Friday")},
},
// search for last Friday on Tuesday
TestCase{
@ -153,16 +153,16 @@ INSTANTIATE_TEST_SUITE_P(
.date = "22 Mar 2024",
.query = u"Tuesday",
.expected_results =
{MakeResult(u"Mar 26", u"this coming Tuesday"),
MakeResult(u"Mar 19", u"this past Tuesday")},
{MakeResult(u"Mar 26", u"This coming Tuesday"),
MakeResult(u"Mar 19", u"This past Tuesday")},
},
// search for this Tuesday on Friday
TestCase{
.date = "22 Mar 2024",
.query = u"this Tuesday",
.expected_results =
{MakeResult(u"Mar 26", u"this coming Tuesday"),
MakeResult(u"Mar 19", u"this past Tuesday")},
{MakeResult(u"Mar 26", u"This coming Tuesday"),
MakeResult(u"Mar 19", u"This past Tuesday")},
},
// search for next Tuesday on Friday
TestCase{
@ -176,7 +176,7 @@ INSTANTIATE_TEST_SUITE_P(
.query = u"last Tuesday",
.expected_results =
{MakeResult(u"Mar 12", u"Tuesday last week"),
MakeResult(u"Mar 19", u"this past Tuesday")},
MakeResult(u"Mar 19", u"This past Tuesday")},
},
// search for Monday on Monday
TestCase{