symfony i18n对象(Doctrine)获得具体文化 [英] symfony i18n objects (Doctrine) get specific culture

查看:124
本文介绍了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();

这篇关于symfony i18n对象(Doctrine)获得具体文化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆