Zend Framework

Zend_Translate and automatic locale detection with directory scanning

Details

  • Type: Improvement Improvement
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Not an Issue
  • Affects Version/s: 1.8.0
  • Fix Version/s: 1.8.1
  • Component/s: Zend_Translate
  • Labels:
    None

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':

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

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 $

Activity

Hide
Thomas Weidner added a comment -

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.

Show
Thomas Weidner added a comment - 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: