在Xcode中省略参数的高级本地化

con*_*are 6 iphone localization internationalization nslocalizedstring

我有这个格式化的字符串,我正在翻译工作.

英语

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

德国翻译

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

这些传递给一个[NSString stringWithFormat:]电话:

//////////////////////////////////////
// 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];
returnString = msg;
Run Code Online (Sandbox Code Playgroud)

具有以下期望和实际结果:

英语

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

德语

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



问题 问题是我假设通过使用编号变量-[NSString stringWithFormat:],我可以做这样的事情,其中%1$@变量被完全省略.如果您注意到,格式字符串的德语翻译根本不使用第一个参数(%1$@),但它("声音")仍然出现在输出字符串中.

我究竟做错了什么?

dre*_*lax 7

这不是一个错误.编号参数不是C标准的一部分,而是IEEE Std 1003.1的一部分,其中说明了以下内容(强调我的):

格式可以包含编号参数转换规范(即"%n $"和"*m $"),或无编号参数转换规范(即%和*),但不能同时包含两者.唯一的例外是%%可以与"%n $"表单混合使用.在格式字符串中混合编号和未编号参数规范的结果是未定义的.当使用带编号的参数规范时,指定第N个参数要求在格式字符串中指定从第一个到第(N-1)个的所有前导参数.