ZF-6612: Zend_Translate and automatic locale detection with directory scanning

Description

I have the following code:


$locale = new Zend_Locale(Zend_Locale::BROWSER);

$translate = new Zend_Translate(
    'gettext',
    $path,
    null,
    array('scan' => Zend_Translate::LOCALE_DIRECTORY));
    
// setting the right locale
if ($translate->isAvailable($locale->getLanguage())) {
    $translate->setLocale($locale);
} else {
    $translate->setLocale('it_IT');
}

In my $path I have it and fr subdirectories.

When initializing Zend_Translate, an implicit setLocale is called with the user's preferred locale according to his browser's preferences. Here is the error message I get if my preferred language is 'en': {quote} Notice: The language 'en_US' has to be added before it can be used. in /home/eserra/kingbid.it/library/Zend/Translate/Adapter.php on line 317 Notice: No translation for the language 'en' available. in /home/eserra/kingbid.it/library/Zend/Translate/Adapter.php on line 330 {quote}

I think that, in case of scan option the automatic locale detection should be disabled. At the end of the scan process, if the locale coming from user's browser is found it could be set, otherwise I think that no notices should be generated, this allow the developer to provide fallback code as I did in my snippet.

My .02 $

Comments

Or you simply disable the notices when you know that you don't need them. See the 'disableNotices' option within the manual.

That's how the manual describes this usecase.