Skip to content

Instantly share code, notes, and snippets.

@keicoder
Created January 25, 2014 04:50
Show Gist options
  • Save keicoder/8612032 to your computer and use it in GitHub Desktop.
Save keicoder/8612032 to your computer and use it in GitHub Desktop.
objective-c : iOS Internationalization using NSLocalizedString()
//iOS Internationalization using NSLocalizedString()
//1. use NSLocalizedString() (even if you don’t care about internationalization right away)
//2. open a Terminal, go into the folder that contains the actual source files
//3. type command :genstrings *.m -o en.lproj
//4. above command add a new file called Localizable.strings in the en.lproj folder
//5. add Localizable.strings file to the project in Xcode (ex : Supporting Files group)
//6. in the File Inspector, add a localization for this file (in this case Dutch)
//7. Change the translations in the Localizable.strings
//use NSLocalizedString()
- (NSString *)kindForDisplay {
if ([self.kind isEqualToString:@"album"]) {
return NSLocalizedString(@"Album", @"Localized kind: Album");
} else if ([self.kind isEqualToString:@"ebook"]) {
return NSLocalizedString(@"E-Book", @"Localized kind: E-Book");
} else {
return self.kind;
}
}
//Change the translations in the Localizable.strings
"Album" = "Album";
"E-Book" = "E-Boek";
//that's it!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment