我想用句子中的数字本地化字符串。我不使用 iOS 的 Localizable.strings 文件,因为它很乏味且容易出错,我可能会决定稍后重新措辞。
这是我所做的:
#define sf_buy_bombs @"Are you sure you want to buy %i bombs for $%i? "
其中“sf”后缀表示“字符串格式”
这是我需要使用它的时候:
[NSString stringWithFormat: [Helper getLocalizedStringWithString:sf_buy_bombs], num_shop_items_bundle, price_bombs]
以及处理翻译的辅助方法
+(NSString*) getLocalizedStringWithString: (NSString*) str {
if ([Helper isSimplifiedChinese]) {
if ([str isEqualToString:sf_buy_bombs]) {
return @"确定要购买%i个炸弹道具吗? ($ %i)";
}
}
return str;
}
最后显示的标签是“确定要购买%i个炸弹道具吗?($ %i)”,数字不会被替换。