Can genstrings work on custom #defines?
Asked Answered
T

1

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.

Tristantristas answered 14/12, 2012 at 15:59 Comment(0)
I
4

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

genstrings -s MyLocalizedString -o someDir *.m
Inbred answered 14/12, 2012 at 16:3 Comment(8)
Yes, I tried that. The command I'm running is genstrings *.m -s MyLocalizedStringWithDefaultValue but it's not picking up the macroTristantristas
That's the wrong value. Look at what I showed compared to what you are using for the -s option.Inbred
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.Tristantristas
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.Inbred
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?Tristantristas
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");Inbred
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.Tristantristas
Heh. This is a crazy bit of customisation. It's like, "You can have it in any colour, as long as its black."Syncope

© 2022 - 2024 — McMap. All rights reserved.