2

Well title says pretty much all of it.

I am using Xcode6.1 (6A1052d).

I have a header file (LocalString.h) in which I have defined some common NSLocalizedStrings like this

#define LocalStringYESButtonTitle NSLocalizedStringWithDefaultValue(@"YES", nil, [NSBundle mainBundle], @"YES", @"General YES button label")

Now when I "Export For Localization..." in resulting .xliff file I don't have strings defined in header.

Any ideas?

user1264176
  • 1,118
  • 1
  • 9
  • 26

3 Answers3

6

Well, it appears that Xcode doesn't parse header files (.h) for NSLocalizedString macros.

I have ended up with putting all definitions into .m file and include it in my .h file. This is just in order not to change includes in other files.

In LocalString.h

#import "LocalString.m"

In LocalString.m

#define LocalStringYESButtonTitle NSLocalizedStringWithDefaultValue(@"YES", nil, [NSBundle mainBundle], @"YES", @"General YES button label")
user1264176
  • 1,118
  • 1
  • 9
  • 26
2

Try using an extern NSString rather than a #define. There might be another error causing problems but XCode might purposely not mess with macros.

in your .h

extern NSString *LocalStringYESButtonTitle;

in your .m

NSString *LocalStringYESButtonTitle = NSLocalizedStringWithDefaultValue(@"YES", nil, etc...);
KirkSpaziani
  • 1,962
  • 12
  • 14
  • This will not work since such strings should be compile time devisable. Well I could put them into some class as getter methods but anyway I have found out what the problem was. – user1264176 Dec 10 '14 at 10:17
1

Most likely the "Export for Localization…" action has the same flaw as the old genstrings tool: it parses the source non-pre-processed and thus will ignore your own macros. It's likely looking for the official macros like NSLocalizedString and NSLocalizedStringWithDefaultValue. You can tell genstrings about your macros but it doesn't look like you can do the same with the integrated "Export for Localization…"

The best solution therefor is the one @KirkSpaziani proposed: instead of using macros, use extern variables (you need to make sure they are correctly initialized before you use them, of course).

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224
  • I don't redefine macros in terms of functionality. As appeared the problem was in defining macros in header file. – user1264176 Dec 10 '14 at 10:48