Changeset 1409

Show
Ignore:
Timestamp:
12/02/06 16:20:46 (2 years ago)
Author:
david
Message:

added 'store_calls' configuration parameter to AgaviGettextTranslator? that allows to set a base directory to which _() (and thus ()) calls will be 'logged' so they can be parsed by xgettext. will just append, so items will be duplicate over time. xgettext has an option to filter these out. will automatically create one file per domain since most xgettext implementations cannot detect domains from dgettext calls. the sample app writes to the cache dir in debug mode, so each generated file will be gone after a refresh. I just couldn't be bothered to chmod a different directory ;)

Location:
branches/0.11
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/samples/app/config/translation.xml

    r1404 r1409  
    7171        <message_translator class="AgaviGettextTranslator"> 
    7272          <parameters> 
    73             <parameter name="store_calls">%core.cache_dir%/data</parameter> 
    7473            <parameter name="text_domains"> 
    7574              <parameters> 
     
    9594     
    9695  </configuration> 
     96   
     97  <configuration environment="development"> 
     98    <translators default_domain="default"> 
     99      <translator domain="default"> 
     100        <message_translator class="AgaviGettextTranslator"> 
     101          <parameter name="store_calls">%core.cache_dir%/data</parameter> 
     102          <!-- other params are inherited from generic config --> 
     103        </message_translator> 
     104      </translator> 
     105    </translators> 
     106  </configuration> 
     107   
    97108</configurations> 
  • branches/0.11/src/translation/AgaviGettextTranslator.class.php

    r1311 r1409  
    4747   */ 
    4848  protected $pluralFormFunc = null; 
     49   
     50  /** 
     51   * @var        bool Whether or not to write a file with all used translations 
     52   *                  that can be parsed using xgettext. 
     53   */ 
     54  protected $storeTranslationCalls = false; 
     55   
     56  /** 
     57   * @var        string The folder to write translation call files to. 
     58   */ 
     59  protected $translationCallStoreDir = null; 
    4960 
    5061  /** 
     
    6980    if(isset($parameters['text_domain_pattern'])) { 
    7081      $this->domainPathPattern = $parameters['text_domain_pattern']; 
     82    } 
     83     
     84    if(isset($parameters['store_calls'])) { 
     85      $this->storeTranslationCalls = true; 
     86      $this->translationCallStoreDir = $parameters['store_calls']; 
     87      AgaviToolkit::mkdir($parameters['store_calls'], 0777, true); 
    7188    } 
    7289  } 
     
    111128    } 
    112129 
    113      
     130    // in "devel" mode, write a gettext() or ngettext() call to a file for xgettext parsing 
     131    if($this->storeTranslationCalls) { 
     132      file_put_contents( 
     133        $this->translationCallStoreDir . DIRECTORY_SEPARATOR . $domain . '.php',  
     134        "" . (is_array($message) ?  
     135          ('ngettext(' . var_export($message[0], true) . ', ' . var_export($message[1], true) . ', ' . var_export($message[2], true) . ')') : 
     136          ('gettext(' . var_export($message, true) . ')') 
     137        ) . ";\n", 
     138      FILE_APPEND); 
     139    } 
    114140 
    115141    if($locale) {