How to use UIKit localized string in my app

Viewed 3293

We are building a iOS game, our company requires cancel button in a UIAlertView should always be localized depend on user's device language.

It looks like there is such a string in UIKit framework, how can I access it in my own app?

Or, any other way to create a UIAlertView with a localized cancel button?

Thank you

Answer by myself:

Problem solved by the following code:

NSBundle* uikitBundle = [NSBundle bundleForClass:[UIButton class]];
NSString *language = [[[NSUserDefaults standardUserDefaults] objectForKey:@"AppleLanguages"] objectAtIndex:0];
NSBundle *languageBundle = [NSBundle bundleWithPath:[uikitBundle pathForResource:language ofType:@"lproj"]];
NSLog(@"%@: %@", language, NSLocalizedStringFromTableInBundle(@"Cancel", @"Localizable", languageBundle, nil));

This read string files from /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/Frameworks/UIKit.framework

Following languages have different name between NSUserDefault and UIKit.framework folder: fr en zh-Hans it de ja nl es pt-PT nb zh-Hant en-GB. They should be handled by code.

3 Answers
Related