iOS游戏本地化与string格式

我想本地化与一个句子内的数字string。 我不使用iOS的Localizable.strings文件,因为它是单调乏味,容易出错,我可能会稍后决定重写一些单词。

这是我做的:

#define sf_buy_bombs @"Are you sure you want to buy %i bombs for $%i? " 

其中'sf'后缀表示'string格式'

这里是我需要使用它的时候:

 [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)”,数字未被replace。

在你的助手类

 #define sf_buy_bombs @"Are you sure you want to buy %i bombs for $%i? " 

 +(NSString *)localizedStringWithString{ return sf_buy_bombs;//all other stuffs } 

在所需的class级中:

 NSString *string=[NSString stringWithFormat:[Helper localizedStringWithString],10,100]; NSLog(@"%@",string); //gives correct output as checked by me as : //Are you sure you want to buy 10 bombs for $100? 

编辑:用你的中文字体string: 在这里找工作模式。

在这里输入图像说明