I want to localize strings with numbers inside a sentence. I dont use iOS's Localizable.strings file since it's tedious and error prone and I may decide to rephrase words later on.
Here is what I did:
#define sf_buy_bombs @"Are you sure you want to buy %i bombs for $%i? "
where 'sf' suffix means 'string format'
here is when i need to use it:
[NSString stringWithFormat: [Helper getLocalizedStringWithString:sf_buy_bombs], num_shop_items_bundle, price_bombs]
and a helper method to handle the translation
+(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.