Skip to content

Commit b42675d

Browse files
committed
[SR-3202] Some of properties of Locale.current object are not filled on Linux
1 parent 124680b commit b42675d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

Foundation/NSLocale.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ open class NSLocale: NSObject, NSCopying, NSSecureCoding {
2828
}
2929

3030
open func object(forKey key: NSLocale.Key) -> Any? {
31-
return CFLocaleGetValue(_cfObject, key.rawValue._cfObject)
31+
return _SwiftValue.fetch(CFLocaleGetValue(_cfObject, key.rawValue._cfObject))
3232
}
3333

3434
open func displayName(forKey key: Key, value: String) -> String? {
@@ -91,7 +91,7 @@ extension NSLocale {
9191

9292
extension NSLocale {
9393
public var localeIdentifier: String {
94-
return (object(forKey: .identifier) as! NSString)._swiftObject
94+
return object(forKey: .identifier) as! String
9595
}
9696

9797
open class var availableLocaleIdentifiers: [String] {

TestFoundation/TestNSLocale.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class TestNSLocale : XCTestCase {
2222
("test_Identifier", test_Identifier),
2323
("test_copy", test_copy),
2424
("test_availableIdentifiers", test_availableIdentifiers),
25+
("test_localeProperties", test_localeProperties),
2526
]
2627
}
2728

@@ -112,4 +113,14 @@ class TestNSLocale : XCTestCase {
112113
func test_availableIdentifiers() {
113114
XCTAssertNoThrow(Locale.availableIdentifiers)
114115
}
116+
117+
func test_localeProperties(){
118+
let enUSID = "en_US"
119+
let locale = Locale(identifier: enUSID)
120+
XCTAssertEqual(String(describing: locale.languageCode!), "en")
121+
XCTAssertEqual(String(describing: locale.decimalSeparator!), ".")
122+
XCTAssertEqual(String(describing: locale.currencyCode!), "USD")
123+
XCTAssertEqual(String(describing: locale.collatorIdentifier!), enUSID)
124+
}
125+
115126
}

0 commit comments

Comments
 (0)