zend translate加入多种文件语言

时间:2011-01-28 15:25:08

标签: zend-framework file translation multilingual

我想添加到我的语言文件,zend表单错误语言文件,可以在

中找到
ZendFramework-1.11.2.zip\ZendFramework-1.11.2\resources\languages

为了拥有本地化的表单验证器erorrs。这个博客http://www.thomasweidner.com/flatpress/2010/03/25/working-with-multiple-translation-sources/comments/解释了我尝试做什么,但它失败了:(它只翻译自我的.ini文件,不包括.php 这是我做的:

这是我的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" 

然后我有了这个

 <?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;
        }
    }

这是我的目录

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

1 个答案:

答案 0 :(得分:4)

仅仅通过查看您的代码,我无法告诉您太多。我怀疑你的问题可能是因为你创建了自己的资源插件,这对于这个目的来说是不合适的,有些东西没有正确引导,或者你的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'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);
}