如何使用 POEdit 从特定域获取(可翻译)字符串 [英] How to get (translatable) strings from specific domain with POEdit
问题描述
我已经尝试了几个小时来寻找一种方法来设置 POEdit 以便它可以从特定的仅限域名
我的 gettext 函数如下所示:
function ri($id, $parameters = array(), $domain = 'default', $locale = null)
示例调用:
echo ri('Text %xyz%', array('%xyz%'=>100), 'myDomain');
我只需要抓取域 myDomain 的文本进行翻译,或者至少我希望 POEdit 将这些文本放入域特定的文件中.有办法吗?
我发现了几个相似的问题,但答案并没有真正告诉我该怎么做(我认为我是个菜鸟,必须用简单的英语解释才能理解):
于是我找了好几天终于想通了,终于在这里找到了答案:
http://sourceforge.net/mailarchive/message.php?msg_id=27691818><块引用>
xgettext 识别字符串中的上下文,并在 *.pot 文件中给出一个 msgctxt 字段,该字段被翻译软件识别为上下文并如此显示(检查显示上下文的 Pootle 图像下面)
这可以通过 3 种方式完成:
- 代码中的字符串的格式应该是_t('context','string');并且 xgettext 调用应该采用 --keyword=_t:1c,2 的形式(这基本上向 xgettext 解释了在关键字函数,第一个是上下文,第二个是字符串)
- 字符串格式为_t('string','context');并且 xgettext 调用应采用 --keyword=_t:1,2c 形式
- 代码中的字符串应该是 _t('context|string') 并且 xgettext 调用应该是 --keyword=_t:1g 形式
所以为了回答我自己的问题,我将此添加到 Poedit 的来源关键字"选项卡中:
ri:1,3c
ri 是函数名,1 是 stringid 的位置,3 是上下文/域的位置
希望这对其他人有帮助,我讨厌所有这些神秘的文件
I have been trying for hours finding a way to setup POEdit so that it can grab the text from specific domain only
My gettext function looks like this:
function ri($id, $parameters = array(), $domain = 'default', $locale = null)
A sample call:
echo ri('Text %xyz%', array('%xyz%'=>100), 'myDomain');
I will need to grab only the text with the domain myDomain to translate, or at least I want POEdit to put these texts into domain specific files. Is there a way to do it?
I found several questions that are similar but the answers don't really tell me what to do (I think I'm such a noob it must be explained in plain English for me to understand):
How to set gettext text domain in Poedit?
How to get list of translatable messages
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:
- 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)
- String in code in the format _t('string','context'); and xgettext invocation should be in the form --keyword=_t:1,2c
- 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
这篇关于如何使用 POEdit 从特定域获取(可翻译)字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!