我在這個論壇上讀到,可以使用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