symfony i18n对象(Doctrine)获得具体文化

symfony i18n对象(Doctrine)获得具体文化

问题描述:

我有一个问题,我无法从我的i18n教义对象中检索特定的翻译。如果我调用 $ object-> getName(); 我按预期得到当前文化中的名称。但是,如果我希望在不改变用户文化的情况下检索特定的翻译... $ object-> getName('fr'); 我仍然得到当前的文化在这个例子中是法语。这个 $ object-> getTranslation() - > fr-> name; 确实有效。我究竟做错了什么?不是 $ object-> getName($ culture); 正确的方法这样做?

I am having an issue where I cannot retrieve a specific translation from my i18n doctrine objects. If I call $object->getName(); I get the name in the current culture as expected. However, if I wish to retrieve a specific translation without switching the user culture... $object->getName('fr'); I still get the current culture instead of French in this example. This $object->getTranslation()->fr->name; does work though. What am I doing wrong? Isn't $object->getName($culture); the correct way to do this?

这里是我的模式的相关部分,如果这有帮助:

Here is the relevant part of my schema if that's helpful:

Object:
  actAs:
    Timestampable: ~
    I18n:
      fields:           [name, description]
  columns:
    name:               { type: string(255), notnull: true }
    description:        { type: string(1000) }
    user_id:            { type: integer }
  relations:
    User:               { class: sfGuardUser, local: user_id, foreign: id, type: one, foreignType: many, foreignAlias: Objects }


$this->Translation['fr']->getName()

另: / p>

alternatively:

$translations = $this->getTranslations();
$translations['fr']->getName();