如何在生成器中翻译标签.yaml文件(Symfony)



我想问你,如何在生成器中翻译字段的标签。yaml文件。一般来说,如何翻译yaml文件的内容?

,

config:
  actions: ~
  fields:
    name:
      label: Name

如何使'name'可翻译?

提前感谢&波兰最美好的祝愿:)

Piotrek

你真的不需要做任何事情。您的标签是否来自发电机。最后,标签字符串会经过处理翻译的sfWidgetFormSchemaFormatter::translate方法。

您需要听表单。post_configure事件。我通常在我的项目配置类中这样做:

class ProjectConfiguration extends sfProjectConfiguration
{
  public function setup()
  {
        $this->dispatcher->connect('form.post_configure', array($this, 'listenToFormPostConfigure'));
  }

  /**
   * Listens to the command.post_command event.
   *
   * @param sfEvent An sfEvent instance
   * @static
   */
  static function listenToFormPostConfigure(sfEvent $event)
  {
    sfProjectConfiguration::getActive()->loadHelpers('I18N');
    $form = $event->getSubject();
    $widgetSchema = $form->getWidgetSchema();
    foreach ($form->getValidatorSchema()->getFields() as $fieldName => $validator)
    {
      if (isset($widgetSchema[$fieldName]))
      {
        $label = $widgetSchema[$fieldName]->getLabel() ? $widgetSchema[$fieldName]->getLabel()
            : sfInflector::humanize($fieldName);
        $label = __($label);
        $asterisk = $validator->getOption('required') ? ' *' : null;
        $widgetSchema[$fieldName]->setLabel($label . $asterisk . ' :');
      }
    }
  }
}

这将在所需的标签上附加一个星号,并翻译标签。希望对你也有用。

最新更新