1

There is a gettext() function in PHP to lookup a message in the current domain.

Is there a way to fetch all messages from current domain?

umpirsky
  • 9,902
  • 13
  • 71
  • 96

3 Answers3

1

No, there isn't. The low-level libgettext API doesn't provide a means either.

You might use (and rewrite) the gettext Adapter from Zend_Translate (or php-gettext or gettext.php) to read out a whole gettext message file however.

mario
  • 144,265
  • 20
  • 237
  • 291
  • So basicly, to do that, you need to write parser for .mo files? – umpirsky Jan 19 '11 at 15:47
  • @umpirsky: Effectively yes. Or better a parser for the .po files if they are available (simpler text format). – mario Jan 19 '11 at 15:52
  • It still does not have provide any kind of "fetch_all_messages" method, does it? – mms27 Jul 14 '15 at 20:32
  • @mms27 Probably never will. The gettext API hasn't evolved since the 90s. Message catalogues are just key:value lookup files really. You might better go for a custom all-PHP implementation then. – mario Jul 14 '15 at 20:37
1

The PHP documentation says no.

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

The current domain by definition contains infinite messages, so your question is not so useful. The question "How to enumerate the messages within a particular message catalog?" may be more suitable.

Get translations from .po or .mo file

This is possible on the command line, e.g.

$ msgcat <catalog-name>
...
#: conf/global_settings.py:44
msgid "Arabic"
msgstr "Árabe"

#: conf/global_settings.py:45
msgid "Bengali"
msgstr "Bengalês"
Community
  • 1
  • 1
Steve-o
  • 12,678
  • 2
  • 41
  • 60