views:

848

answers:

2

What is the *comment parameter in:

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 es), does each need the entry:

English: @"Hello_World_Key" = @"Hello World";

Spanish: @"Hello_World_Key" = @"Hola Mundo";

Isn't the English one redundant?

+16  A: 

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

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:

/* Title of the Save button in the theme saving dialog */
"Save" = "Save";
Rob Keniger
+8  A: 

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_Key key may take different values in a given language, depending on how formal or informal the Hello World phrase needs to be in that language ("What's up World", "Yo World", "Good Day World", etc.).

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.

Alex Reynolds