Scar
Scar

Reputation: 3480

Localize iPad app at run time

I'm developing an app that require a localization at run time, i mean that it will be a button to change the language instantly, i've searched about localization and what i've found is how to localize the app depend on the iPhone international language.

I've localize all the nib files i have and redesign each nib file according to it's language, but how i can change the nib file when the user click on the button ?

any help will be appreciated.

Upvotes: 3

Views: 489

Answers (2)

Infinite Possibilities
Infinite Possibilities

Reputation: 7476

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.

Upvotes: 3

Rob Napier
Rob Napier

Reputation: 299365

See my answer to Creating a localized iPhone app but allowing the user to change language for the application.

Basically, you split up your localizations into tables and bundles rather than using the built-in localization system. You look your strings up from per-language tables and your nib files from per-langage bundles.

Upvotes: 1

Related Questions