Make xcodebuild -exportLocalizations know how to parse a custom macro NSLocalizedString

Using the inline macro:

NSLocalizedStringWithDefaultValue(@"fantasy-group.group-rank.stats-label", nil, [NSBundle mainBundle], @"Group Rank", nil); 

Results in the following block in the resulting .xliff file when exporting for localization:

  <trans-unit id="fantasy-group.group-rank.stats-label"> <source>Group Rank</source> <note>No comment provided by engineer.</note> </trans-unit> 

This works as expected since source :

The main advantage of these macros is that they can be analyzed by genstrings and used to create files for your applications.

But if I try to get confused with my own macro to avoid specifying a table and package, and possibly specify my own table in an attempt to split a string file :

 #define WSLLocalizedString(key, val, comment) \ [[NSBundle mainBundle] localizedStringForKey:(key) value:(val) table:nil] [WSLLocalizedString(@"fantasy-group.group-rank.stats-label", @"Group Rank", nil); 

It does not receive Xcode or the associated command line tool when trying to generate an xliff file:

 $ xcodebuild -exportLocalizations -localizationPath WSL/Translations/ -project WSL.xcodeproj 

If I were just doing genstrings, I could do the following source :

 find . -name *.m | xargs genstrings -o en.lproj -s WSLLocalizedString 

But I want xliffs. Is there a parameter that I can pass to xcodebuild to keep this dream alive?

+4
source share
1 answer

Not sure about Objective-C, but I did it for Swift, overriding the NSLocalizedString function as follows:

 public func NSLocalizedString(key: String, tableName: String? = nil, bundle: NSBundle = NSBundle.mainBundle(), value: String = "", comment: String) -> String { return yourBundleHere.localizedStringForKey(key, value: value, table: tableName) } 

In my case, I needed to use custom NSBundle .

+1
source

All Articles