6

我正在尝试翻译我的应用程序,但当有半个占位符时,我发现很难翻译。我需要找到以下代码:

[textView1 insertText:[NSString stringWithFormat:@"%@ è il %i/%i/%i. Il giorno delle settimana è %@. La Festa è compresa nel calcolo. \n", nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

我把文件localizable.string(英文):

"festaCompresa" = @"%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

然后我编辑了这段代码:

[textView1 insertText:[NSString stringWithFormat:NSLocalizedString(@"festaCompresaW, @""), nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

这没用。

4

2 回答 2

6

您的字符串文件有一个小错误,您已将@字符串作为NSString常量包含在内 - 文件格式使用引号中的字符串:

"festaCompresa" = "%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

顺便说一句:在为本地化创建格式字符串时,您可能需要使用位置格式,其中每个格式规范都包含参数的数量。例如:

"festaCompresa" = "%1$@ is the %2$i/%3$i/%4$i. the day of the week is %@. The holidays is included in the calculation. \n";

显然,上述字符串中不需要这样做,因为参数按提供的顺序包含在内。然而,在某些语言中,它们可能需要以不同的顺序排列,这就是它的完成方式。

于 2012-04-30T18:47:27.383 回答
5

你复制粘贴代码了吗?还是你重新输入的?因为如果你复制粘贴它,问题就在那里:

[textView1 insertText:[NSString stringWithFormat:NSLocalizedString(@"festaCompresaW, @""), nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

我想应该是

[textView1 insertText:[NSString stringWithFormat:NSLocalizedString(@"festaCompresa", @""), nomeFesta, giornoFesta, meseFesta, annoFestaModificato, ggSett]];

所以基本上是一个"而不是W

此外,在 Localizable.strings 中,您不要放在@引号前面,所以:

"festaCompresa" = @"%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

应该是这样的:

"festaCompresa" = "%@ is the %i/%i/%i. the day of the week is %@. The holidays is included in the calculation. \n";

希望能帮助到你

于 2012-04-30T18:54:34.733 回答