Jona
Jona

Reputation: 13555

Localizing multiple placeholders where order matters

I'm having a hard time figuring out how to localize a string with various placeholders where in some languages the order matters.

For example the following message where %1$s is song title and %2$s is the song artist. In Japanese the translation requires to show the song artist first an then song title. This is fairly easy with Android since the placeholder specifies the argument number it takes for input.

Android

<string name="share_listening_msg_2">I’m listening to “%1$s” by %2$s on #xiialive</string>

For iOS I'm having a hard time figuring out a solution since there is no placeholder ids like on Android.

iOS

"share_listening_msg_2"="I’m listening to “%@” by %@ on #xiialive";

Upvotes: 0

Views: 249

Answers (1)

Dima
Dima

Reputation: 23634

You can use order specifiers pretty much the same way.

Documentation here: https://developer.apple.com/library/ios/documentation/MacOSX/Conceptual/BPInternational/Articles/NotesForLocalizers.html

Relevant excerpt:

If a string contains multiple variable arguments, you can change the order of the arguments by using the “$” modifier plus the argument number

/* Message in alert panel when something fails */
"Oh %@! %@ failed!" = "%2$@ blah blah, %1$@ oh!";

Upvotes: 1

Related Questions