Skip to content

Commit 2bdae69

Browse files
authored
Use regions, not languages, for calendar algorithm defaults (#6325)
Depends on #6302 Matching on languages is incorrect here, these are region codes (treating `"sa"` as a language code gives us the obviously incorrect result of mapping Sanskrit to the Islamic calendar). Calendar choice is corellated with the region, not the language. This does not start using fallback (though we really should). This also removes the sa/umalqura mapping entirely since @sffc said it is not in the latest CLDR. <!-- Thank you for your pull request to ICU4X! Reminder: try to use [Conventional Comments](https://conventionalcomments.org/) to make comments clearer. Please see https://github.com/unicode-org/icu4x/blob/main/CONTRIBUTING.md for general information on contributing to ICU4X. -->
1 parent 2deb42f commit 2bdae69

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

components/calendar/src/any_calendar.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use crate::{types, AsCalendar, Calendar, Date, DateDuration, DateDurationUnit, R
1414

1515
use crate::preferences::{CalendarAlgorithm, HijriCalendarAlgorithm};
1616
use icu_locale_core::preferences::define_preferences;
17-
use icu_locale_core::subtags::language;
17+
use icu_locale_core::subtags::region;
1818
use icu_provider::prelude::*;
1919

2020
use core::fmt;
@@ -731,12 +731,10 @@ impl AnyCalendar {
731731
{
732732
// This will eventually need fallback data from the provider
733733
let algo = prefs.calendar_algorithm.unwrap_or_else(|| {
734-
let lang = prefs.locale_preferences.language();
735-
if lang == language!("th") {
734+
let reg = prefs.locale_preferences.region();
735+
if reg == Some(region!("th")) {
736736
CalendarAlgorithm::Buddhist
737-
} else if lang == language!("sa") {
738-
CalendarAlgorithm::Hijri(Some(HijriCalendarAlgorithm::Umalqura))
739-
} else if lang == language!("af") || lang == language!("ir") {
737+
} else if reg == Some(region!("af")) || reg == Some(region!("ir")) {
740738
CalendarAlgorithm::Persian
741739
} else {
742740
CalendarAlgorithm::Gregory

components/datetime/src/neo.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -804,7 +804,7 @@ impl<FSet: DateTimeNamesMarker> DateTimeFormatter<FSet> {
804804
/// use writeable::assert_try_writeable_eq;
805805
///
806806
/// let formatter = DateTimeFormatter::try_new(
807-
/// locale!("th").into(),
807+
/// locale!("th-TH").into(),
808808
/// YMD::long(),
809809
/// )
810810
/// .unwrap()
@@ -1097,7 +1097,7 @@ impl<FSet: DateTimeMarkers> DateTimeFormatter<FSet> {
10971097
/// use writeable::assert_writeable_eq;
10981098
///
10991099
/// let formatter =
1100-
/// DateTimeFormatter::try_new(locale!("th").into(), YMD::long()).unwrap();
1100+
/// DateTimeFormatter::try_new(locale!("th-TH").into(), YMD::long()).unwrap();
11011101
///
11021102
/// assert_writeable_eq!(
11031103
/// formatter.format(&Date::try_new_iso(2024, 12, 16).unwrap()),

components/locale_core/src/preferences/locale.rs

+5
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,11 @@ impl LocalePreferences {
151151
self.language
152152
}
153153

154+
/// Preference of Region
155+
pub const fn region(&self) -> Option<Region> {
156+
self.region
157+
}
158+
154159
/// Extends the preferences with the values from another set of preferences.
155160
pub fn extend(&mut self, other: LocalePreferences) {
156161
if !other.language.is_default() {

0 commit comments

Comments
 (0)