1

As per this blog post you can localise a story board with IBInspectable extensions in swift. we can rely Localizable.strings file alone instead of having localised story boards and worrying about multiple files for strings.

So my question is how to achieve the same with objective c? If the answer is not possible what is the best approach for keeping all the UI facing strings in one single file and fetching it.

Bluewings
  • 3,438
  • 3
  • 18
  • 31
  • to rephrase my question: I dont want to use two different strings files like one for storyboards and one for .m files. So is there any way to use only one strings file for localization. – Bluewings Sep 09 '15 at 11:00
  • 1
    The number of .strings files shouldn't matter since you're technically supposed to export an Xliff file (which contains all the content from all .strings files) by selecting your project file in Xcode, then Editor -> Export for Localization – wakachamo Sep 09 '15 at 13:13

1 Answers1

4

Are you aware you can use those extensions from Objective-C the same as you would in Swift, right? Anyway, to do the same in Objective-C you just create categories with the IBInspectable attribute.

@interface UILabel(LocalizationUtils)
@property (nonatomic, weak) IBInspectable NSString *localizedText;
@end

@implementation UILabel(LocalizationUtils)

- (void)setLocalizedText:(NSString*)localizedText {
    self.text = NSLocalizedString(localizedText, @"");
}

- (NSString*)localizedText {
    return @"";
}

@end
Rafael Nobre
  • 5,062
  • 40
  • 40