开发者

zend translate join multiple file languages

开发者 https://www.devze.com 2023-02-07 20:07 出处:网络
i am trying to add to my language file, the zend form errors language file, which can be found in ZendFramework-1.11.2.zip\\ZendFramework-1.11.2\\resources\\languages

i am trying to add to my language file, the zend form errors language file, which can be found in

ZendFramework-1.11.2.zip\ZendFramework-1.11.2\resources\languages

in order to have localized form validators erorrs. This blog http://www.thomasweidner.com/flatpress/2010/03/25/working-with-multiple-translation-sources/comments/ explains what i try to do, but it fails :( it only translates from my .ini file, the .php is not included Here is what i did:

开发者_高级运维this is my application.ini

resources.translate.adapter = "ini"
resources.translate.default.locale = "it_IT"
resources.translate.default.locale = "en_US"
resources.translate.default.file = APPLICATION_PATH "/lang/source-it.ini"
resources.translate.translation.en = APPLICATION_PATH "/lang/source-en.ini"
;resources.translate.data.directory = APPLICATION_PATH "/lang"
resources.translate.data = APPLICATION_PATH "/lang" 

and then i have this

 <?php
    class Gestionale_Application_Resource_Translate extends Zend_Application_Resource_ResourceAbstract
    {
        public function init ()
        {
            $options = $this->getOptions();
            $adapter = $options['adapter'];
            $defaultTranslation = $options['default']['file'];
            $defaultLocale = $options['default']['locale'];


            $translate = new Zend_Translate($adapter, $defaultTranslation, $defaultLocale);

            $translation_addme = new Zend_Translate(
                'array', 
APPLICATION_PATH."/resources/languages/it/Zend_Validate.php"
                'it',
                array('scan' => Zend_Translate::LOCALE_DIRECTORY)
            );
            $translate->addTranslation($translation_addme);

            foreach ($options['translation'] as $locale => $translation) {
                $translate->addTranslation($translation, $locale);
            }
            Zend_Registry::set('Zend_Translate', $translate);
            return $translate;
        }
    }

and this is my dir

c:\www\www\gestionale\application>dir /w /aD
 Il volume nell'unità C è OS
 Numero di serie del volume: 6A5E-FD9B

 Directory di c:\www\www\gestionale\application

[.]           [..]          [.svn]        [configs]     [controllers]
[forms]       [lang]        [layouts]     [models]      [resources]
[views]
               0 File              0 byte
              11 Directory  447.780.282.368 byte disponibili


Just by looking at your code I cannot tell you much. I suspect that your problems might be because you create your own resource plugin, which is unnessesry for this purpose, somethings are not being bootstrap properly, or there are some conflicts with your application.ini. Any way, I will post my translation setup and maybe it will give you some clues.

application.ini

Nothing here about translation or locale since I setup them in Bootstrap.php.

Bootstrap.php

protected function _initLocale() {
    // define locale
    $locale = new Zend_Locale('en');

    // register it so that it can be used all over the website
    Zend_Registry::set('Zend_Locale', $locale);
}

protected function _initTranslate() {
    // Get Locale
    $locale = Zend_Registry::get('Zend_Locale');


    // Set up and load the translations (there are my custom translations for my app)
    $translate = new Zend_Translate(
                    array(
                        'adapter' => 'array',
                        'content' => APPLICATION_PATH . '/languages/' . $locale . '.php',
                        'locale' => $locale)
    );

    // Set up ZF's translations for validation messages.
    $translate_msg = new Zend_Translate(
                    array(
                        'adapter' => 'array',
                        'content' => APPLICATION_PATH .
                        '/resources/languages/' . $locale . '/Zend_Validate.php',
                        'locale' => $locale)
    );

    // Add translation of validation messages
    $translate->addTranslation($translate_msg);

    Zend_Form::setDefaultTranslator($translate);

    // Save it for later
    Zend_Registry::set('Zend_Translate', $translate);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消