0

JMS Translation Bundle を使用して抽出しています。以下は私の設定です。

jms_i18n_routing:

    default_locale: %locale%
    locales: [en]
    strategy: prefix_except_default

jms_translation:
    configs:
        app:
            dirs: [%kernel.root_dir%, %kernel.root_dir%/../src]
            output_dir: %kernel.root_dir%/Resources/translations
            ignored_domains: [routes]
            excluded_names: [*TestCase.php, *Test.php]
            excluded_dirs: [cache, data, logs]
#            extractors: [jms_translation.file_visitor]

ただし、実行時にバンドルからラベルを取得して形成できないようです:

php app/console translation:extract de --dir=./src/ --output-dir=./app/Resources/translations

そして、私のフォームは次のようになります

public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('name', 'text', array(
            'label' => 'nilead.form.discount.name'
        ))

            ->add('value', 'number', array(
                'label' => 'nilead.form.discount.number',
                'constraints' => array(
                    new GreaterThan(array('value' => 0))
                )
            ))

            ->add('percentage', 'percent', array(
                'label' => 'nilead.form.discount.percentage',
            ))

            ->add('code', 'text', array(
                'label' => 'nilead.form.discount.code',
            ))

            ->add('throughDate', 'date', array(
                'label' => 'nilead.form.discount.throughDate',
                'widget' => 'single_text',
                'format' => 'yyyy-MM-dd',
            ))

            ->add('fromDate', 'date', array(
                'label' => 'nilead.form.discount.fromDate',
                'widget' => 'single_text',
                'format' => 'yyyy-MM-dd',
            ))

            ->add('usageRemaining', 'text', array(
                'label' => 'nilead.form.discount.usageRemaining',
            ))

            //->add('fromDate', 'text')

//            ->add('throughDate', 'text')

            ->add('calculator', 'nilead_discount_calculator_choice', array(
                'empty_value' => '----',
                'label' => 'nilead.form.discount.calculator',
            ))
            ->addEventSubscriber(new BuildDiscountFormListener($this->calculator, $builder->getFormFactory()));

        $prototypes = array();
        $prototypes['calculators'] = array();

        foreach ($this->calculator->getCalculators() as $calculator) {
            $calculatorObj = $this->calculator->get($calculator);
            $prototype = $builder->create('settings', $calculatorObj->getConfigurationFormType())->getForm();

            $prototypes['calculators'][$calculator] = $prototype;
        }
        $builder->setAttribute('prototypes', $prototypes);
    }
4

2 に答える 2

0

次のように、翻訳サービスを使用する必要があります。

$translator = $this->get('translator');
$translator->trans('nilead.form.discount.number', array(), 'SomeBundle');

この前に - DI を使用してトランスレータをフォームに挿入します。

于 2015-08-13T14:00:06.920 に答える
0

JMSTranslationBundleを使用して、ラベルなどをフォームから翻訳ファイルに抽出できます。

例:

$ bin/console translation:extract --output-dir translations/ -d src/Form en
于 2021-01-18T17:57:38.737 に答える