Xcode中省略参数的高级本地化 [英] Advanced Localization with Omission of Arguments in Xcode
问题描述
我有一个正在翻译的格式化字符串.
I have this formatted string that I am having a translator work on.
ENGLISH
ENGLISH
"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;
预期的和实际的结果:
ENGLISH
ENGLISH
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$@
),但是它(声音")仍会出现在输出字符串中.
THE PROBLEM
The problem is that I was under the assumption that by using numbered variable in the -[NSString stringWithFormat:]
, 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.
我在做什么错了?
推荐答案
这不是错误.带编号的参数不是C标准的一部分,而是IEEE Std 1003.1的一部分,它表示以下内容(强调我的意思):
This is not a bug. Numbered arguments are not part of the C standard, but part of IEEE Std 1003.1, which says the following (emphasis mine):
格式可以包含带编号的参数转换规范(即%n $"和"* m $"),也可以包含无编号的参数转换规范(即%和*),但不能同时包含两者.唯一的例外是%%可以与%n $"形式混合使用.在格式字符串中混合编号和未编号的参数说明的结果是不确定的. 使用带编号的参数规范时,指定第N个参数要求在格式字符串中指定所有从第一个到第(N-1)个前导参数.
The format can contain either numbered argument conversion specifications (that is, "%n$" and "*m$"), or unnumbered argument conversion specifications (that is, % and * ), but not both. The only exception to this is that %% can be mixed with the "%n$" form. The results of mixing numbered and unnumbered argument specifications in a format string are undefined. When numbered argument specifications are used, specifying the Nth argument requires that all the leading arguments, from the first to the (N-1)th, are specified in the format string.
这篇关于Xcode中省略参数的高级本地化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!