We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Phalcon\Translate\Adapter\Gettext not supporting msgctxt (context)

Why Phalcon\Translate\Adapter\Gettext doesn't support msgctxt? msgctxt gives context to the translated word or expression.

So for example:

# messages.po file (Croatian translation)

msgctxt "optionInForms"
msgid "yes"
msgstr "da"

msgctxt "confirmation"
msgid "yes"
msgstr "OK"

Basicly, one can't use:

// This worked in Incubator Gettext class, which got removed from the Incubator
$this->getDi()->get('translation)->__('yes', 'optionInForms'); // notice double _

Now, I have the Incubator Gettext class saved and it works flawlessly, but I have two questions:

  • Did I miss something in Phalcon\Translate\Adapter\Gettext and the above can work somehow?
  • If the above can't work, why was the Incubator Gettext class removed?

I think you should create issue on github.

NFR, not affect old code if:

public string t (string $translateKey, [array $placeholders]) 

add:

public string t (string $translateKey, [array $placeholders], [string $context])

https://docs.phalcon.io/en/latest/api/Phalcon_Translate_Adapter_Gettext.html