How to localize your iPad (iPhone) application
There are several ways to localize your application, written in Xcode for iPad, or iPhone. The best way is to use “.strings” files and set it to a location to save individual languages.
1. all texts written into application controllers
In order to perform localization, it is necessary to rewrite all the texts from XIB files into controllers.
We do this quite easily, so that all variables we set textual labels and values in application code.
For example:
1 2 3 4 5 |
[loginTextFieldEmail setPlaceholder: @"Please enter email"]; [loginTextFieldPassword setPlaceholder:@"Please insert password"]; [loginLabelEmail setText:@"Email:"]; [loginLabelPassword setText:@"Password"]; [submit setTitle:@"Submit form" forState: UIControlStateNormal]; |
2. create a file for localization
Create a new file – file type is “.strings”, which will contain individual localizations for all language variants:
For example, place the file into the “Supporting Files” and name it “Localizable.strings”
Navigate to the file and look into the pane “Info Pane” (usually right) and click on the “+” button to add new language versions:
Set values for each language like this example:
Section localizable (English):
1 2 |
/** English translations */ "Error" = "Error"; |
Section localizable (Czech):
1 2 |
/** English translations */ "Error" = "Chyba"; |
3. Calling localize strings:
Now we call NSLocalizedString function that automatically connects and loads the translations of these strings:
1 2 |
NSString *val = NSLocalizedString(@"Error", @"call error string"); NSLog(@"%@", val); |
Thus the function load the value for key “Error” and stored in the variable “val”. Now we can continue working with this variable.
If you want to check the language setting, you can call:
1 2 3 4 |
NSUserDefaults* defs = [NSUserDefaults standardUserDefaults]; NSArray* languages = [defs objectForKey:@"AppleLanguages"]; NSString* preferredLang = [languages objectAtIndex:0]; NSLog(@"%@", preferredLang); |
This code list the current language in the console.
It is necessary before adding new language to clear the cache and delete the application in device (simulator) and upload again:
4. Change language to the iPad
The language is automatically loaded by the settings in your device:
Hi!
If you’re interested in a tool to collaboratively localize iOS apps for iPad or iPhone, I suggest you give poeditor.com a shot.
It’s a very user-friendly online translation platform that handles .strings files too, along with other popular language file formats.
You’ll see that it has a sum of very useful features to aid your localization workflow, like set reference language and translation memory.
Cheers and good luck with your projects!
Thanks, finally found out why it didnt work for me… did everything except clearing the cache before reading this… 3 hours wasted!