2

I'd like to use pgettext to specify the context of some strings to translate, I've found that you need to add it yourself in PHP, which is what I did following this post's instructions. I've changed it a little bit to make it work (the dcgettext function call had some errors):

function pgettext($context, $msgid) {
  $contextString = "{$context}\004{$msgid}";
  $translation = dcgettext('messages', $contextString, 5);
  if ($translation == $contextString) return $msgid;
  else return $translation;
}

But this function doesn't seems to work, the text is not changing when I change the language.

What am I missing?

Community
  • 1
  • 1
Zealot
  • 687
  • 4
  • 17

1 Answers1

4

I've found a solution that is working well for me:

function pgettext($context, $msgid) {
  $contextString = "{$context}\004{$msgid}"; 
  $translation = _($contextString); 

  if($translation == $contextString) return $msgid;
  else return $translation;
}
Zealot
  • 687
  • 4
  • 17