I must be having a (several) blonde moment(s), I have been over the docs for
translate and locale and I am still not getting it:

I have created a debug trace of the results from using my current method:
 
<BEGIN>
Return value of new Zend_Locale('auto'): fr_FR

_SERVER["HTTP_ACCEPT_LANGUAGE"]=fr-fr,de-de;q=0.7,en-gb;q=0.3

Registry contains:
Zend_Translate Object
(
    [_adapter:private] => Zend_Translate_Adapter_Csv Object
        (
            [_automatic:private] => 1
            [_options:protected] => Array
                (
                    [clear] => 
                    [scan] => 
                    [locale] => auto
                    [separator] => ;
                )

            [_translate:protected] => Array
                (
                    [de] => Array
                        (
                            [helloWorld] => Hallo Welt
                        )

                    [en] => Array
                        (
                            [helloWorld] => Hello World!
                        )

                )

        )

)
Display getList():
Array
(
    [de] => de
    [en] => en
)
Translate helloWorld: helloWorld
<END>

You can see from the above that I have set my browser language preference to
be French then German and finally English.  I am expecting Zend_Translate to
select German as I currently don't have a French translation file.  What I
get is the messageId only.

The code I am using is:

    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $frontendOptions = array('lifetime' => 7200);
        $backendOptions = array('cache_dir' =>
Zend_Registry::get('config')->general->sessionSavePath);
        $cache = Zend_Cache::factory('Page', 'File', $frontendOptions,
$backendOptions);
        Zend_Translate::setCache($cache);

        $options = array('scan' => Zend_Translate::LOCALE_DIRECTORY);

        $translate = new Zend_Translate('csv', 'lang', 'auto', $options);

        Zend_Registry::set('Zend_Translate', $translate);
    }

If I run the test again and set the browser to use German my trace gives me:

<BEGIN>
Return value of new Zend_Locale('auto'): de_DE

_SERVER["HTTP_ACCEPT_LANGUAGE"]=de-de,fr-fr;q=0.7,en-gb;q=0.3

Registry contains:
Zend_Translate Object
(
    [_adapter:private] => Zend_Translate_Adapter_Csv Object
        (
            [_automatic:private] => 1
            [_options:protected] => Array
                (
                    [clear] => 
                    [scan] => 
                    [locale] => auto
                    [separator] => ;
                )

            [_translate:protected] => Array
                (
                    [de] => Array
                        (
                            [helloWorld] => Hallo Welt
                        )

                    [en] => Array
                        (
                            [helloWorld] => Hello World!
                        )

                )

        )

)
Display getList():
Array
(
    [de] => de
    [en] => en
)
Translate helloWorld: Hallo Welt
<END>

This is correct and as expected.

Why won't my code + Zend_Translate downgrade through the languages my
browser sends?  Please help, I am now on my knees begging :-)



-----Original Message-----
From: Thomas Weidner [mailto:[EMAIL PROTECTED] 
Sent: 22 March 2008 23:43
To: Robert Castley; [email protected]
Subject: Re: [fw-general] Zend_Locale and browser detection question (ZF
1.5)

Robert,

as short summary:

*) Delete the else tree. Its not needed as described before.
*) Look at your array_key_exists clause... it's not doing what you expect it
to do.


________________________________________________________________________
This email has been scanned for all known viruses by the MessageLabs Email 
Security Service and the Macro 4 plc internal virus protection system.
________________________________________________________________________

Reply via email to