iOS: How to localize strings with multiple interpolated parameters?

前端 未结 1 1427
梦毁少年i
梦毁少年i 2021-01-12 04:26

How do I use NSLocalizedString to build a string with multiple parameters while giving the translator control to change the order if they wish?

An example in my Loca

相关标签:
1条回答
  • 2021-01-12 04:37

    According to the documentation

    https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW2

    Note that you can also use the “n$” positional specifiers such as %1$@ %2$s

    So you can simply create your string as

    "score_out_of"="Your score is %1$i out of %2$i"

    And in other language, it could be

    "score_out_of"="Out of %2$i, your score is %1$i"

    0 讨论(0)
提交回复
热议问题