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
Related
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.
There is an option in my app that will enable the user to change the language of the app which can be different from the system's language.
The app has to be localised according to that language instead of the device's language.
I have found couple of solutions like this one but I couldn't find a solution that will work for storyboards an base localisation.
How to achieve this?
I have set up 2 languages in my app:
English (development language)
Italian
I am expecting that in case the device is set to a language different than Italian, the app would come up in English.
However I noticed an inconsistency, between simulator and device:
If I set the simulator to Spanish, the app comes up in English
If I set the device to Spanish, the app comes up in Italian
how can I make sure the app comes up in English when the device language is set to Spanish?
I believe this inconsistency is due to the preferred language order in Setting App -> General -> Language & Region. Your iPhone device is likely to have ordered Italian with higher preference.
As stated in Apple's documentation (https://developer.apple.com/library/ios/qa/qa1828/_index.html)
To determine the language for your app, iOS considers not only the order of the user language preferences (in General > Language & Region of the Settings application) but also the localizations your app declares it supports. Here is the detailed process:
iOS first looks up your user's most preferred language, which is the first entry in their language preferences.
It proceeds to check if that language is supported by your app. iOS searches your app bundle for an .lproj folder matching the preferred language. If the folder exists, iOS infers that your app has been localized for that language and chooses it for your app. Otherwise, iOS selects the next language in the user language preferences, then repeats the above check.
The dialect support in iOS may slightly change the above behavior. If your user's preferred language is a regional variant that is not supported by your app, iOS will try to fall back to a more generic language before giving up. For example, if your user's preferred language is British English and your app bundle doesn't contain an en-GB.lproj or en_GB.lproj folder, iOS then searches your bundle for an en.lproj folder and chooses English for your app if the folder exists.
If none of the user’s preferred languages are supported by your app, iOS chooses the language matching your app's development region (CFBundleDevelopmentRegion).
In Summary,
a. For user who knows both Italian and English, it will display in their
preference.
b. If they only know one of the two, it will display the correct one.
c. If they don't know both, you should set CFBundleDevelopmentRegion in your info.plist to select English.
Let's suppose we've translated our application to a new language and we have the localization files in our project.
Now, how is the app going to know the language of the final user?
Is the app going to change the language depending on the settings of the iPhone/iPad?
The app determines which language to use based on the Region and Language set up by the user.
iOS 13 and newer support language selection on a "per app" basis.
Apple Developer News: How to support per-app language settings in your app
Although, I have noticed the "per app" language selection capability may not itially be visible to the user ...
Starting with iOS 14, if a "per app language setting" via the Settings app is not accessible, then some second language for the device in Setting > General > Language & Region needs to be added. After any second language is added at the device level, then all language choices for the app are visible in the Settings > Some Example App > Preferred Language section.
"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.