From 0cc9e4e62dc015d49ae16bac473b68397c6818fe Mon Sep 17 00:00:00 2001 From: Mike Grabowski Date: Mon, 26 Oct 2026 18:35:22 +0400 Subject: [PATCH] fix(apple): return the current locale as a bcp 47 code without keywords When language and region differ, the locale identifier carries keywords such as en_US@rg=plzzzz. It is the default language of the speech, transcription and embedding models, and AVSpeechSynthesisVoice does not accept it, so getCurrentLocale() now returns en-US. Co-Authored-By: Claude Opus 5.5 --- packages/apple-llm/ios/utils/AppleUtils.mm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/apple-llm/ios/utils/AppleUtils.mm b/packages/apple-llm/ios/utils/AppleUtils.mm index 5b656b70b..7221a0203 100644 --- a/packages/apple-llm/ios/utils/AppleUtils.mm +++ b/packages/apple-llm/ios/utils/AppleUtils.mm @@ -29,8 +29,19 @@ + (NSString *)moduleName { return std::make_shared(params); } +// A BCP 47 code such as en-US or zh-Hans-CN. The locale identifier can carry +// keywords such as "@rg=plzzzz" (when language and region differ), which +// AVSpeechSynthesisVoice and other APIs taking a language code do not accept - (NSString *)getCurrentLocale { - return [NSLocale currentLocale].localeIdentifier; + NSLocale *locale = [NSLocale currentLocale]; + NSMutableArray *parts = [NSMutableArray arrayWithObject:locale.languageCode]; + if (locale.scriptCode != nil) { + [parts addObject:locale.scriptCode]; + } + if (locale.countryCode != nil) { + [parts addObject:locale.countryCode]; + } + return [parts componentsJoinedByString:@"-"]; } @end