gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 13:49:02 25 4
gpt4 key购买 nike

我有一个格式化的字符串,我正在让翻译人员处理它。

英语

"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];
returnString = msg;

期望的和实际的结果:

英语

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$@),但它(“声音”)仍然出现在输出字符串中。

我做错了什么?

最佳答案

这不是一个错误。编号参数不是 C 标准的一部分,而是 IEEE Std 1003.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.

关于iphone - Xcode 中省略参数的高级本地化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34558421/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com