Shmidt
Shmidt

Reputation: 16664

Localization doesn't affect some .strings files

I use SORelativeDateTransformer in my project.

I localized my project (translated storyboard and created Localizable.strings(I used NSLocalizedString)) and that part translates perfect.

The problem is that SORelativeDateTransformer uses it's own SORelativeDateTransformer.strings(uses NSLocalizedStringFromTable), which works in demo, but not in my project.

Upd.: Found also that some labels, that I translated to Norwegian localization keep English words. Oughh!

Any ideas?

Upvotes: 3

Views: 273

Answers (1)

saintjab
saintjab

Reputation: 1642

I know this question is quite old but here is a solution I used. There is a way to force SORelativeDateTransformer to load a particular Localisation string base on your preference. If you did manual installation instead of using pod then you can edit the .m base on your preference. For instance this is how I am implementing it in the + (NSBundle*) bundle method

+ (NSBundle *)bundle {
static NSBundle *bundle = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    NSString *systemLanguage = [[[NSBundle mainBundle] preferredLocalizations] objectAtIndex:0];//you can use conditional statement after here to load a specific bundle since you now have you language codes here (e.g. 'en' for English, 'zh-Hans' for Chinese (Simplified) etc) 
    NSURL *url = [[NSBundle mainBundle] URLForResource:@"SORelativeDateTransformer" withExtension:@"bundle"];
    bundle = [[NSBundle alloc] initWithURL:url];
    NSString *path = [bundle pathForResource:systemLanguage ofType:@"lproj"];
    bundle = [NSBundle bundleWithPath:path];
});
return bundle;
}

This should do the trick.

Upvotes: 1

Related Questions