I recently noticed an inconsistency in how languages are represented in Apple’s new Translation API compared to Foundation’s Locale system.
Observation from the Translation API
When retrieving the list of supported languages using:
let availableLanguages = try await LanguageAvailability().supportedLanguages
The results are:
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(uk), script: nil, region: Optional(UA)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(zh), script: nil, region: Optional(TW)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(ko), script: nil, region: Optional(KR)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(en), script: nil, region: Optional(GB)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(de), script: nil, region: Optional(DE)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(zh), script: nil, region: Optional(CN)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(ja), script: nil, region: Optional(JP)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(id), script: nil, region: Optional(ID)))
Language(components: Foundation.Locale.Language.Components(languageCode: Optional(nl), script: nil, region: Optional(NL)))
....
Key points:
• The script component is always nil.
• Region codes (CN, TW, etc.) determine the script for languages like Chinese (Simplified or Traditional).
• Other languages (e.g., en-GB, en-US, pt-BR) also rely on region-based identification.
Observation from Foundation Locale (Locale.current.language)
When retrieving the user’s system language setting:
systemLanguageObj = Locale.current.language
I get a different format where the script component is present, but the region may vary based on user settings. This means that mapping between script and region is not consistent between the two APIs, requiring manual handling.
My key questions:
1. Is my current approach correct, or is there a better way to get user language settings that match Translation API identifiers?
2. If no alternative exists, could the Translation API align its language identification method with Foundation Locale to reduce ambiguity?
Any insights or suggestions would be greatly appreciated!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hi,
My app keeps getting rejected during App Review with the reason that the Sign in with Apple button is unresponsive. However, I have tested it extensively on:
• A real iPad Pro (iPadOS 18.3.2)
• Multiple Xcode simulators
• Including an iPad Air 5th simulator (18.3.1)
In all of these cases, the button works correctly.
The reviewer mentioned they are using an iPad Air 5th running iPadOS 18.3.2, which I cannot find as a simulator in Xcode, nor do I have access to this exact device around me.
I’m using standard SignInWithAppleButton code with no custom wrappers or UI layers on top. Here is the relevant snippet:
GeometryReader { geometry in
ZStack {
Color.black.opacity(0.3)
.ignoresSafeArea()
.onTapGesture {
prompt = ""
showChat = false
}
VStack(alignment: .leading, spacing: 0){
switch purchaseManager.hasAISubscription {
case 1:
HStack{
}
case 2:
HStack{
}
case 3:
HStack{
}
default:
HStack{
}
}
Divider()
ScrollView {
VStack(alignment: .leading, spacing: 8) {
ForEach(filteredChatHistory, id: \.id) { chat in
}
}
Spacer()
}
.frame(maxHeight: geometry.size.height * 0.7)
.defaultScrollAnchor(.bottom)
.padding()
Divider()
HStack(){
if httpManager.isLoggedIn && purchaseManager.hasAISubscription > 0 {
}
}
else if purchaseManager.hasAISubscription == 0{
}
else{
Spacer()
SignInWithAppleButton(.continue){ request in
request.requestedScopes = [.email]
} onCompletion: { result in
switch result {
case .success(let auth):
switch auth.credential {
case let appleCredential as ASAuthorizationAppleIDCredential:
let userID = appleCredential.user
saveToKeychain(userID, for: "com.xing-fu.aireader.apple.userid")
if let identityTokenData = appleCredential.identityToken,
let identityToken = String(data: identityTokenData, encoding: .utf8) {
Task {
//后端认证过,才算登录成功
await httpManager.loginWithApple(identityToken)
}
}
break
default:
break
}
case .failure(let error):
print("error")
}
}
.frame(maxWidth: 350, maxHeight: 40)
.padding()
.cornerRadius(10)
Spacer()
}
}
}
.overlay( // 边框
RoundedRectangle(cornerRadius: 10)
.stroke(Color.g2, lineWidth: 4)
)
.background(Color(UIColor.systemBackground))
.cornerRadius(10) // 圆角
.shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 5)
.frame(width: geometry.size.width * 0.8)
.onDisappear{
httpManager.alertMessage = nil
}
}
}
Topic:
Privacy & Security
SubTopic:
Sign in with Apple
Hi I have a very strange problem: my phone number can not be saved. I manually typed but it always says format need to only contains number.
However it works when I add "+". This error message is misleading and need to be fixed
Topic:
App Store Distribution & Marketing
SubTopic:
TestFlight