swiftxcodeswiftuilocalizationstring-catalog

How to change app language on the fly using the new String Catalogs system?


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...


Solution

  • If your app supports iOS 13+ or macOS 10.15+, 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.