我在这个论坛上读到,可以使用NSLocalizedString作为NSDictionary的关键。NSLocalizedString作为NSDictionary的关键
这是我的NSDictionary:
LABELS = [[NSDictionary alloc] initWithObjectsAndKeys:
NSLocalizedString(@"Threshold 0", @"Description for threshold 0") , @"threshold_0",
NSLocalizedString(@"Threshold 1", @"Description for threshold 1"), @"threshold_1",
NSLocalizedString(@"Threshold 2", @"Description for threshold 2"), @"threshold_2",
NSLocalizedString(@"Threshold 3", @"Description for threshold 3"), @"threshold_3",
NSLocalizedString(@"Threshold 4", @"Description for threshold 4"), @"threshold_4",
nil];
这是代码试图访问的NSDictionary:
NSString *key = [NSString stringWithFormat: @"threshold_%d",{MY_VARIABLE}];
NSString *text = [LABELS objectForKey: key];
其中{} MY_VARIABLE可容纳从0值到4
我有三个本地化(意大利,法国,西班牙)。我生成并翻译了所有“Localizable.strings”文件(在它的.lproj,fr.lproj和es.lproj文件夹中),但是当执行应用程序时,我只能看到主要的翻译,例如:阈值0,阈值1。 ..
我在哪里做错了?
谢谢你的回答。问题其实是我忘了将文件Localizable.strings添加到项目中。下次我会更聪明:)。 – MarcoSciamanna