How to get (translatable) strings from a specific domain using POEdit

I spent many hours trying to find a way to configure POEdit so that it can only capture text from a specific domain

My gettext function looks like this:

function ri($id, $parameters = array(), $domain = 'default', $locale = null) 

Sample call:

 echo ri('Text %xyz%', array('%xyz%'=>100), 'myDomain'); 

I will only need to capture text with the myDomain domain for translation, or at least I want POEdit to put these texts in files of a specific domain. Is there any way to do this?

I found several questions that are similar, but the answers don't really tell me what to do (I think I'm so noob that I need to explain in plain English so that I can understand):

How to set text text domain in Poedit?

How to get a list of translated messages

+4
source share
2 answers

So, I finally figured it out after a few days of searching, I finally found the answer here:

http://sourceforge.net/mailarchive/message.php?msg_id=27691818

  • xgettext recognizes the context in the lines and gives the msgctxt field in the * .pot file, which is recognized by the translation software as a context and displays as such (check the Pootle context image below)

    • There are three ways to do this:

      • The line in the code should be in the format _t ('context', 'string'); and the xgettext call should be in the form --keyword = _t: 1c, 2 (this basically explains xgettext that there are 2 arguments to the keyword function, the first is the context, the second is the string)
      • A string in the code in the format _t ('string', 'context'); and the xgettext call should be in the form --keyword = _t: 1,2c
      • The line in the code should be like _t ('context | string'), and the xgettext call should be in the form --keyword = _t: 1g

So, to answer my own question, I added this to the "keywords keywords" tab in Poedit:

 ri:1,3c 

ri is the name of the function, 1 is the location of the stringid, 3 is the location of the context / domain

Hope this helps someone else, I hate all these cryptic documents

+7
source

(This is the answer of my answer to the same here .)

Neither the GNU gettext tools nor the Poedit (which uses them) support this misuse of gettext.

In gettext, a domain is roughly a “piece of software” —a program, library, plugin, theme. Thus, it is usually located in one directory tree and is located there alone - or at least if you have several pieces = domains, you can organize them in some subdirectories that you can limit to extraction.

Mixing and matching domains in the same file, just like you, is not how gettext should have been used, and there is no reasonable solution to handle it except using your own helper function, for example. wrapping all myDomain texts in __mydomain (which you should define, obviously) and adding this to the keyword list in Poedit when retrieving for myDomain and not adding it to the keyword list for files of other domains.

+1
source

All Articles