O'Reilly logo

Cocoa Programming for OS X: The Big Nerd Ranch Guide by Aaron Hillegass, Adam Preble, Nate Chandler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Explicit Ordering of Tokens in Format Strings

As text is moved from language to language, both the words and the order of the words change. For example, the words in one language may be laid out like this: “Ted needs a scooter.” In another, the order might be “A scooter is what Ted needs.” Suppose that you try to localize the format string to be used like this:

l​e​t​ ​f​o​r​m​a​t​ ​=​ ​N​S​L​o​c​a​l​i​z​e​d​S​t​r​i​n​g​(​"​N​E​E​D​S​"​,​ ​c​o​m​m​e​n​t​:​ ​"​%​@​ ​n​e​e​d​s​ ​a​ ​%​@​"​)​
l​e​t​ ​s​t​r​i​n​g​ ​=​ ​S​t​r​i​n​g​(​f​o​r​m​a​t​:​ ​f​o​r​m​a​t​,​ ​"​I​"​,​ ​"​H​e​r​o​"​)​

The following will work fine for the first language:

"​N​E​E​D​S​"​ ​=​ ​"​%​@​ ​n​e​e​d​s​ ​a​ ​%​@​"​;​

For the second language, you would need ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required