Is it possible to localize a header with macros in Xcode?
Lets say for English 开发者_运维技巧i might want a size of a font to be 17.0f, but 13.0f for Spanish.
Can this be done?
You can anyway put a PLIST file (let's say "constants.plist") in your .lproj localized folders (put the PLIST file aside you Localizable.strings files, in en.lproj/fr.lproj/es.lproj/...).
The PLIST may then contain an NSDictionary of key/value pairs for each value you need to customize according to the user locale (e.g. your font size).
Then you can use:
NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"constants" ofType:@"plist"]; // will return the path of the plist in the right language-specific .lproj directory)
NSDictionary* constants = [NSDictionary dictionaryWithContentsOfFile:plistPath];
float fontSize = [[constants objectForKey:@"fontSize"] floatValue]; // or whatever key you use in your plist for this constant
This is then very easy to have a different constants.plist for each language of your app.
Figured it out. What I asked for is not possible. The header files are evaluated during build time but the localization is set during run time.
精彩评论