Search code examples
phpinternationalizationgettextzend-framework3xgettext

Handle textDomains with zend-framework3 and gettext




We're using ZF3 for a large app with internationalization.
i18n is done with zend-i18n, zend-mvc-i18n, and xgettext cli for extraction / compilation of pot / po / mo files.
For some words like Contact which could be a verb or a noun, we've specified a $textDomain : $this->translate('Contact', 'Verb') or $this->translate('Contact', 'Noun').

Problem is, when we extract those strings, it's all in the same pot file.
Since Zend load translation files by textDomain, it would be better if we could split pot files by textDomain, but it seems like xgettext can't do that.

Could someone help us to manage properly textDomains with Zend and gettext?


Solution

  • For those who may have the same problem, we ended up creating our own Gettext file loader, which properly parses msgctxt and returns a TextDomain structured by msgctxt.
    We also created our own Translator extends Zend\I18n\Translator\Translator to override loadMessagesFrom... functions and properly update the $this->messages variable