English 中文(简体)
理论扩展( Gedmo) 可翻换 - 如何根据当前语法显示翻译实体
原标题:Doctrine extensions (Gedmo) Translatable - how display translated entity based on current locale

我用我的 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);
    }

我错过了什么?

问题回答

你必须告诉Gedmo,默认情况下,必须使用什么地方。

当您知道要使用什么位置时, 您可以添加这些行 :

$listener = $this->getDoctrine()->getEventManager()->getListener(
     GedmoTranslatableTranslatableListener 
);

$listener->setTranslatableLocale($locale);




相关问题
Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

Link to a specific step in onepage checkout

Is it possible to redirect the browser to nth step in the onepage checkout? If so, how would one go about doing it? I m working on a payment module and have a sort of "cancel" action that i would ...

Tagging with Zend Framework

I m trying to create the same solutions as below, but using a simple MySQL query (instead of the static version used below where the words/tags are implemented in the code). The name of the MySQL ...

dynamicaly adding textboxes to zend_form

I hope that this is a quick question to answer. I am developing a form using Zend_Form, I have a number of Zend_Dojo_Form_Element_Textboxs to add to this form dynamically. These are added from rows ...

热门标签