Symfony FOSuser翻译新表格

时间:2016-05-16 11:29:47

标签: doctrine fosuserbundle symfony

我在FOSUSER的注册表单中翻译新输入时遇到问题。基本上我扩展了FOS用户实体:

<button type="button" 
   class="btn btn-danger"
   id="{{ currency.id }}"
   data-curname="{{ currency.name }}"
   data-toggle="modal"
   data-target="#deleteConfirm"
   onclick="deleteCurConf(this)">
   <span class="glyphicon glyphicon-remove"></span>
   &nbsp;Delete
</button>

Ovveride注册表格

function deleteCurConf(id) {
 var curName = $(id).data('curname'); // use $(id)
 console.log(curName);
}

在我的注册视图中,我有:

namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Security\Core\User\AdvancedUserInterface;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
use Symfony\Component\Validator\Constraints as Assert;
use FOS\UserBundle\Model\User as BaseUser;

    /**
     * @ORM\Entity
     * @ORM\Table(name="fos_user")
     */
    class User extends BaseUser {

        /**
         * @ORM\Id
         * @ORM\Column(type="integer")
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        protected $id;

        /**
         * @ORM\Column(type="string", length=255)
         *
         * @Assert\NotBlank(message="Fill it", groups={"Registration", "Profile"})
         * @Assert\Length(
         *     min=3,
         *     max=255,
         *     minMessage="To short.",
         *     maxMessage="To long.",
         *     groups={"Registration", "Profile"}
         * )
         */
        protected $nameU;

        public function getNameU() {
            return $this->nameU;
        }

     public function setNameU($nameU) {
            $this->nameU= $nameU;
        }

在app / Resource / FosUser中添加到FOS USER BUNDLE区域设置的翻译特定声明../ translation /.....

<?php

namespace AppBundle\Form;

use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
    use Gregwar\CaptchaBundle\Type\CaptchaType;

use FOS\UserBundle\Util\LegacyFormHelper;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;

class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('nameU')

    }

    public function getParent()
    {
        return 'FOS\UserBundle\Form\Type\RegistrationFormType';

        // Or for Symfony < 2.8
        // return 'fos_user_registration';
    }

    public function getBlockPrefix()
    {
        return 'app_user_registration';
    }

    // For Symfony 2.x
    public function getName()
    {
        return $this->getBlockPrefix();
    }
}

翻译不起作用,它看起来像变量名nameU :(

1 个答案:

答案 0 :(得分:0)

确定。我找到了。我忘记在注册类型中发送它:

    class RegistrationType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->
                ->add('numeU',null, array('label' => 'form.nameU', 'translation_domain' => 'FOSUserBundle'))