2011-08-09 8 views
1

generator.yaml 파일에서 라벨 라벨을 번역하는 방법에 대해 문의하고 싶습니다. 일반적으로 yaml의 파일 내용을 번역하는 방법은 무엇입니까?generator.yaml 파일 (Symfony)에서 라벨을 번역하는 방법

예 :

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

방법 '이름'번역을 할? & 최고의 소원 폴란드에서 사전에

들으 :)

Piotrek

답변

0

당신은 form.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 . ' :'); 
     } 

    } 
    } 

} 

이 필요한 라벨에 별표를 추가하고 또한 라벨을 변환합니다. 희망은 당신에게도 유용 할거야.

2

아무 것도 할 필요가 없습니다. label이 generator.yml에서 왔는지, ModelForm 클래스에서 왔는지에 관계없이 레이블 문자열은 번역을 처리하는 sfWidgetFormSchemaFormatter :: translate 메서드를 통해 처리됩니다.

관련 문제