recentpopularlog in

adrianoconnor : ios   159

later »
taskpaper  ios 
july 2015 by adrianoconnor
iphone - How to force NSLocalizedString to use a specific language - Stack Overflow

#import <objc/runtime.h>

static const char _bundle=0;

@interface BundleEx : NSBundle

@implementation BundleEx
-(NSString*)localizedStringForKey:(NSString *)key value:(NSString *)value table:(NSString *)tableName
NSBundle* bundle=objc_getAssociatedObject(self, &_bundle);
return bundle ? [bundle localizedStringForKey:key value:value table:tableName] : [super localizedStringForKey:key value:value table:tableName];

@implementation NSBundle (Language)
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^
object_setClass([NSBundle mainBundle],[BundleEx class]);
objc_setAssociatedObject([NSBundle mainBundle], &_bundle, language ? [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:language ofType:@"lproj"]] : nil, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
ios  iphone  language  localise  localisation  NSBundle  back 
june 2015 by adrianoconnor

Copy this bookmark:

to read