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

Checking for translations

Normally text will be translated without any computation. But sometimes it is necessary to know if a text is translated or not, therefor the isTranslated() method can be used.

isTranslated($messageId, $original = false, $locale = null) takes the text you want to check as its first parameter, and as optional third parameter the locale for which you want to do the check. The optional second parameter declares whether translation is fixed to the declared language or a lower set of translations can be used. If you have a text which can be returned for 'en' but not for 'en_US' you will normally get the translation returned, but by setting $original to TRUE, isTranslated() will return FALSE.

Example 975. Checking if a text is translatable

= array(
'message1' => 'Nachricht 1',
'message2' => 'Nachricht 2',
'message3' => 'Nachricht 3');

$translate = new Zend_Translate(
'adapter' => 'array',
'content' => $english,
'locale' => 'de_AT'

if (
$translate->isTranslated('message1')) {
"'message1' can be translated";

if (!(
$translate->isTranslated('message1'true'de'))) {
"'message1' can not be translated to 'de'"
" as it's available only in 'de_AT'";

if (
$translate->isTranslated('message1'false'de')) {
"'message1' can be translated in 'de_AT' as it falls back to 'de'";

Zend Framework