Skip to content

Instantly share code, notes, and snippets.

@dodikk
Last active September 15, 2016 22:30
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dodikk/5642176 to your computer and use it in GitHub Desktop.
Save dodikk/5642176 to your computer and use it in GitHub Desktop.
Dynamic localization for iOS
@implementation NSBundle( Dynamic )
-(NSString*)localizedStringForKey:(NSString*)key
value:(NSString*)value
table:(NSString*)table
locale:( NSLocale* )locale
{
// TODO : implement this category
NSString* shortLocaleId = [ locale shortLocaleIdentifier ];
// get en.lproj path somehow
NSString* path = [ self pathForResource: shortLocaleId
ofType: @"lproj"];
NSBundle *languageBundle = [NSBundle bundleWithPath:path];
NSString *str = [languageBundle localizedStringForKey: key value:value table:table];
return str;
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment