Simple localized manager
Sometimes we need to change language of application "on fly", without changing device locale. This manager very helpfull for this purpose
- You can simple usage ALLocalizedString(key, comment) like are NSLocalizedString(key, comment)
- Or use you own table
- Plural support with awesone TTTLocalizedPluralString
Read article at alobanov.github.io
- In your AppDelegate file you configure manager
[[ALLocalizedManager sharedInstance] setLanguages:@[ @{@"ru": @"Русский"}, @{@"en": @"English"}, @{@"pt-PT": @"Portugal"} ]];
[[ALLocalizedManager sharedInstance] setDefaultLanguage:@"ru"];
-
After first running this manager uses default locale of device. Then user change language information stored at NSUserDefaults
-
You can change language by
NSString *newLang = @"ru";
ALLocalizationSetLanguage(newLang);
- You can observe language changes by
[[ALLocalizedManager sharedInstance] addChangeLanguageBlock:^(NSString *newLang) {
[self updateTitles:nil];
} forObject:self];
For append plural rule to you project follow next steps
-
Add .strings file by default named LocalizablePlural
-
Append to file localizable plural rules like this
/* Murloc */
"%d Murloc (plural rule: one)" = "%d мурлок";
"%d Murloc (plural rule: few)" = "%d мурлока";
"%d Murloc (plural rule: many)" = "%d мурлоков";
"%d Murloc (plural rule: other)" = "%d мурлока";
- Use plural like this
NSString *pluralString = ALLocalizedPluralString(@"Murloc", 4, nil);