Default language not working in iOS app - ios

I have such problem:
I have localized my app for two languages - English and Polish, with English being set as the Base one.
I set developmentRegion to "en" (also tried "English") in both info.plist and project.pbxproj files.
My translated texts are contained within localized Main.strings and Localizable.strings files.
So everything should be fine, yet when I set any language other than Polish or English the app does not fall back to the Base (English) one, instead stays on the last used, supported language. (i.e. Polish if I recently changed from Polish to lets say French).
Can anyone help me ?

Ok I see now. I thought that whatever unsupported language I would set in system settings, my app would always revert to English (Base).
That's not true.
When selected language is not supported then the app is taking the language that is the highest on "Preferred languages" list in system settings. Only if none of these preferred languages is supported, then the base one is selected.

Related

Should I have Localizable.strings Base or English?

Following Ray Wenderlich tutorial (https://www.raywenderlich.com/180356/ios-internationalization), the Localizable.strings is as following. Notice there is no Localizable.strings(Base)
But in some other tutorials, they would use Base instead of English, so did I in my project as follow.
My iPhone's preferred language order is English then Chinese and is currently set to English. But whenever I run the app, it goes to Chinese except when I explicitly edit scheme to ask Xcode to run it in English. Does that mean I should have Localizable.strings (English) instead of Localizable.strings (Base)?
Another question, I have Main.storyboard (Base) and Main.strings (Chinese (Simplified)) under Main.storyboard. But no matter what I do, the storyboard always shows up in Chinese version. What have I done wrong?
=== Update ===
I played around with it (simply remove and recreate, nothing changed), and then magically the localization works as expected: The app default to English, which is my system language, and switches to Chinese when I edit scheme. However, now my storyboard is stuck with (Base) version no matter what I do.
I am no expert on this, but as I understand the Base file is a fallback if your app doesn't have a Localizable.strings file for the user's device language.
So if you have English and Chinese as localization files, but your preferred languages are German and Japanese, the system will check the Base file for strings.
In your case you have Chinese and the base files. English is not found, so it takes the other preferred language (Chinese). Therefore the base strings are not used -- the app defaults to the Chinese localization.
To solve the problem, you need to make an English strings file in addition to your base strings.

Develop app in Japanese, add localization into English

I am developing an iOS app targeted almost exclusively at a Japanese audience, with the possibility of a small portion of english-speaking users.
All storyboards and xibs are being designed with Japanese strings, and localization into English should take place at a later stage.
From the beginning, the Project's Info/Localizations section in Xcode reads:
(The two files are, of course, "Main.storyboard" and "LaunchScreen.xib")
Because "English" is already added (as the development language), I can not click the "+" button and add it as a localization. I could add 'Japanese' instead, but I want it to be the Development Language, not just some (secondary) localization.
Also, and in an apparent contradiction with the above, The Target's Info.plist file reads:
When I select either of the localized files (Main.storyboard and LaunchScreen.xib) in the Project Navigator, and check the file inspector, the 'Localization' section reads:
...which seems to suggest that the existing, Japanese files (.xib and .storyboard) are the 'Base' and checking 'English' will add support for that language too (The pull-down menu seems to indicate that I can chose between using a strings file or a dedicated duplicate of the storyboard. I am inclined to believe the strings approach is better).
...So, how should I proceed?
A. Check the 'English' box in the File inspector / Localization section?
This creates an en.lproj folder and adds a strings file inside it that I should translate later, I guess. This effectively seems to treat my existing Interface Builder files (populated with Japanese labels) as 'Base', and provide for localization into English through the strings file created (if I understand correctly). However, English as the Development Language in the Project settings remains somehow unsettling...
B. Remove English and instead add Japanese in the Project/Info/Localizations pane?
This will make Japanese the Development Language, and I can re-add English as a localization afterwards. But for some reason, if I do this Japanese will not be treated as 'Base' language, and (unnecessary) string files will be also added for Japanese, not just for English.
EDIT: I found this question, which somehow provides a 'fix' for the option B above.
OK, this is what I settled for (but I will still accept better/smarter answers):
I did as suggested by the question I mentioned before, and edited the Xcode project file to force Japanese as the "Development Language":
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
en,
Base,
);
becomes:
developmentRegion = Japanese;
hasScannedForEncodings = 0;
knownRegions = (
en,
ja,
Base,
Next, for the storyboards/xibs I want to localize, I will check the 'English' checkbox in the File inspector/Localization:
...and that will create my string files for English localization (Notice the 'Japanese' checkbox below 'English'. I'd rather it not be there at all, because the Base xibs/storyboards already have Japanese text labels by default, but I can just leave it unchecked).
Now, the Project's Info pane, 'Localizations' section looks like this:
ADDENDUM: Now that I think of it, with things setup like this, if someone ever launches this app on (say) an iPhone set to French, the app will fall back to Japanese (not English). This is probably not ideal, since the default language for non-Japanese speakers should be English, not the other way around.
However, I can not afford to design my xibs with English text and translate them to Japanese afterwards.

Xcode using wrong localization

I have two localizations in my project: Base (which is in English) and Swedish. When I set my phone to Swedish it works, and when I set it to English it works. But when I set it to another language, for example German, it uses the Swedish translations instead of Base. Any ideas why?
I found the answer. In the phones settings, you don't just set the current language, you set language priorities. So if you've had Swedish and switches to another language, Swedish will be second priority and English lower.
Go to your target and then to the Info tab. Under "Custom iOS Target Properties" you will find an entry with the name "Localization native development region". This entry determines which is the default language, the one displayed in case that there in no localization resource for the selected language. Make sure that the entry is set to "en".

Base localization not loaded keeps on last used one

I'm localizing my app to support English and Spanish.
If I set the device to Spanish and then I change to a non supported language, for example Italian or French, the app still shows the labels in Spanish. I'm not setting the values from code using NSLocalizedString. I'm localizing it in Interface Builder using the Main.strings file.
I have the Base localization in English, so it should show the content in English for other languages, but it’s not working. It keeps showing the last localization used.
Is this the correct behavior? How can I force it to use the Base localization when the language is neither English or Spanish?

How to use a language other than english, but still use NSLocalizedString with english?

I couldn't find any similar questions, so here we go:
I am working on an iOS app that for the first release will only be in french, but we plan to release an english version as well in the future. At this point, I thought it was a good idea to use NSLocalizedString for all the text, so that the app will be ready when the english language will be required. However, I would really like to use english as the key value in my code:
aString = NSLocalizedString(#"Yes", #"Text for positive answer");
instead of
aString = NSLocalizedString(#"Oui", #"Text for positive answer");
Then I want to run genstrings, and localize the .strings file in french (and give it to the translators). But if I do it like that, how can I get rid of the "original" english .strings file? Am I totally wrong here, and do I have to use french for now in my code?
If you are developing the app in English and localizing it into French, I wonder why you would want to actively prevent the app from running in English. If some users in your target market (France only, I imagine?) prefer to run their iOS device in English language, why deny them their preferred language? Or is it because you won't be doing QA of the English version and therefore don't wish to expose it yet?
In any case, I believe that you can restrict the list of supported languages by simply editing your project metadata. In XCode the list of supporting languages is shown on this page -- simply remove English and I believe that your English localizations, even if they are present in your project, won't be used (I haven't tested this but I doubt it would delete your existing English files, it should just remove them from the application's supported languages list)
You can do your whole project in english, keep english words for keys in the localizable.strings files, but keep only the fr.lproj folder, and in the plist set the supported languages only to french.

Resources