Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...

When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Accessing source data

Sometimes it is useful to have access to the translation source data. Therefor the following two functions are provided.

The getMessageIds($locale = null) method returns all known message IDs as array.

When you want to know the message ID for a given translation then you can use the getMessageId() method.

The getMessages($locale = null) method returns the complete translation source as an array. The message ID is used as key and the translation data as value.

Both methods accept an optional parameter $locale which, if set, returns the translation data for the specified language. If this parameter is not given, the actual set language will be used. Keep in mind that normally all translations should be available in all languages. Which means that in a normal situation you will not have to set this parameter.

Additionally the getMessages() method can be used to return the complete translation dictionary using the pseudo-locale 'all'. This will return all available translation data for each added locale.


Attention: the returned array can be very big, depending on the number of added locales and the amount of translation data.

Example 979. Handling languages with adapters

// returns all known message IDs
$messageIds $translate->getMessageIds();

// or just for the specified language
$messageIds $translate->getMessageIds('en_US');

// returns all the complete translation data
$source $translate->getMessages();

Zend Framework