コード例 #1
0
ファイル: PoStreamReader.php プロジェクト: biaogebusy/mi
 /**
  * Read the header from the PO stream.
  *
  * The header is a special case PoItem, using the empty string as source and
  * key-value pairs as translation. We just reuse the item reader logic to
  * read the header.
  */
 private function readHeader()
 {
     $item = $this->readItem();
     // Handle the case properly when the .po file is empty (0 bytes).
     if (!$item) {
         return;
     }
     $header = new PoHeader();
     $header->setFromString(trim($item->getTranslation()));
     $this->_header = $header;
 }
コード例 #2
0
 /**
  * Implements PoMetadataInterface::setHeader().
  *
  * Sets the header and configure Drupal accordingly.
  *
  * Before being able to process the given header we need to know in what
  * context this database write is done. For this the options must be set.
  *
  * A langcode is required to set the current header's PluralForm.
  *
  * @param PoHeader $header
  *   Header metadata.
  *
  * @throws Exception
  */
 function setHeader(PoHeader $header)
 {
     $this->_header = $header;
     $languages = language_list();
     // Check for options.
     $options = $this->getOptions();
     if (empty($options)) {
         throw new \Exception('Options should be set before assigning a PoHeader.');
     }
     $overwrite_options = $options['overwrite_options'];
     // Check for langcode.
     $langcode = $this->_langcode;
     if (empty($langcode)) {
         throw new \Exception('Langcode should be set before assigning a PoHeader.');
     }
     // Check is language is already created.
     if (!isset($languages[$langcode])) {
         throw new \Exception('Language should be known before using it.');
     }
     if (array_sum($overwrite_options) || empty($languages[$langcode]->plurals)) {
         // Get and store the plural formula if available.
         $plural = $header->getPluralForms();
         if (isset($plural) && ($p = $header->parsePluralForms($plural))) {
             list($nplurals, $formula) = $p;
             db_update('languages')->fields(array('plurals' => $nplurals, 'formula' => $formula))->condition('language', $langcode)->execute();
         }
     }
 }