How to get (translatable) strings from specific domain with POEdit

有些话、适合烂在心里 提交于 2019-11-29 05:10:46

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

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

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

    • This can be done in 3 ways:

      1. String in code should be in the format _t('context','string'); and xgettext invocation should be in the form --keyword=_t:1c,2 (this basically explains to xgettext that there are 2 arguments in the keyword function, 1st one is context, 2nd one is string)
      2. String in code in the format _t('string','context'); and xgettext invocation should be in the form --keyword=_t:1,2c
      3. String in the code should be as _t('context|string') and xgettext invocation should be in the form --keyword=_t:1g

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

ri:1,3c

ri is the function name, 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

Václav Slavík

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

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

In gettext, domain is roughly “a piece of software” — a program, a library, a plugin, a theme. As such, it typically resides in a single directory tree and is alone there — or at the very least, if you have multiple pieces=domains, you have them organized sanely into some subdirectories that you can limit the extraction to.

Mixing and matching domains within a single file as you do is not how gettext was intended to be used, and there’s no reasonable solution to handle it other than using your own helper function, e.g. by wrapping all myDomain texts into __mydomain (which you must define, obviously) and adding that to the list of keywords in Poedit when extracting for myDomain and not adding that to the list of keywords for other domains' files.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!