Skip to content

Commit feed84d

Browse files
authored
(112778892) Unlocalized decimal separators (swiftlang#215)
We regressed this behavior in 110211953; Now `IntegerFormatStyle` (and all other number format styles) and `Date.FormatStyle` ignores user's region settings if it uses the current locale. The regression was caused by us changing to use `locale.identifierCapturingPreferences` for the identifier, which includes "Country" code from global preferences as the extra "rg" keyword. I misunderstood what that represents -- It has nothing to do with the Region setting in System Preferences. We should ignore it internally. I'm very inclined to remove the reference to that key altogether, but let's keep it for compatibility reason for now.
1 parent d8a335c commit feed84d

File tree

2 files changed

+5
-6
lines changed

2 files changed

+5
-6
lines changed

Sources/FoundationInternationalization/Locale/Locale_ICU.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,9 @@ internal final class _Locale: Sendable, Hashable {
402402

403403
// This only includes a subset of preferences that are representable by
404404
// CLDR keywords: https://www.unicode.org/reports/tr35/#Key_Type_Definitions
405+
//
406+
// Intentionally ignore `prefs.country`: Locale identifier should already contain
407+
// that information. Do not override it.
405408
internal var identifierCapturingPreferences: String {
406409
lock.withLock { state in
407410
if let result = state.identifierCapturingPreferences {
@@ -424,10 +427,6 @@ internal final class _Locale: Sendable, Hashable {
424427
components.firstDayOfWeek = weekday
425428
}
426429

427-
if let country = prefs.country {
428-
components.region = .init(country)
429-
}
430-
431430
if let measurementSystem = prefs.measurementSystem {
432431
components.measurementSystem = measurementSystem
433432
}

Tests/FoundationInternationalizationTests/LocaleTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ final class LocaleTests : XCTestCase {
354354
// We treat it as US system as long as `metricUnits` is false
355355
expectIdentifier("en_US", preferences: .init(metricUnits: false, measurementUnits: .centimeters), expectedFullIdentifier: "en_US@measure=ussystem")
356356

357-
expectIdentifier("en_US", preferences: .init(country: "GB"), expectedFullIdentifier: "en_US@rg=gbzzzz")
358-
// Preference's region code is the same as the language code; no need for the specific keyword
357+
// 112778892: Country pref is intentionally ignored
358+
expectIdentifier("en_US", preferences: .init(country: "GB"), expectedFullIdentifier: "en_US")
359359
expectIdentifier("en_US", preferences: .init(country: "US"), expectedFullIdentifier: "en_US")
360360

361361
expectIdentifier("en_US", preferences: .init(firstWeekday: [.gregorian : 3]), expectedFullIdentifier: "en_US@fw=tue")

0 commit comments

Comments
 (0)