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

CLDR-8823 Don't use Jan, Feb, for non-gregorian calendar systems #3861

Merged
merged 2 commits into from
Jul 23, 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 @@ -20,7 +20,11 @@
%L = (long|short|narrow)
%M = (Alaska_Hawaii|Bering|Dominican|Goose_Bay|Greenland_Central|Dutch_Guiana|Africa_FarWestern|Liberia|British|Irish|Kuybyshev|Sverdlovsk|Baku|Tbilisi|Turkey|Yerevan|Aktyubinsk|Ashkhabad|Dushanbe|Frunze|Kizilorda|Oral|Samarkand|Shevchenko|Tashkent|Uralsk|Urumqi|Dacca|Karachi|Borneo|Malaya|Kwajalein)
%N = (gregorian|generic|buddhist|chinese|coptic|dangi|ethiopic|hebrew|indian|islamic|japanese|persian|roc)
%O = (gregorian|chinese|coptic|dangi|ethiopic|hebrew|indian|islamic|persian)
# calendar systems that should use Gregorian months (just Gregorian)
# We don't list roc, etc here because their months are hidden.
%G = (gregorian)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should support not only gregorian, but also gregorian-based calendars. (Those that use the same 12 month solar calendar: Thai Buddhist, Julian, etc.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are the calendars. Unfortunately, we don't have data here as to which is gregorian-based.

            <type name="buddhist" description="Thai Buddhist calendar"/>
            <type name="chinese" description="Traditional Chinese calendar"/>
            <type name="coptic" description="Coptic calendar"/>
            <type name="dangi" description="Traditional Korean calendar" since="22.1"/>
            <type name="ethioaa" description="Ethiopic calendar, Amete Alem (epoch approx. 5493 B.C.E)" alias="ethiopic-amete-alem"/>
            <type name="ethiopic" description="Ethiopic calendar, Amete Mihret (epoch approx, 8 C.E.)"/>
            <type name="gregory" description="Gregorian calendar" alias="gregorian"/>
            <type name="hebrew" description="Traditional Hebrew calendar"/>
            <type name="indian" description="Indian calendar"/>
            <type name="islamic" description="Hijri calendar"/>
            <type name="islamic-umalqura" description="Hijri calendar, Umm al-Qura" since="24"/>
            <type name="islamic-tbla" description="Hijri calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - astronomical epoch)" since="24"/>
            <type name="islamic-civil" description="Hijri calendar, tabular (intercalary years [2,5,7,10,13,16,18,21,24,26,29] - civil epoch)" since="24"/>
            <type name="islamic-rgsa" description="Hijri calendar, Saudi Arabia sighting" since="24"/>
            <type name="iso8601" description="ISO calendar (Gregorian calendar using the ISO 8601 calendar week rules)" since="2.0"/>
            <type name="japanese" description="Japanese Imperial calendar"/>
            <type name="persian" description="Persian calendar"/>
            <type name="roc" description="Republic of China calendar"/>
            <type name="islamicc" description="Civil (algorithmic) Arabic calendar" deprecated="true" preferred="islamic-civil"  alias="islamic-civil"/>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran a quick check, and it appears that the following are gregorian-based:
[gregoriy, iso8601, buddhist, japanese, roc]

Also filed a ticket to add metadata to cldr, so that this can be unhardcoded

Copy link
Member Author

@srl295 srl295 Jul 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So actually it seems the pre existing "intent" was to hide those so that you don't have a Japanese month January with a different translation than Gregorian January. That mystified me too but I think that's why %G is just one and not the others

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pedberg-icu should also weigh in on this.

  • It clearly should not be limited to exactly 'gregory', since iso8601 uses the same months, etc.
  • In the case of thai buddhist, japanese, roc, M2, M2 etc seem ok.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's here, then it's visible for editing. Do we want users giving a different translation for January in 8601 than for gregorian?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@macchiati Specifically, this PR does not make any changes to the visibility (HIDE) or textual content for these calendars: iso8601, buddhist, japanese, roc.

All that it does is change the following calendars to no longer have month codes based on Gregorian:

chinese|coptic|dangi|ethiopic|hebrew|indian|islamic|persian

# all others use M## form months.
%O = (chinese|coptic|dangi|ethiopic|hebrew|indian|islamic|persian)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't working, I think, because what we want is that every calendar falls into one of these groups.

  • Certain calendars are hidden.
  • Certain calendars are non-gregorian-based, and use M1
  • Certain calendars are gregorian-based, and use Jan

Because we NEVER want to miss a calendar, exactly one of these groups should be "any", and that needs to come last. That should not be the Hidden one, because we want to be safe, and better to show a calendar that we shouldn't, than hide a calendar that should be shown.

So it should be:

So

all the calendars that should be hidden

...%XXX...

all the calendars that should use M1

...%O...

all the calendars that should use Jan

...%A...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you detail what "isn't working"?

%P = (future|past)
%R = (gregorian|buddhist|coptic|ethiopic|ethiopic-amete-alem|hebrew|indian|islamic|japanese|persian|roc)
%S = ([^/]*+)
Expand Down Expand Up @@ -82,10 +86,14 @@
//ldml/dates/calendars/calendar[@type="gregorian"]/quarters/quarterContext[@type="%A"]/quarterWidth[@type="%A"]/quarter[@type="%A"] ; DateTime ; &calendar(gregorian) ; &calField(Quarters:$2:$1) ; $3
//ldml/dates/calendars/calendar[@type="%A"]/quarters/quarterContext[@type="%A"]/quarterWidth[@type="%A"]/quarter[@type="%A"] ; Special ; Suppress ; &calendar($1) ; &calField(Quarters:$3:$2)-$4 ; HIDE

//ldml/dates/calendars/calendar[@type="%O"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"][@yeartype="%A"] ; DateTime ; &calendar($1) ; &calField(Months:$3:$2) ; &month($4) (leap)
//ldml/dates/calendars/calendar[@type="%O"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"] ; DateTime ; &calendar($1) ; &calField(Months:$3:$2) ; &month($4)
//ldml/dates/calendars/calendar[@type="%A"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"][@yeartype="%A"] ; Special ; Suppress ; &calendar($1) ; &calField(Months:$3:$2)-&month($4) (leap) ; HIDE
//ldml/dates/calendars/calendar[@type="%A"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"] ; Special ; Suppress ; &calendar($1) ; &calField(Months:$3:$2)-&month($4) ; HIDE
# months that follow Gregorian - %G
//ldml/dates/calendars/calendar[@type="%G"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"][@yeartype="%A"] ; DateTime ; &calendar($1) ; &calField(Months:$3:$2) ; &month($4) (leap)
//ldml/dates/calendars/calendar[@type="%G"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"] ; DateTime ; &calendar($1) ; &calField(Months:$3:$2) ; &month($4)
# All others just use "M#" form
//ldml/dates/calendars/calendar[@type="%O"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"][@yeartype="%A"] ; DateTime ; &calendar($1) ; &calField(Months:$3:$2) ; M$4 (leap)
//ldml/dates/calendars/calendar[@type="%O"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"] ; DateTime ; &calendar($1) ; &calField(Months:$3:$2) ; M$4
//ldml/dates/calendars/calendar[@type="%A"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"][@yeartype="%A"] ; Special ; Suppress ; &calendar($1) ; &calField(Months:$3:$2)-M$4 (leap) ; HIDE
//ldml/dates/calendars/calendar[@type="%A"]/months/monthContext[@type="%A"]/monthWidth[@type="%A"]/month[@type="%A"] ; Special ; Suppress ; &calendar($1) ; &calField(Months:$3:$2)-M$4 ; HIDE

//ldml/dates/calendars/calendar[@type="gregorian"]/days/dayContext[@type="%A"]/dayWidth[@type="%A"]/day[@type="%A"] ; DateTime ; &calendar(gregorian) ; &calField(Days:$2:$1) ; &day($3)
//ldml/dates/calendars/calendar[@type="%A"]/days/dayContext[@type="%A"]/dayWidth[@type="%A"]/day[@type="%A"] ; Special ; Suppress ; &calendar($1) ; &calField(Days:$3:$2)-&day($4) ; HIDE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,9 @@ public void TestCoverage() {
if (hidePathHeader != hideCoverage) {
String message = "PathHeader: " + status + ", Coverage: " + level + ": " + path;
if (hidePathHeader && !hideCoverage) {
errln(message);
errln(
message
+ " - PathHeader says to HIDE this, but it visible at <comprehensive coverage. Fix PathHeader to show, or fix coverage.");
} else if (!hidePathHeader && hideCoverage) {
logln(message);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Test;
import org.unicode.cldr.util.*;

public class TestPathHeader {
static final String GREGORIAN = "gregorian";

@Test
public void TestNonGregorianMonths() {
CLDRFile english = CLDRConfig.getInstance().getCldrFactory().make("en", true);
PathHeader.Factory phf = PathHeader.getFactory(null);
for (final String xpath : english.fullIterable()) {
// skip unless a month name
if (!xpath.startsWith("//ldml/dates/calendars/calendar")) continue;
if (!xpath.contains("/month[")) continue;
final PathHeader ph = phf.fromPath(xpath);
final String value = english.getStringValue(xpath);
// skip any null values.
if (value == null) continue;
// skip any hidden items
final XPathParts xpp = XPathParts.getFrozenInstance(xpath);
final String calType = xpp.getAttributes(3).get("type");
// we skip Gregorian itself.
if (calType.equals(GREGORIAN)) continue;
// now, we need Gregorian for comparison.
final String gregopath =
xpp.cloneAsThawed().setAttribute("calendar", "type", GREGORIAN).toString();
final String gregovalue = english.getStringValue(gregopath);
final PathHeader gph = phf.fromPath(gregopath);
if (gph.shouldHide()) continue; // hide if the *gregorian* is hidden.

if (gregovalue != null && value.equals(gregovalue)) {
// The month name is the same as the Gregorian. So we assume the codes will be the
// same.
if (!ph.shouldHide())
assertEquals(
ph.getCode(),
gph.getCode(),
() ->
"Expected the same PathHeader code"
+ ph
+ " as Gregorian "
+ gph
+ " for xpath "
+ xpath
+ " because the month "
+ value
+ " was the same as gregorian "
+ gregopath);
assertTrue(
ph.shouldHide(),
() ->
"Should be hidden. To fix: remove "
+ calType
+ " from the %G line of PathHeader.txt.");
} else {
assertNotEquals(
ph.getCode(),
gph.getCode(),
() ->
"Expected a different PathHeader code from Gregorian for xpath "
+ xpath
+ " because the month "
+ value
+ " was the differnet from gregorian "
+ gregovalue
+ ".");
}
}
}
}
Loading