Zend translate join multiple file languages

I am trying to add a language file of zend form errors to my language file, which can be found in

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

to have localized form validators. This blog http://www.thomasweidner.com/flatpress/2010/03/25/working-with-multiple-translation-sources/comments/ explains what I'm trying to do, but it fails :( it only translates from mine .ini file, .php not included Here is what I did:

this is my application.ini application

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 it

 <?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 catalog

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
+3
source share
1 answer

, . , - , , , - , application.ini. , , , , .

application.ini

, 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 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);
}
+4

Source: https://habr.com/ru/post/1788514/


All Articles