What is the second parameter of NSLocalizedString()?
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";
The comment parameter is used for ease in translation. It has nothing to do with output of NSLocalizedString function. It will help just translator to translate nothing else.
According to Localizing Your App documentation, you can export localizations for a localization team. The comments you put in NSLocalizedString
are included in the exported files.
Exporting localizations creates files with xliff
extension, which contains XML like the code below.
<trans-unit id="Settings">
<source>Settings</source>
<target>설정</target>
<note>Label of the button to Settings screen</note>
</trans-unit>
<trans-unit id="Take Photo">
<source>Take Photo</source>
<target>사진 찍기</target>
<note>No comment provided by engineer.</note>
</trans-unit>
XLIFF
files can be edited using app localization tools like XLIFFTool.
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.