iOS: Is there any way to fake the user's locale? - ios

I'm interested in allowing my users to choose the language / locale my app appears to them in. I have figured out how to load the right bundle, choose the correct strings files, etc. However, some system items I still seem to have no control over. Switch controls, for example.
Is there any way for me to tell the system that this app should now behave in a specific language, rather than the user's current system setting?

The least hacky way is via NSUserDefaults: The locale is determined by AppleLocale (the locale ID as a string) and the language is determined by the first match in AppleLanguages (an array of language IDs); your app can override these defaults for your app only. To check if it's overridden by your app, you can use something like [defaults persistentDomainForName:[[NSBundle mainBundle] bundleIdentifier]] objectForKey:#"AppleLocale"]. To remove the override, use -removeObjectForKey:.
Whichever way you do it, you'll probably have to relaunch the app when changing languages; OS X and iOS apps simply aren't designed to change language at runtime (on OS X, only newly launched apps see the language change; on iOS the system kills all apps to change language).
I added this feature to make switching languages easier for development/testing; I have no idea whether this will fail the App Store review process.

Related

How to get/set the iOS "preferred language" from a RN app?

We are developing a React Native app supporting three languages. For various reasons, we must have specific language selection logic in the app and a language selector within the app.
In iOS 13 there is a new "Preferred language" selector in the system settings for the app. We would want the in-app language selector to change the preferred language, and conversely that the user could also change their language in the system settings.
How can I read/write the iOS "Preferred language" in a React Native app?
The preferred language setting cannot be explicitly fetched or set. Changing the preferred language appears to the app just like the whole system language is changed to the selected language.
We implemented in-app language selection so that the app uses the system language until the user explicitly changes the language in the app. Thus, if the user changes the preferred language, the app language changes. After the user changes the language in the app, the preferred language no longer matches the app language and changing it has no impact. (The user knows where to find the language setting after they have changed it once.)
You simply add it to Xcode (see image).
Then grab the languages in your app by using react-native-localize

How to change system alert language from within app

I am working on app, and customers want it to be fully localized. We have several Localizable.strings and InfoPlist.strings files for each supported language.
There is an opportunity in the app to change app's language "on fly".
(This is done by associating another bundle with chosen language)to main bundle. So when app calls [NSBundle.mainBundle localizedStringForKey:value:table:], it actually refer to bundle with language user has selected.)
Here comes bad consequences. System permission alerts (requests for location usage, camera usage, etc.) are not localized with language selected within the app, but localized with preferred language from iOS Settings.
So, for example, if user has English as preferred language in Settings, but in our app he chose French, the whole app will be in French except system alerts, which will be in English.
Is there any way to fix it? I mean, to choose programmatically which language system alert must consider as preferred?
Apple Rejection Reason: Your app's modal alerts are in English, but your app's primary language is French. To help users understand why your app is requesting access to a specific feature, your app's modal alerts should be in the same language as the rest of your app.

Change iOS system prompt language when app language is different from system language

In the application I'm developing, the user has the possibility to change the language. Therefore, the app language can be different than the iOS language.
The problem I'm facing is when a system prompt is shown within the application (i.e. Touch ID prompt), it uses the system language and not the app language. Is there any way of "forcing" the system prompts language?
As #qtngo mentioned, it is not possible.

Display system UI in specified language in iOS App

We have an iOS App that supports only English-language UI. When we run it on a device set to a different Language/Region (e.g. fr-CA), system UIs appear in the device language, not in English. Our preference would be to have all UI displayed "inside" the App appear in English.
To experiment, I created a single-view project that only does two things: request permission for notifications and show a MapKit map view, the two things we're most concerned with. I've tried the following, none of which appears to have the desired effect:
No localizations whatsoever (i.e. default when creating a new Xcode iOS project)
Added explicit "English - Development Language" localizaton (i.e. CFBundleLocalizations) and no other localizations
Tried setting the "AppleLanguages" in UserDefaults early in the App lifecycle (tried this in the AppDelegate and in a custom main.swift, similar to the solutions described in Setting "AppleLanguages" doesn't change app language)
let defaults = UserDefaults.standard
defaults.set(["en-CA"], forKey: "AppleLanguages")
defaults.synchronize()
Posts on the Apple Developer forums that suggest changing localization on the fly can/should not be attempted (e.g. https://forums.developer.apple.com/thread/85549, https://forums.developer.apple.com/message/36704#36704) but that's not exactly what we're going for. We don't want to change on the fly (e.g. in response to a language option inside our app), but rather just have all UIs, whether ours or from the system/frameworks appear only in English.
Is there some way to inform the system that the app is running in a specified localization that we've just overlooked?

XCode 5 localizing app name on the fly

"Application has localized display name" = YES in Info.plist
Localized CFBundleDisplayName & CFBundleName in InfoPlist.strings
When I change the language of the whole device, it works. It changes the name of my app.
When I install it, the name is in the language of the device.
I manually change the app language from inside the app with NSUserDefaults language setting. Everything inside the app is perfectly localized whenever I change the language from inside the app. (Needs a restart of app)
But the app name does not change this way, the only way for it to change is, changing the device language.
Am I missing something? Is there a way to change the app name when the language is changed?
Unfortunately, I don't think you can.
iOS has no way to tell what language preference is set inside each application (well, it could, but it's not done that way).
Instead, it uses the system-wide setting to find and display the appropriate CFBundleDisplayName for every application.
Developing a custom language preference inside an app is also not the recommended way. Apple expects users to set their language of choice in the device's Preferences, not from inside individual apps (see here: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPInternational/Articles/InternatSupport.html#//apple_ref/doc/uid/20000278-SW1). As an example, there's no way to change Facebook's language from inside the app, but as soon as you change the device's global language setting, the Facebook app reflects the change.

Resources