我想用一个句子中间的数字本地化字符串。 我不使用的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;
}
The final label displayed is "确定要购买%i个炸弹道具吗? ($ %i)", the number are not substituted in.