Skip to content

Commit

Permalink
Bug 1636984 - Part 1: Add patches to workaround ICU/CLDR issues with …
Browse files Browse the repository at this point in the history
…display names and append items. r=jwalden

Differential Revision: https://phabricator.services.mozilla.com/D74681
  • Loading branch information
anba committed Jun 12, 2020
1 parent c055ecf commit 0b50093
Show file tree
Hide file tree
Showing 4 changed files with 161 additions and 0 deletions.
33 changes: 33 additions & 0 deletions intl/icu-patches/bug-1636984-alias-append-items-sink.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Handle "alias" entries in DateTimePatternGenerator::AppendItemNamesSink.
#
# ICU bug: https://unicode-org.atlassian.net/browse/ICU-20992

diff --git a/intl/icu/source/i18n/dtptngen.cpp b/intl/icu/source/i18n/dtptngen.cpp
--- a/intl/icu/source/i18n/dtptngen.cpp
+++ b/intl/icu/source/i18n/dtptngen.cpp
@@ -956,16 +956,25 @@ struct DateTimePatternGenerator::AppendI
virtual void put(const char *key, ResourceValue &value, UBool /*noFallback*/,
UErrorCode &errorCode) {
ResourceTable itemsTable = value.getTable(errorCode);
if (U_FAILURE(errorCode)) { return; }
for (int32_t i = 0; itemsTable.getKeyAndValue(i, key, value); ++i) {
UDateTimePGDisplayWidth width;
UDateTimePatternField field = dtpg.getFieldAndWidthIndices(key, &width);
if (field == UDATPG_FIELD_COUNT) { continue; }
+
+ UResType type = value.getType();
+ U_ASSERT(type == URES_TABLE || type == URES_ALIAS);
+
+ // TODO: Implement support for alias types.
+ if (type == URES_ALIAS) {
+ continue;
+ }
+
ResourceTable detailsTable = value.getTable(errorCode);
if (U_FAILURE(errorCode)) { return; }
for (int32_t j = 0; detailsTable.getKeyAndValue(j, key, value); ++j) {
if (uprv_strcmp(key, "dn") != 0) { continue; }
const UnicodeString& valueStr = value.getUnicodeString(errorCode);
if (dtpg.getFieldDisplayName(field,width).isEmpty() && !valueStr.isEmpty()) {
dtpg.setFieldDisplayName(field,width,valueStr);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Add <appendItem> entries for "DayPeriod" and "FractionalSeconds" to avoid the
# "├ ┤" parentheses from ICU and instead use the normal "( )" parentheses.
#
# CLDR bug: https://unicode-org.atlassian.net/browse/CLDR-13184

diff --git a/intl/icu/source/data/locales/root.txt b/intl/icu/source/data/locales/root.txt
--- a/intl/icu/source/data/locales/root.txt
+++ b/intl/icu/source/data/locales/root.txt
@@ -213,17 +213,19 @@ root{
}
NoonMarker:alias{"/LOCALE/calendar/gregorian/NoonMarker"}
NoonMarkerNarrow:alias{"/LOCALE/calendar/gregorian/NoonMarkerNarrow"}
appendItems{
Day{"{0} ({2}: {1})"}
+ DayPeriod{"{0} ({2}: {1})"}
Day-Of-Week{"{0} {1}"}
Era{"{1} {0}"}
Hour{"{0} ({2}: {1})"}
Minute{"{0} ({2}: {1})"}
Month{"{0} ({2}: {1})"}
Quarter{"{0} ({2}: {1})"}
Second{"{0} ({2}: {1})"}
+ FractionalSecond{"{0} ({2}: {1})"}
Timezone{"{0} {1}"}
Week{"{0} ({2}: {1})"}
Year{"{1} {0}"}
}
availableFormats{
@@ -749,17 +751,19 @@ root{
}
NoonMarker:alias{"/LOCALE/calendar/gregorian/NoonMarker"}
NoonMarkerNarrow:alias{"/LOCALE/calendar/gregorian/NoonMarkerNarrow"}
appendItems{
Day{"{0} ({2}: {1})"}
+ DayPeriod{"{0} ({2}: {1})"}
Day-Of-Week{"{0} {1}"}
Era{"{1} {0}"}
Hour{"{0} ({2}: {1})"}
Minute{"{0} ({2}: {1})"}
Month{"{0} ({2}: {1})"}
Quarter{"{0} ({2}: {1})"}
Second{"{0} ({2}: {1})"}
+ FractionalSecond{"{0} ({2}: {1})"}
Timezone{"{0} {1}"}
Week{"{0} ({2}: {1})"}
Year{"{1} {0}"}
}
availableFormats{
@@ -1018,17 +1022,19 @@ root{
"{1} {0}",
"{1} {0}",
}
appendItems{
Day{"{0} ({2}: {1})"}
+ DayPeriod{"{0} ({2}: {1})"}
Day-Of-Week{"{0} {1}"}
Era{"{1} {0}"}
Hour{"{0} ({2}: {1})"}
Minute{"{0} ({2}: {1})"}
Month{"{0} ({2}: {1})"}
Quarter{"{0} ({2}: {1})"}
Second{"{0} ({2}: {1})"}
+ FractionalSecond{"{0} ({2}: {1})"}
Timezone{"{0} {1}"}
Week{"{0} ({2}: {1})"}
Year{"{1} {0}"}
}
availableFormats{
diff --git a/intl/icu/source/i18n/dtptngen.cpp b/intl/icu/source/i18n/dtptngen.cpp
--- a/intl/icu/source/i18n/dtptngen.cpp
+++ b/intl/icu/source/i18n/dtptngen.cpp
@@ -257,12 +257,12 @@ static const dtTypeElem dtTypes[] = {
{0, UDATPG_FIELD_COUNT, 0, 0, 0} , // last row of dtTypes[]
};

static const char* const CLDR_FIELD_APPEND[] = {
"Era", "Year", "Quarter", "Month", "Week", "*", "Day-Of-Week",
- "*", "*", "Day", "*", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
- "Hour", "Minute", "Second", "*", "Timezone"
+ "*", "*", "Day", "DayPeriod", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
+ "Hour", "Minute", "Second", "FractionalSecond", "Timezone"
};

static const char* const CLDR_FIELD_NAME[UDATPG_FIELD_COUNT] = {
"era", "year", "quarter", "month", "week", "weekOfMonth", "weekday",
"dayOfYear", "weekdayOfMonth", "day", "dayperiod", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
39 changes: 39 additions & 0 deletions intl/icu-patches/bug-1636984-display-name-fractional-seconds.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Give fractional seconds a more useful display name than "F14".
#
# CLDR bug: https://unicode-org.atlassian.net/browse/CLDR-13623

diff --git a/intl/icu/source/data/locales/root.txt b/intl/icu/source/data/locales/root.txt
--- a/intl/icu/source/data/locales/root.txt
+++ b/intl/icu/source/data/locales/root.txt
@@ -2527,10 +2527,15 @@ root{
zone{
dn{"Zone"}
}
zone-narrow:alias{"/LOCALE/fields/zone-short"}
zone-short:alias{"/LOCALE/fields/zone"}
+ fractionalSecond{
+ dn{"Fractional Second"}
+ }
+ fractionalSecond-narrow:alias{"/LOCALE/fields/fractionalSecond-short"}
+ fractionalSecond-short:alias{"/LOCALE/fields/fractionalSecond"}
}
layout{
characters{"left-to-right"}
lines{"top-to-bottom"}
}
diff --git a/intl/icu/source/i18n/dtptngen.cpp b/intl/icu/source/i18n/dtptngen.cpp
--- a/intl/icu/source/i18n/dtptngen.cpp
+++ b/intl/icu/source/i18n/dtptngen.cpp
@@ -264,11 +264,11 @@ static const char* const CLDR_FIELD_APPE
};

static const char* const CLDR_FIELD_NAME[UDATPG_FIELD_COUNT] = {
"era", "year", "quarter", "month", "week", "weekOfMonth", "weekday",
"dayOfYear", "weekdayOfMonth", "day", "dayperiod", // The UDATPG_x_FIELD constants and these fields have a different order than in ICU4J
- "hour", "minute", "second", "*", "zone"
+ "hour", "minute", "second", "fractionalSecond", "zone"
};

static const char* const CLDR_FIELD_WIDTH[] = { // [UDATPG_WIDTH_COUNT]
"", "-short", "-narrow"
};
3 changes: 3 additions & 0 deletions intl/update-icu.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ for patch in \
suppress-warnings.diff \
bug-1198952-workaround-make-3.82-bug.diff \
bug-1433303-minimize-subtags.diff \
bug-1636984-alias-append-items-sink.diff \
bug-1636984-display-name-fractional-seconds.diff \
bug-1636984-append-item-dayperiod-fractional-seconds.diff \
; do
echo "Applying local patch $patch"
patch -d ${icu_dir}/../../ -p1 --no-backup-if-mismatch < ${icu_dir}/../icu-patches/$patch
Expand Down

0 comments on commit 0b50093

Please sign in to comment.