【发布时间】:2011-10-22 16:28:08
【问题描述】:
我在这个论坛上读到可以使用 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”文件(在 it.lproj、fr.lproj 和 es.lproj 文件夹中),但是当应用程序执行时,我只看到主要翻译,例如:Threshold 0、Threshold 1、. ..
我哪里做错了?
【问题讨论】:
标签: iphone ios localization nsdictionary