What is the second parameter of NSLocalizedString()?

前端 未结 3 1754
长情又很酷
长情又很酷 2020-11-29 19:30

What is the *comment parameter in:

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

If I do this:



        
相关标签:
3条回答
  • 2020-11-29 19:42

    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...

    0 讨论(0)
  • 2020-11-29 19:53

    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.

    0 讨论(0)
  • 2020-11-29 20:04

    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";
    
    0 讨论(0)
提交回复
热议问题