ios NSLocalizedString() 的第二个参数是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1442822/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-30 16:24:56  来源:igfitidea点击:

What is the second parameter of NSLocalizedString()?

iosobjective-cswiftxcodelocalization

提问by 4thSpace

What is the *commentparameter in:

里面的*comment参数是什么:

NSString *NSLocalizedString(NSString *key, NSString *comment)

If I do this:

如果我这样做:

NSLocalizedString(@"Hello_World_Key", @"Hello World")

and have two versions of a Localizable.strings (English and Spanish), does each need the entry:

并且有两个版本的 Localizable.strings(英语和西班牙语),是否每个都需要条目:

English.lproj/Localization.strings: @"Hello_World_Key" = @"Hello World";

Spanish.lproj/Localization.strings: @"Hello_World_Key" = @"Hola Mundo";

Isn't the English one redundant?

英文不是多余的吗?

采纳答案by Alex Reynolds

The comment string is ignored by the application. It is used for a translator's benefit, to add meaning to the contextual usage of the key where it is found in your application.

应用程序将忽略注释字符串。它用于翻译人员的利益,为在您的应用程序中找到的密钥的上下文使用添加含义。

For example, the Hello_World_Keykey may take different values in a given language, depending on how formal or informal the Hello Worldphrase needs to be in that language ("What's up World", "Yo World", "Good Day World", etc.).

例如,Hello_World_Key键在给定的语言中可能采用不同的值,这取决于Hello World短语在该语言中的正式或非正式程度(“What's up World”、“Yo World”、“Good Day World”等)。

You can add a string in the comment field to hint this usage to the translator, who will (one would presume) be better able to localize your application.

您可以在注释字段中添加一个字符串,以向翻译人员暗示这种用法,他们(有人会认为)能够更好地本地化您的应用程序。

回答by Rob Keniger

The second parameter is a comment that will automatically appear in the strings file if you use the genstringscommand-line utility, which can create the strings file for you by scanning your source code.

第二个参数是一个注释,如果您使用genstrings命令行实用程序,它将自动出现在字符串文件中,它可以通过扫描您的源代码为您创建字符串文件。

The comment is useful for your localizers. For example:

该注释对您的本地化人员很有用。例如:

NSLocalizedString(@"Save",@"Title of the Save button in the theme saving dialog");

When you run genstrings, this will produce an entry in the Localizable.strings file like this:

当您运行 genstrings 时,这将在 Localizable.strings 文件中生成一个条目,如下所示:

/* Title of the Save button in the theme saving dialog */
"Save" = "Save";

回答by Shanmugaraja G

It's for just developer understanding on the translation, that is you are giving a key to get corresponding string from the corresponding strings file.

这只是为了开发人员对翻译的理解,即您提供了从相应字符串文件中获取相应字符串的密钥。

The comment parameter enables developer to understand what the key represents...

注释参数使开发人员能够了解密钥代表什么...