We just dropped support for iOS 16 in our app and migrated to the new properties on Locale to extract the language code, region, and script. However, after doing this we are seeing an issue where the script property is returning a value when the language has no script.
Here is the initializer that we are using to populate the values. The identifier is coming from the preferredLanguages
property that is found on Locale.
init?(identifier: String) {
let locale = Locale(identifier: identifier)
guard
let languageCode = locale.language.languageCode?.identifier
else {
return nil
}
language = languageCode
region = locale.region?.identifier
script = locale.language.script?.identifier
}
Whenever I inspect locale.language
I see all of the correct values. However, when I inspect locale.language.script
directly it is always returning Latn
as the value. If I inspect the deprecated locale.scriptCode
property it will return nil
as expected.
Here is an example from the debugger for en-AU
. I also see the same for other languages such as en-AE
, pt-BR
.
Since the language components show the script
as nil
, then I would expect locale.language.script?.identifier
to also return nil.