zend フレームワーク アプリケーションで動作する gedmo 翻訳可能な拡張機能があります。つまり、次のコードは ext_translations テーブルを作成し、翻訳された記事をテーブルに挿入します。
$article = new \App\Entity\Article;
$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('App\Entity\Article', 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('App\Entity\Article', 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('App\Entity\Article')->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);
}
ここで何が欠けていますか?