7

The macros iOS has for creating localized strings are pretty awesome when used with genstrings. However, I'd like to create my own #define on top of one of the macros like so:

#define MyLocalizedStringWithDefaultValue(key, tbl, val, comment) \
NSLocalizedStringWithDefaultValue(key, tbl, [NSBundle mainBundle], val, comment)
#endif

Essentially, I always want to be going against the main bundle, so I don't feel the need to type it out every time. This works great in code, but genstrings doesn't pick up my macro. Is there anything I can do to make it pick up my custom macro? I saw on the man page that there's a routine parameter that looks like what I'm trying to do, but I was unable to get it to work.

Mike
  • 1,112
  • 1
  • 13
  • 20

1 Answers1

3

Type genstrings to see the help text. Notice the -s substring option. You want something like:

genstrings -s MyLocalizedString -o someDir *.m
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Yes, I tried that. The command I'm running is `genstrings *.m -s MyLocalizedStringWithDefaultValue` but it's not picking up the macro – Mike Dec 14 '12 at 16:29
  • 1
    That's the wrong value. Look at what I showed compared to what you are using for the `-s` option. – rmaddy Dec 14 '12 at 16:34
  • I'm still confused. Are you saying I should be using `MyLocalizedString` instead of `MyLocalizedStringWithDefaultValue`? That wouldn't make sense, as my macro is called `MyLocalizedStringWithDefaultValue`. – Mike Dec 14 '12 at 19:08
  • 2
    Yes, that is what I am saying. Run the `genstrings` command with no arguments and look at what it says for the `-s` argument. It expects the prefix to use instead of `NSLocalizedString`. – rmaddy Dec 14 '12 at 21:18
  • OK, I understand what you're saying now. I didn't see anything in the man page that made me think it was a prefix. It's still not working though. The output of genstrings is complaining that anything I pass through `MyLocalizedStringWithDefaultValue` is not a literal string and therefore not adding it to my strings file. Any idea why? – Mike Dec 17 '12 at 14:26
  • I don't know. Suggestion - instead of using your `MyLocalizedStringWithDefaultValue` macro, why not do `#define MB [NSBundle mainBundle]`. Then you can do `NSLocalizedStringWithDefaultValue(@"some.key", @"sometbl", MB, @"some val", @"some comment");` – rmaddy Dec 17 '12 at 17:43
  • 1
    I'm looking to remove the `bundle` and eventually `table` parameters altogether. The rest of my team is going to start hammering on this in a month or two, and the more I can prevent them from going away from the standard the better. – Mike Dec 17 '12 at 21:02
  • Heh. This is a crazy bit of customisation. It's like, "You can have it in any colour, as long as its black." – Benjohn Feb 10 '16 at 21:05