ios - 如何使用新的字符串目录系统动态更改应用程序语言? [Xcode 15]

标签 ios swift swiftui localization xcode15

我想知道如何使用新的字符串目录系统动态手动获取和更改当前应用程序语言。

尝试在https://developer.apple.com/documentation/xcode/localization处查看文档以获取信息。

我希望有一种方法可以获取当前的语言环境,并有一个函数可以更改它......

最佳答案

如果您支持 iOS 13 或 macOS Catalina 或更高版本,则不再需要提供在应用内选择语言的方法。 Apple 支持每个应用程序本地化:

How to support per-app language settings in your app

When you localize your app, people all over the world can view your content in the language they feel most comfortable reading. And with the latest versions of iOS and macOS, people can have even more control by choosing languages on a per-app basis. For example, someone may set their iPhone’s language to English, but want to use a social media app in Arabic.

Apple 明确建议不要手动进行语言切换:

If you currently offer such a UI, you should remove it to avoid customer confusion and potential conflict with the system. If you’d like to guide people to the system settings for language selection, you can replace your app’s custom UI with a flow that launches directly into the Settings app on iOS. On iOS, add the following:

UIApplication.shared.open(URL(字符串:UIApplication.openSettingsURLString)!)

On macOS, direct people to System Preferences > Language & Region to add a per-language setting for your app.

关于ios - 如何使用新的字符串目录系统动态更改应用程序语言? [Xcode 15],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76730835/

相关文章:

swift - RealityKit – 如何将视频素材添加到 ModelEntity?

ios - 为什么 -[UIColor setFill] 在不引用绘图上下文的情况下工作?

ios - 根据 label.text 更改 UITableViewCell 高度?

ios - 在 uitextfield 中添加图标 - iOS Swift

ios - Swift语言的StructName.init是什么意思?

Swift 和 Vapor : optionally update model field based in reques

ios - 如何为 iPhone 6 和 iPhone 6-Plus 优化非常老式的 iOS 应用程序

ios - MKAnnotationView 框架的初始化程序

ios - SwiftUI 动画和后续的反向动画到原始状态

ios - 我想在不停止另一个应用程序后台播放音乐的情况下制作音效