symfony i18n objects (Doctrine) get specific culture

寵の児 提交于 2019-12-08 09:25:37

问题


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 }

回答1:


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

alternatively:

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



回答2:


This almost the same problem as on your other question, use:

$object->Translation['fr']->name;
$object->Translation['en']->name;
$object->Translation['it']->name;
// etc ...

I quote the comment I post on the other question:

->getName() works if you are on the object direclty, like $object->getName(). But if you hit the Translation relation, I never used a getter to retrieve value.

By the way, I didn't remember that we can use this $object->getName('fr'); with sf1.0.



来源:https://stackoverflow.com/questions/14987859/symfony-i18n-objects-doctrine-get-specific-culture

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!