johan
johan

Reputation: 6666

Localization of header files iOS

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?

Upvotes: 2

Views: 352

Answers (2)

AliSoftware
AliSoftware

Reputation: 32681

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.

Upvotes: 2

johan
johan

Reputation: 6666

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.

Upvotes: 1

Related Questions