gpt4 book ai didi

zend-framework - zend translate 加入多种文件语言

转载 作者:行者123 更新时间:2023-12-04 06:49:03 24 4
gpt4 key购买 nike

我正在尝试将 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/解释了我尝试做的事情,但它失败了:(它只翻译 self 的 .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

最佳答案

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

关于zend-framework - zend translate 加入多种文件语言,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4829873/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com