当前位置: 首页>>代码示例>>PHP>>正文


PHP Translations::getHeaders方法代码示例

本文整理汇总了PHP中Gettext\Translations::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP Translations::getHeaders方法的具体用法?PHP Translations::getHeaders怎么用?PHP Translations::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Gettext\Translations的用法示例。


在下文中一共展示了Translations::getHeaders方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: generateHeaders

 /**
  * Returns the headers as a string.
  * 
  * @param Translations $translations
  *
  * @return string
  */
 private static function generateHeaders(Translations $translations)
 {
     $headers = '';
     foreach ($translations->getHeaders() as $name => $value) {
         $headers .= sprintf("%s: %s\n", $name, $value);
     }
     return $headers;
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:15,代码来源:HeadersGeneratorTrait.php

示例2: toString

 /**
  * {@inheritdoc}
  */
 public static function toString(Translations $translations, array $options = [])
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:2.0');
     $xliff->setAttribute('version', '2.0');
     $xliff->setAttribute('srcLang', $translations->getLanguage());
     $xliff->setAttribute('trgLang', $translations->getLanguage());
     $file = $xliff->appendChild($dom->createElement('file'));
     $file->setAttribute('id', $translations->getDomain() . '.' . $translations->getLanguage());
     //Save headers as notes
     $notes = $dom->createElement('notes');
     foreach ($translations->getHeaders() as $name => $value) {
         $notes->appendChild(self::createTextNode($dom, 'note', $value))->setAttribute('id', $name);
     }
     if ($notes->hasChildNodes()) {
         $file->appendChild($notes);
     }
     foreach ($translations as $translation) {
         $unit = $dom->createElement('unit');
         $unit->setAttribute('id', md5($translation->getContext() . $translation->getOriginal()));
         //Save comments as notes
         $notes = $dom->createElement('notes');
         $notes->appendChild(self::createTextNode($dom, 'note', $translation->getContext()))->setAttribute('category', 'context');
         foreach ($translation->getComments() as $comment) {
             $notes->appendChild(self::createTextNode($dom, 'note', $comment))->setAttribute('category', 'comment');
         }
         foreach ($translation->getExtractedComments() as $comment) {
             $notes->appendChild(self::createTextNode($dom, 'note', $comment))->setAttribute('category', 'extracted-comment');
         }
         foreach ($translation->getFlags() as $flag) {
             $notes->appendChild(self::createTextNode($dom, 'note', $flag))->setAttribute('category', 'flag');
         }
         foreach ($translation->getReferences() as $reference) {
             $notes->appendChild(self::createTextNode($dom, 'note', $reference[0] . ':' . $reference[1]))->setAttribute('category', 'reference');
         }
         $unit->appendChild($notes);
         $segment = $unit->appendChild($dom->createElement('segment'));
         $segment->appendChild(self::createTextNode($dom, 'source', $translation->getOriginal()));
         $segment->appendChild(self::createTextNode($dom, 'target', $translation->getTranslation()));
         foreach ($translation->getPluralTranslations() as $plural) {
             if ($plural !== '') {
                 $segment->appendChild(self::createTextNode($dom, 'target', $plural));
             }
         }
         $file->appendChild($unit);
     }
     return $dom->saveXML();
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:53,代码来源:Xliff.php

示例3: toString

 /**
  * {@parentDoc}.
  */
 public static function toString(Translations $translations)
 {
     $lines = array('msgid ""', 'msgstr ""');
     $headers = $translations->getHeaders();
     $headers['PO-Revision-Date'] = date('c');
     foreach ($headers as $name => $value) {
         $lines[] = '"' . $name . ': ' . $value . '\\n"';
     }
     $lines[] = '';
     //Translations
     foreach ($translations as $translation) {
         if ($translation->hasComments()) {
             foreach ($translation->getComments() as $comment) {
                 $lines[] = '# ' . $comment;
             }
         }
         if ($translation->hasExtractedComments()) {
             foreach ($translation->getExtractedComments() as $comment) {
                 $lines[] = '#. ' . $comment;
             }
         }
         if ($translation->hasReferences()) {
             foreach ($translation->getReferences() as $reference) {
                 $lines[] = '#: ' . $reference[0] . (!is_null($reference[1]) ? ':' . $reference[1] : null);
             }
         }
         if ($translation->hasFlags()) {
             $lines[] = '#, ' . implode(',', $translation->getFlags());
         }
         if ($translation->hasContext()) {
             $lines[] = 'msgctxt ' . self::convertString($translation->getContext());
         }
         self::addLines($lines, 'msgid', $translation->getOriginal());
         if ($translation->hasPlural()) {
             self::addLines($lines, 'msgid_plural', $translation->getPlural());
             self::addLines($lines, 'msgstr[0]', $translation->getTranslation());
             foreach ($translation->getPluralTranslation() as $k => $v) {
                 self::addLines($lines, 'msgstr[' . ($k + 1) . ']', $v);
             }
         } else {
             self::addLines($lines, 'msgstr', $translation->getTranslation());
         }
         $lines[] = '';
     }
     return implode("\n", $lines);
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:49,代码来源:Po.php

示例4: toString

 /**
  * {@parentDoc}.
  */
 public static function toString(Translations $translations, array $options = [])
 {
     $pluralForm = $translations->getPluralForms();
     $pluralSize = is_array($pluralForm) ? $pluralForm[0] - 1 : null;
     $lines = ['msgid ""', 'msgstr ""'];
     foreach ($translations->getHeaders() as $name => $value) {
         $lines[] = sprintf('"%s: %s\\n"', $name, $value);
     }
     $lines[] = '';
     //Translations
     foreach ($translations as $translation) {
         if ($translation->hasComments()) {
             foreach ($translation->getComments() as $comment) {
                 $lines[] = '# ' . $comment;
             }
         }
         if ($translation->hasExtractedComments()) {
             foreach ($translation->getExtractedComments() as $comment) {
                 $lines[] = '#. ' . $comment;
             }
         }
         if ($translation->hasReferences()) {
             foreach ($translation->getReferences() as $reference) {
                 $lines[] = '#: ' . $reference[0] . (!is_null($reference[1]) ? ':' . $reference[1] : null);
             }
         }
         if ($translation->hasFlags()) {
             $lines[] = '#, ' . implode(',', $translation->getFlags());
         }
         if ($translation->hasContext()) {
             $lines[] = 'msgctxt ' . self::convertString($translation->getContext());
         }
         self::addLines($lines, 'msgid', $translation->getOriginal());
         if ($translation->hasPlural()) {
             self::addLines($lines, 'msgid_plural', $translation->getPlural());
             self::addLines($lines, 'msgstr[0]', $translation->getTranslation());
             foreach ($translation->getPluralTranslations($pluralSize) as $k => $v) {
                 self::addLines($lines, 'msgstr[' . ($k + 1) . ']', $v);
             }
         } else {
             self::addLines($lines, 'msgstr', $translation->getTranslation());
         }
         $lines[] = '';
     }
     return implode("\n", $lines);
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:49,代码来源:Po.php

示例5: mergeWith

 /**
  * Merges this translations with other translations.
  *
  * @param Translations $translations The translations instance to merge with
  * @param int|null     $method       One or various Translations::MERGE_* constants to define how to merge the translations
  */
 public function mergeWith(Translations $translations, $method = null)
 {
     if ($method === null) {
         $method = self::$mergeDefault;
     }
     if ($method & self::MERGE_HEADERS) {
         foreach ($translations->getHeaders() as $name => $value) {
             if (!$this->getHeader($name)) {
                 $this->setHeader($name, $value);
             }
         }
     }
     $add = (bool) ($method & self::MERGE_ADD);
     foreach ($translations as $entry) {
         if ($existing = $this->find($entry)) {
             $existing->mergeWith($entry, $method);
         } elseif ($add) {
             $this[] = clone $entry;
         }
     }
     if ($method & self::MERGE_REMOVE) {
         $filtered = array();
         foreach ($this as $entry) {
             if ($translations->find($entry)) {
                 $filtered[] = $entry;
             }
         }
         $this->exchangeArray($filtered);
     }
     if ($method & self::MERGE_LANGUAGE) {
         $language = $translations->getLanguage();
         $pluralForm = $translations->getPluralForms();
         if (!$pluralForm) {
             if (!empty($language)) {
                 $this->setLanguage($language);
             }
         } else {
             if (!empty($language)) {
                 $this->setHeader(self::HEADER_LANGUAGE, $language);
             }
             $this->setPluralForms($pluralForm[0], $pluralForm[1]);
         }
     }
 }
开发者ID:ppiedaderawnet,项目名称:concrete5,代码行数:50,代码来源:Translations.php

示例6: toString

 /**
  * {@parentDoc}
  */
 public static function toString(Translations $translations)
 {
     $array = array();
     $headers = '';
     foreach ($translations->getHeaders() as $headerName => $headerValue) {
         $headers .= "{$headerName}: {$headerValue}\n";
     }
     if ($headers !== '') {
         $array[''] = $headers;
     }
     foreach ($translations as $translation) {
         if (!$translation->hasTranslation() && !static::$includeEmptyTranslations) {
             continue;
         }
         if ($translation->hasContext()) {
             $originalString = $translation->getContext() . "" . $translation->getOriginal();
         } else {
             $originalString = $translation->getOriginal();
         }
         $array[$originalString] = $translation;
     }
     ksort($array);
     $numEntries = count($array);
     $originalsTable = '';
     $translationsTable = '';
     $originalsIndex = array();
     $translationsIndex = array();
     foreach ($array as $originalString => $translation) {
         if (is_string($translation)) {
             // Headers
             $translationString = $translation;
         } else {
             /* @var $translation \Gettext\Translation */
             if ($translation->hasPlural()) {
                 $originalString .= "" . $translation->getPlural();
             }
             $translationString = $translation->getTranslation();
             if ($translation->hasPluralTranslation()) {
                 $translationString .= "" . implode("", $translation->getPluralTranslation());
             }
         }
         $originalsIndex[] = array('relativeOffset' => strlen($originalsTable), 'length' => strlen($originalString));
         $originalsTable .= $originalString . "";
         $translationsIndex[] = array('relativeOffset' => strlen($translationsTable), 'length' => strlen($translationString));
         $translationsTable .= $translationString . "";
     }
     // Offset of table with the original strings index: right after the header (which is 7 words)
     $originalsIndexOffset = 7 * 4;
     // Size of table with the original strings index
     $originalsIndexSize = $numEntries * (4 + 4);
     // Offset of table with the translation strings index: right after the original strings index table
     $translationsIndexOffset = $originalsIndexOffset + $originalsIndexSize;
     // Size of table with the translation strings index
     $translationsIndexSize = $numEntries * (4 + 4);
     // Hashing table starts after the header and after the index table
     $originalsStringsOffset = $translationsIndexOffset + $translationsIndexSize;
     // Translations start after the keys
     $translationsStringsOffset = $originalsStringsOffset + strlen($originalsTable);
     // Let's generate the .mo file binary data
     $mo = '';
     // Magic number
     $mo .= pack('L', 0x950412de);
     // File format revision
     $mo .= pack('L', 0);
     // Number of strings
     $mo .= pack('L', $numEntries);
     // Offset of table with original strings
     $mo .= pack('L', $originalsIndexOffset);
     // Offset of table with translation strings
     $mo .= pack('L', $translationsIndexOffset);
     // Size of hashing table: we don't use it.
     $mo .= pack('L', 0);
     // Offset of hashing table: it would start right after the translations index table
     $mo .= pack('L', $translationsIndexOffset + $translationsIndexSize);
     // Write the lengths & offsets of the original strings
     foreach ($originalsIndex as $info) {
         $mo .= pack('L', $info['length']);
         $mo .= pack('L', $originalsStringsOffset + $info['relativeOffset']);
     }
     // Write the lengths & offsets of the translated strings
     foreach ($translationsIndex as $info) {
         $mo .= pack('L', $info['length']);
         $mo .= pack('L', $translationsStringsOffset + $info['relativeOffset']);
     }
     // Write original strings
     $mo .= $originalsTable;
     // Write translation strings
     $mo .= $translationsTable;
     return $mo;
 }
开发者ID:yakamoz-fang,项目名称:concrete,代码行数:93,代码来源:Mo.php


注:本文中的Gettext\Translations::getHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。