我使用 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 翻译: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);
}