我是 Objective-C 的新手。这是我的问题:
在我的两个字符串文件中有以下两个条目:
(德语字符串文件)
/* Class = "IBUILabel"; text = "Import to DoS"; ObjectID = "GfF-rD-aDa"; */
"GfF-rD-aDa.text" = "Zu DT %lu importieren";
(英文字符串文件)
/* Class = "IBUILabel"; text = "Import to DoS"; ObjectID = "GfF-rD-aDa"; */
"GfF-rD-aDa.text" = "Import to DoS %lu";
我的代码如下:
self.importLabel.text = [NSString localizedStringWithFormat:NSLocalizedString(@"GfF-rD-aDa.text", nil), projectday];
根据苹果文档 NSLocalizedString需要一个键和一个评论。这就是我将 @"GfF-rD-aDa.text"放入第一个参数的原因,因为它与我的字符串文件中的键相同。
所以我希望它生成如下字符串:
"Zu DT 2 importieren"
和
"Import to DoS 2"
但它不起作用。输出文本为:
"GfF-rD-aDa.text"
我不允许更改字符串表中的键,因为我们使用脚本根据对象 ID 生成所有这些条目。
问候
最佳答案
尝试使用这个在 NSLocalizedStringFromTable 宏中指定您的字符串文件。
self.importLabel.text = [NSString stringWithFormat:NSLocalizedStringFromTable(@"GfF-rD-aDa.text", @"yourStringsFile", @"comment"), projectday];
关于ios - 具有变量值的格式化 NSLocalizedString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28876600/