All my calls of NSLocalizedString have nil as second param, because i don't use any comments. But i hate to repeat myself. Now i'm asking myself if it's ok to define a macro like LSSTRING(str) that calls NSLocalizedString(str, nil), and if so how?
Asked
Active
Viewed 3,293 times
2 Answers
10
You can. Add the following macro to your pre-compiled header. ie., in {ProjectName}-Prefix.pch file
#define LSSTRING(str) NSLocalizedString(str, nil)

Ilanchezhian
- 17,426
- 1
- 53
- 55
-
4One problem with this approach is that genstrings expects to find a string for the comment, and will give an error like this: `Bad entry in file ... (line = #): Argument is not a literal string.` – Eric Baker Mar 07 '12 at 15:42
-
3In Xcode, just do a find/replace like this: Find: LSSTRING\((@\"\w+\")\) Replace: NSLocalizedString\(\1, \1\) – Damon May 14 '14 at 14:06
2
im using
#define _(format, ...) [[NSBundle mainBundle] localizedStringForKey: [NSString stringWithFormat:@"%@", [NSString stringWithFormat:format, ##__VA_ARGS__]] value:@"" table:nil]

RolandasR
- 3,030
- 2
- 25
- 26