开发者

Localization of header files iOS

开发者 https://www.devze.com 2023-04-03 03:44 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消