2012-04-14 68 views
1

重新排列i18n的字符串格式

英文:

He used <Str_1> to <Str_2> 

和中國:

他對 <Str_2> 使用了 <Str_1> 

如何訂購這兩String秒(這是在代碼生成)爲不同下面的代碼?

[NSString stringWithFormat:@"%@ %@ %@ %@", 
     NSLocalizedString(@"Part1", nil),  // "He used" -> "他對" 
     NSLocalizedString(str_1, nil), 
     NSLocalizedString(@"Part3", nil),  // "to" -> "使用了" 
     NSLocalizedString(str_2", nil), nil]; 

我以前見過一個相關的問題,但不幸的是,我現在找不到它!
解決方法是類似%[email protected] & %[email protected]做重新排序,我不確定。

在此先感謝!

+0

嘿,downvote爲什麼?! – Kjuly 2012-04-14 12:10:22

回答

6

在你localizable.strings文件:

"He used %@ to %@" = "他對 %[email protected] 使用了 %[email protected]"; 

在代碼:

[NSString stringWithFormat: NSLocalizedString(@"He used %@ to %@", nil), 
    str1, str2]; 

這應該重新排序字符串參數。

+0

就是這樣!謝謝!!! – Kjuly 2012-04-14 06:44:57