So far the apps i have written are available only in English,what if a korean user who wants to see and understand my app in korean language.Only two options are available for this user either he should learn English to use this app or choose a similar app which shows korean language too.He picks the most easy option of preferring second option.I don't want to lose the user just because am not showing korean nativity in app then lets include korean,chinese,spanish,french,u name the language we have in our app.
This is called localization of app.Making ios app work with multiple languages is precisely called Localization or rather with localization we can say let's display text in user's preferred language.
Method 1:
The user can change the language by going to Settings -> General -> International -> Language. When the language is changed, the iPhone also changes the name of the application, only if the application supports it.
Notes from the http://www.sortedbits.com/localization-of-your-io-app/ are given below:
Notes from the http://www.sortedbits.com/localization-of-your-io-app/ are given below:
CREATED LANGUAGE SPECIFIC DIRECTORIES
In my folder, where my project was located, I created 3 directories. For each language 1:
- en.lproj : This is where the English localization files go
- nl.lproj : This is where the Dutch localizations files go
- de.lproj : This is where the German localization files go
CREATED STRINGS FILES
In each of those directories I created 2 strings files, I did this by right-clicking the resources folder in Xcode, select Add -> New File. Then click the Resourcetag under Mac OS X and select Strings file.
When the New File dialog comes up, make sure you select the right location. You want to create 2 files per language directory you created with the step mentioned above. Name the files:
- InfoPlist.strings : This file I created to be able to localize my application name
- Localizable.strings : This file contains all the text my application is showing, in the appropriate language
Mind the capitalization, this is very important because we are running on a case sensitive file system.
FILL YOUR LOCALIZABLE.STRING FILE
What you need to do now is maybe a little bit of hassle, but you need to copy all the string you used in your application to this application and give them keys by which you can identify them. With keys I mean unique keys.
For example, my localization file in the directory nl.lproj looked a bit like this:
"Add new product" = "Voeg product toe";
While my localization file in the de.lproj looked like this:
"Add new product" = "Neue produkt";
I think you get the point.
ACTUALLY DISPLAY THE STRINGS
Now, after you spend hours filling your localization files and translating it to every language known to man you want to actually display some text in your application. Well that is pretty easy.
- (void) doSomeStuff { myLabel.text = NSLocalizedString(@"Add new product", @""); }
Whenever a language file for the users language could not be found, it will default back to the key and show that instead. So make sure your keys also say what you want your button/label/etc to say. That’s it! There isn’t more to it than that.
BUT WHAT ABOUT MY APPLICATION NAME?
I almost forgot. Remember that you created 2 files for each language? Well, just put this line in your InfoPlist.strings files (ofcourse with the translated application names).
CFBundleDisplayName = "My App Name";
Hope this helps you out.
Method 2:
Set the language of the application with in the application
Current procedure is we use NSLocalizedString() to get the localized version of any string, which acts as a key to match the key value pair in the localized version of Localizable.strings file.
NSLocalizedString() calls in background is [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] where [NSBundle mainBundle] is the default main bundle.
The trick to use is to get the value of localizedStringForKey from the bundle of your choice. So what we will do is that depending on the language selected we will select the specific bundle and use the [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] to get the localized value of the string.
This is how we do it:
1- Localize your application using the method describe here. i recommend using this method just so that you can use "genstrings" to create string table.
2- put the localized version of string values in the localized Localizable.strings.
3- Replace the NSLocalizedString with any function name of your choice, i will be using languageSelectedStringForKey .
4- Write a method definition and implementation of -(NSString*) languageSelectedStringForKey:(NSString*) key where it is accessible in the scope where the localized string is needed.
5- in the languageSelectedStringForKey method select the appropriate bundle depending on the language selected and call [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] on the bundle.
e.g.
for NSString *path= [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
and then get the string like this
NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
str here is the localized string.
2- put the localized version of string values in the localized Localizable.strings.
3- Replace the NSLocalizedString with any function name of your choice, i will be using languageSelectedStringForKey .
4- Write a method definition and implementation of -(NSString*) languageSelectedStringForKey:(NSString*) key where it is accessible in the scope where the localized string is needed.
5- in the languageSelectedStringForKey method select the appropriate bundle depending on the language selected and call [[NSBundle mainBundle] localizedStringForKey:(key) value:@"" table:nil] on the bundle.
e.g.
for NSString *path= [[NSBundle mainBundle] pathForResource:@"fr" ofType:@"lproj"];
NSBundle* languageBundle = [NSBundle bundleWithPath:path];
and then get the string like this
NSString* str=[languageBundle localizedStringForKey:key value:@"" table:nil];
str here is the localized string.
Hello! I think a software localization management platform like https://poeditor.com/ can be a great method to translate your iOS app in multiple languages. It is a collaborative translation platform designed to automate the localization process while offering a simple and user-friendly interface for users.
ReplyDelete