PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, August 31, 2022

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

 August 31, 2022     dns, gettext, poedit     No comments   

Issue

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


Solution

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



Answered By - mr1031011
Answer Checked By - Mary Flores (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing