Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 828
Shmidt Avatar asked Dec 07 '25 20:12

Shmidt


1 Answers

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.

like image 56
saintjab Avatar answered Dec 09 '25 18:12

saintjab



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!