CocoaPods trunk is moving to be read-only. Read more on the blog, there are 14 months to go.
| TestsTested | ✓ |
| LangLanguage | Obj-CObjective C |
| License | MIT |
| ReleasedLast Release | Jan 2017 |
Maintained by 0x5e.
ViewController in Settings > General > Language & Region > iPhone Langage.Present GSLanguagePickerController:
- (IBAction)selectLanguageAction:(UIButton *)button {
GSLanguagePickerController *vc = [GSLanguagePickerController new];
UINavigationController *navi = [[UINavigationController alloc] initWithRootViewController:vc];
[self presentViewController:navi animated:YES completion:nil];
}Or push GSLanguagePickerController:
- (IBAction)selectLanguageAction:(UIButton *)button {
GSLanguagePickerController *vc = [GSLanguagePickerController new];
[self.navigationController pushViewController:vc animated:YES];
}And you can also observing language changed notification NSCurrentLocaleDidChangeNotification:
- (void)viewDidLoad {
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(languageChanged:) name:NSCurrentLocaleDidChangeNotification object:nil];
}
- (void)languageChanged:(NSNotification *)notification {
NSString *languageId = notification.object;
NSLog(@"Language has changed: %@", languageId);
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:[NSBundle defaultLanguage]];
NSString *languageName = [locale displayNameForKey:NSLocaleIdentifier value:languageId];
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Language has changed" message:[NSString stringWithFormat:@"%@: %@", languageId, languageName] preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
[alertController addAction:action];
[self presentViewController:alertController animated:YES completion:nil];
// TODO: reload viewcontroller or other works
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
Language and Locale IDs - Apple Developer
GSLanguagePickerController require iOS 8.0+.
GSLanguagePickerController is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "GSLanguagePickerController"The legacy localization bundle name in UIKit.framework has various types.
[English Name].lproj
Examples: English.lproj, French.lproj, German.lproj, Spanish.lproj
[Language Id]_[Region Id].lproj
Examples: zh_CN.lproj, zh_HK.lproj, zh_TW.lproj, en_GB.lproj
[Language Id]-[Script Id].lproj
Examples: zh-Hans.lproj, zh-Hant.lproj, es-ES.lproj
At present, type 2 can't be supported well, so UIBarButtonSystemItem and other components who uses UIKit bundle resource, may be affected until application relaunch.
gaosen, [email protected]
GSLanguagePickerController is available under the MIT license. See the LICENSE file for more info.