2011-10-22 50 views
1

我在这个论坛上读到,可以使用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。 ..

我在哪里做错了?

回答

0

在模拟器中构建并运行您的应用程序。在Finder中打开〜/ Library/Application Support/iPhoneSimulator/your-ios-version/Applications/your-app-id /。

然后右键单击.app文件并选择“显示包内容”,查看本地化的字符串是否属于它们的位置。

最有可能的本地化资源不是您的目标的一部分。这些设备也是区分大小写的,所以“Localizable.strings”是正确的,而“localizable.strings”则不是。

如果文件存在但它仍然不能正常工作,请打开BBEdit中的文件并确保编码是little-endian UTF-16。 (或者你可以使用Terminal.app并输入“file path-to-strings-file”来查看编码类型)。

+0

谢谢你的回答。问题其实是我忘了将文件Localizable.strings添加到项目中。下次我会更聪明:)。 – MarcoSciamanna