我用我的 zend 框架应用中工作着 Gedmo 转接扩展。 我的意思是, 以下代码创建 ext_ 翻译表, 并在表格中插入翻译文章 。
$article = new AppEntityArticle;
$article->setTitle( my title in en );
$article->setContent( my content in en );
$this->_em->persist($article);
$this->_em->flush();
//// first load the article
$article = $this->_em->find( AppEntityArticle , 1 /*article id*/);
$article->setTitle( my title in de );
$article->setContent( my content in de );
$article->setTranslatableLocale( de_de ); // change locale
$this->_em->persist($article);
$this->_em->flush();
// first load the article
$article = $this->_em->find( AppEntityArticle , 1 /*article id*/);
$article->setTitle( my title in es );
$article->setContent( my content in es );
$article->setTranslatableLocale( es_es ); // change locale
$this->_em->persist($article);
$this->_em->flush();
$article = $this->_em->getRepository( AppEntityArticle )->find(1/* id of article */);
echo $article->getTitle();
// prints: "my title in en"
echo $article->getContent();
// prints: "my content in en"
上述作品和打印了我在评论中所包括的内容。 但是,如果我把我的应用程序范围更改为 ES_ES, 它的输出结果是一样的, 似乎没有注意到当地的变化 。
在我的靴子里,它被设置如下:
public function _initLocale() {
$session = new Zend_Session_Namespace( myswaplocalesession );
if ($session->locale) {
$locale = new Zend_Locale($session->locale);
}
$config = $this->getOptions();
if (!isset($locale) || $locale === null) {
try {
$locale = new Zend_Locale(Zend_Locale::BROWSER);
} catch (Zend_Locale_Exception $e) {
$locale = new Zend_Locale($config[ resources ][ locale ][ default ]);
}
}
Zend_Registry::set( Zend_Locale , $locale);
echo $locale;
$translator = new Zend_Translate( gettext , APPLICATION_PATH . /../data/lang/ ,
null, array( scan => Zend_Translate::LOCALE_FILENAME, disableNotices => 1));
Zend_Registry::set( Zend_Translate , $translator);
Zend_Form::setDefaultTranslator($translator);
}
我错过了什么?