Search code examples
gettextpoedit

In PO file for Poedit, How to provide keywords list, so that a comment is automatically extracted for each keyword?


I want to put keywords and comments in my source file.

the keywords documentation for gettext says: if keywordspec is of the form ‘id:argnum...,"xcomment"’, xgettext, when extracting a message from the specified argument strings, adds an extracted comment xcomment to the message.

I couldn't find any samples to help me with this.

This is my X-Pedit-KeywordsList header,

"X-Poedit-KeywordsList: __;_ex;\n"

And this is a sample line in my php source code:

_ex("unlock_level", "Available at level #.")

I expect the output to be:

# "Available at level #."
msgid "unlock_level"

How should I edit my keywordslist header (and/or the source)?


Solution

  • Poedit supports translator comments. I ended up adding localization keys to my source file like this:

    // TRANSLATORS: "Available at level #."
    __("unlock_level")
    

    And this is what I get in my po file by pressing the update button in Poedit:

    #. TRANSLATORS: "Available at level #."
    msgid "unlock_level"