Skip to content

Conversation

@itingliu
Copy link
Contributor

Here are some examples:

print(Locale(languageCode: "", script: "", languageRegion: "").identifier) // "-_"

let languageComponents = Locale.Language.Components(language: .init(identifier:""))
print(Locale(languageComponents: languageComponents).identifier) // "-Latn"

Fix this by handling empty identifiers passed in at initialization time correctly.

resolves 132353443

…esults in an unreasonable locale.

Here are some examples:

```swift
print(Locale(languageCode: "", script: "", languageRegion: "").identifier) // "-_"

let languageComponents = Locale.Language.Components(language: .init(identifier:""))
print(Locale(languageComponents: languageComponents).identifier) // "-Latn"
```

Fix this by handling empty identifiers passed in at initialization time correctly.

resolves 132353443
XCTAssertEqual(emptyLocale.language.languageCode, nil)
XCTAssertEqual(emptyLocale.language.script, nil)
XCTAssertEqual(emptyLocale.language.region, nil)
XCTAssertEqual(emptyLocale.language.maximalIdentifier, "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently returns "en-Latn-US"

XCTAssertEqual(emptyLocale.language.script, nil)
XCTAssertEqual(emptyLocale.language.region, nil)
XCTAssertEqual(emptyLocale.language.maximalIdentifier, "")
XCTAssertEqual(emptyLocale.language.minimalIdentifier, "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently returns "en"


let emptyLocale = Locale(identifier: "")
XCTAssertEqual(emptyLocale.language.languageCode, nil)
XCTAssertEqual(emptyLocale.language.script, nil)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently returns "Latn"

@itingliu
Copy link
Contributor Author

@swift-ci please test

@itingliu itingliu requested a review from parkera January 10, 2025 17:43
@itingliu
Copy link
Contributor Author

@swift-ci please test

@itingliu itingliu requested a review from parkera May 12, 2025 17:23
@itingliu itingliu merged commit e072f82 into swiftlang:main May 28, 2025
15 checks passed
@itingliu itingliu deleted the locale-identifier-from-empty-comp branch May 28, 2025 16:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants