1

e.g.

In English:

He used <Str_1> to <Str_2>

and in Chinese:

他对 <Str_2> 使用了 <Str_1>

How can I order this two Strings (which are generated in code) differently for the code below?

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

I happened saw a related question before, but unluckily, I can't find it now!
The workaround is something like %2@ & %1@ to do reorder, I'm not sure.

Thanks in advance!

4

1 回答 1

6

In your localizable.strings file:

"He used %@ to %@" = "他对 %2$@ 使用了 %1$@";

In code:

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

This should re-order the string parameters.

于 2012-04-14T06:34:15.830 回答