本地化 iOS 14 动态小部件配置

Far*_*ouK 4 swift widgetkit swiftui ios14

我试图根据应用程序语言加载小部件的不同配置,但是当我使用类似以下内容时:

Locale.preferredLanguages
Bundle.main.preferredLocalizations
Bundle.main.localizations

Run Code Online (Sandbox Code Playgroud)

所有这些都仅在 IntentExtensionTarget 中返回“en”。

这是我使用代码的示例:

extension IntentHandler: ReciterAndSurahIntentHandling {
    
    func provideSurahOptionsCollection(for intent: ReciterAndSurahIntent, with completion: @escaping (INObjectCollection<NSString>?, Error?) -> Void) {
        
        Locale.preferredLanguages
        Bundle.main.preferredLocalizations
        Bundle.main.localizations
        // All of them return "en" only, and I have multiple localization for the app.
    }
}
Run Code Online (Sandbox Code Playgroud)

Jkr*_*ist 5

您只能获得 EN,因为描述和小部件名称的本地化基于设备语言。如果您尝试将设备语言设置为其他语言,本地化应该可以工作。目前,还无法在小部件描述和名称本地化上使用应用内语言。