头文件iOS的本地化

时间:2011-09-06 13:35:09

标签: iphone xcode4

是否可以在Xcode中使用宏本地化标头?

让我们说英语我可能想要一个字体大小为17.0f,但西班牙语为13.0f。

可以这样做吗?

2 个答案:

答案 0 :(得分:2)

你可以在你的.lproj本地化文件夹中放一个PLIST文件(让我们说“constants.plist”)(将PLIST文件放在你的Localizable.strings文件旁边,在en.lproj / fr.lproj / es.lproj /中...)。

然后,PLIST可能包含您需要根据用户区域设置(例如您的字体大小)自定义的每个值的键/值对的NSDictionary。

然后你可以使用:

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

然后,对于您应用的每种语言,都可以很容易地使用不同的constants.plist。

答案 1 :(得分:1)

想出来。我要求的是不可能的。头文件在构建期间进行评估,但本地化是在运行时设置的。