1

我想用句子中的数字本地化字符串。我不使用 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)”,数字不会被替换。

4

1 回答 1

1

在您的 Helper 类中

#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? 

编辑:使用您的中文字体字符串: 在此处查找工作模型。

在此处输入图像描述

于 2013-04-08T14:23:40.153 回答