zend Translation 加入多种文件语言

发布于 2024-10-14 22:28:33 字数 2451 浏览 2 评论 0原文

我正在尝试将 zend 表单错误语言文件添加到我的语言文件中,可以在 中找到该文件,

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

以便本地化表单验证器错误。此博客 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

[旋木] 2024-10-21 22:28:33

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

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);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文