0

I had create a framework that send data to server. Whenever I get response from the server I translate it using NSLocalizedString but it not working.

I tried to change Main Bundle to my Framework Bundle like this :

NSString* mainBundlePath = [[NSBundle mainBundle] resourcePath];
NSString* frameworkBundlePath = [mainBundlePath stringByAppendingPathComponent:@"Frameworks/MYFRAMEWORK.framework"];
NSBundle *bundle = [NSBundle bundleWithPath:frameworkBundlePath];

[bundle localizedStringForKey:@"Message" value:@"" table:nil];

But still not working. is there any way to localized message when the Localizable.string is inside the framework ?

Thanks

victorz
  • 39
  • 1
  • 12

2 Answers2

1

Finally, I tried to recreate Localizable.string and whenever I want to localize I use this :

NSString *message = [[NSBundle bundleForClass:self.class] localizedStringForKey:@"MESSAGE" value:nil table:nil];

I put this code inside class of framework, so bundle of self.class is direct to framework bundle. Thank's for everybody help.

victorz
  • 39
  • 1
  • 12
0

Try to use [NSBundle bundleForClass:self.class].

Anton Malmygin
  • 3,406
  • 2
  • 25
  • 31
  • Hi Anton, NSString *message = [[NSBundle bundleForClass:self.class] localizedStringForKey:@"Message" value:@"" table:nil]; still not working – victorz Jan 30 '17 at 10:04
  • Strange... What is your bundle configuration? Also, this link maybe helpful for your https://github.com/davbeck/TUSafariActivity/blob/master/Pod/Classes/TUSafariActivity.m#L45 – Anton Malmygin Jan 30 '17 at 10:45
  • What is self.class here? Make sure it is the class from the framework. – jesse Jan 30 '17 at 11:54
  • I tried to NSLog [NSBundle bundleForClass:self.class] when I put in class framework and it show the right path with comment "(loaded)". but when I tried log [mainBundlePath stringByAppendingPathComponent:@"Frameworks/MYFRAMEWORK.framework"] , it show different path with comment "(not yet loaded)". why bundle with self.class still not working to localizedString ?? – victorz Jan 31 '17 at 02:49