Advanced Localization with Omission of Arguments in Xcode

Posted by coneybeare on Stack Overflow See other posts from Stack Overflow or by coneybeare
Published on 2010-05-31T16:10:11Z Indexed on 2010/05/31 16:13 UTC
Read the original article Hit count: 283

I have this formatted string that I am having a translator work on.

ENGLISH
"Check out the %1$@ %2$@ in %3$@: %4$@" = "Check out the %1$@ %2$@ in %3$@: %4$@"

GERMAN TRANSLATION
"Check out the %1$@ %2$@ in %3$@: %4$@" = "Hör Dir mal %2$@ in %3$@ an: %4$@";

These are passed to a [NSString stringWithFormat:] call:

//////////////////////////////////////
// Share Over Twitter
NSString *frmt = NSLocalizedString(@"Check out the %1$@ %2$@ in %3$@: %4$@", @"The default tweet for sharing sounds. Use %1$@ for where the sound type (Sound, mix, playlist) will be, %2$@ for where the audio name will be, %3$@ for the app name, and %3$@ for where the sound link will be.");
NSString *urlString = [NSString stringWithFormat:@"sounds/%@", SoundSoundID(audio)];
NSString *url = ([audio audioType] == UAAudioTypeSound ? UrlFor(urlString) : APP_SHORTLINK);
NSString *msg = [NSString stringWithFormat:
                 frmt,
                 [[Audio titleForAudioType:[audio audioType]] lowercaseString],
                 [NSString stringWithFormat:@"\"%@\"", AudioName(audio)],
                 APP_NAME, 
                 url];
NSString *applink = [NSString stringWithFormat:@" %@", APP_SHORTLINK];
if (msg.length <= (140 - applink.length)) {
    msg = [msg stringByAppendingString:applink];
}
returnString = msg;

With the desired and actual outcome of:

ENGLISH

desired: "Check out the sound "This Sound Name" in My App Name: link_to_sound link_to_app"
actual:  "Check out the sound "This Sound Name" in My App Name: link_to_sound link_to_app"

GERMAN

desired: "Hör Dir mal "This Sound Name" in My App Name an: link_to_sound link_to_app"
actual:  "Hör Dir mal sound in "This Sound Name" an: My App Name link_to_app"



THE PROBLEM The problem is that I was under the assumption that by using numbered variable in the NSLocalizedString, I could do things like this, where the %1$@ variable is completely omitted. If you notice, the German translation of the format string does not use the first argument (%1$@) at all but it ("sound") still appears in the output string.

What am I doing wrong?

© Stack Overflow or respective owner

Related posts about iphone

Related posts about iphone-sdk