@@ -85,7 +85,9 @@ struct LocaleCache : Sendable {
85
85
}
86
86
}
87
87
88
- mutating func current( preferences: LocalePreferences ? , cache: Bool ) -> ( any _LocaleProtocol ) ? {
88
+ /// Get or create the current locale.
89
+ /// `disableBundleMatching` should normally be disabled (`false`). The only reason to turn it on (`true`) is if we are attempting to create a testing scenario that does not use the main bundle's languages.
90
+ mutating func current( preferences: LocalePreferences ? , cache: Bool , disableBundleMatching: Bool ) -> ( any _LocaleProtocol ) ? {
89
91
resetCurrentIfNeeded ( )
90
92
91
93
if let cachedCurrentLocale {
@@ -98,7 +100,7 @@ struct LocaleCache : Sendable {
98
100
return nil
99
101
}
100
102
101
- let locale = LocaleCache . localeICUClass. init ( name: nil , prefs: preferences, disableBundleMatching: false )
103
+ let locale = LocaleCache . localeICUClass. init ( name: nil , prefs: preferences, disableBundleMatching: disableBundleMatching )
102
104
if cache {
103
105
// It's possible this was an 'incomplete locale', in which case we will want to calculate it again later.
104
106
self . cachedCurrentLocale = locale
@@ -255,13 +257,14 @@ struct LocaleCache : Sendable {
255
257
func resetCurrent( to preferences: LocalePreferences ) {
256
258
lock. withLock {
257
259
$0. reset ( )
258
- let _ = $0. current ( preferences: preferences, cache: true )
260
+ // Disable bundle matching so we can emulate a non-English main bundle during test
261
+ let _ = $0. current ( preferences: preferences, cache: true , disableBundleMatching: true )
259
262
}
260
263
}
261
264
262
265
var current : any _LocaleProtocol {
263
266
var result = lock. withLock {
264
- $0. current ( preferences: nil , cache: false )
267
+ $0. current ( preferences: nil , cache: false , disableBundleMatching : false )
265
268
}
266
269
267
270
if let result { return result }
@@ -270,7 +273,7 @@ struct LocaleCache : Sendable {
270
273
let ( prefs, doCache) = preferences ( )
271
274
272
275
result = lock. withLock {
273
- $0. current ( preferences: prefs, cache: doCache)
276
+ $0. current ( preferences: prefs, cache: doCache, disableBundleMatching : false )
274
277
}
275
278
276
279
guard let result else {
0 commit comments