I'm writing an iOS app, where I want the user to be able to change the UI language independent of the iPhone's or iPad's language. The question is, how do I reload the appropriate NIB file for the currently displayed view when the language changes and how do I load the appropriate .strings file so that NSLocalizedString
works appropriately?
Change The App Language in iPhone or iPad AppsTap on the Settings app on the Home screen. Scroll down, select the app you wish to change its language. Select Language under Preferred Language. Choose the language you want to use.
This should do the trick, assuming that de
is the new language selected by the user. Also assure that you are reinitiating the current view.
[[NSUserDefaults standardUserDefaults] setObject:[NSArray arrayWithObjects:@"de", nil]
forKey:@"AppleLanguages"];
Personally, I don't like the idea of giving NIB files to translators. Instead, I design the NIBs so there is enough space for non-English languages (typically they will require 50% more room for text), and then I store all text resources in Localizable.strings files.
Then, in my code I set the text for each UI control.
[_myButton setTitle:NSLocalizedString(@"My button title",
@"My description for translation file, e.g. including chars limit")
forState:UIControlStateNormal];
I find this makes the translation process easier to manage.
To answer your original question, you would put this code in the viewWillAppear
function of your UIView
to ensure it is reloaded each time the UI reappears.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With