的iOS游戏与本地化字符串格式[关闭](iOS game Localization with Str

2019-10-17 23:56发布

我想用一个句子中间的数字本地化字符串。 我不使用的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.

Answer 1:

在助手类

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

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

在所需的类:

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? 

编辑:您的中国字体的字符串: 在这里找到工作模式。



文章来源: iOS game Localization with String Format [closed]