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

huangapple go评论72阅读模式
英文:

How to change app language on the fly using the new String Catalogs system? [Xcode 15]

问题

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

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

我期望有一种获取当前区域设置的方法和一个更改它的函数...

英文:

I'm wondering how I can get and change the current app language manually on the fly using the new String Catalogs system.

Tried checking the docs for information at https://developer.apple.com/documentation/xcode/localization

I expect there to be a way to get the current locale and a function to change it...

答案1

得分: 1

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

如何在您的应用程序中支持每个应用程序的语言设置

> 当您将您的应用程序本地化时,全世界的人们都可以用他们最舒适阅读的语言查看您的内容。而且在最新版本的iOS和macOS上,人们甚至可以通过在每个应用程序上选择语言来拥有更多的控制权。例如,有人可能将他们的iPhone语言设置为英文,但希望在社交媒体应用程序中使用阿拉伯语。

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

> 如果您目前提供此类UI,您应该将其删除以避免客户困惑和与系统可能发生冲突

如果您想引导人们前往系统设置进行语言选择,您可以将您的应用程序自定义的UI替换为一个直接启动iOS上的“设置”应用程序的流程。

在iOS上,添加以下内容:

UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)

> 在macOS上,引导用户前往系统偏好设置 > 语言与地区,以为您的应用程序添加每种语言的设置。

英文:

If you support iOS 13 or macOS Catalina or later, you no longer need to provide a way to select languages within your app.
Apple supports per-app localization:

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 is clearly advising against doing language switching manually:

> 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(string: UIApplication.openSettingsURLString)!)

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

huangapple
  • 本文由 发表于 2023年7月20日 22:18:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/76730835.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定