Mainly you can use a project created by someone: Advance Localization in iOS apps
Or there is another method, to implement it by yourself.You must have all localization files in your project:
@implementation Language
static NSBundle *bundle = nil;
+(void)initialize {
NSArray* languages = [NSLocale preferredLanguages];
NSString *current = [languages objectAtIndex:0];
[self setLanguage:current];
}
/*
example calls:
[Language setLanguage:@"it"];
[Language setLanguage:@"de"];
*/
+(void)setLanguage:(NSString *)l {
NSLog(@"preferredLang: %@", l);
NSString *path = [[ NSBundle mainBundle ] pathForResource:l ofType:@"lproj" ];
bundle = [[NSBundle bundleWithPath:path] retain];
}
+(NSString *)get:(NSString *)key alter:(NSString *)alternate {
return [bundle localizedStringForKey:key value:alternate table:nil];
}
@end
This code is good for what you need. But this is only the base. So each text must be loaded with the get:alter:
method, so it will be loaded in the correct language. As you see at initialization this class will use the system language, but after you call the setLanguage
method, then it will use the language you've setup. After you set a language with the get:alter:
method, you should reload all your text in your view controller, by calling the get:alter:
method again for each text that appears and set the result to the desired label or textfield or to any other NSString
type parameter that needs i18n. So there is more work, but this is a very good base. I don't think it can happen automatically, you have to code.