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


PHP Translations::setHeader方法代码示例

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


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

示例1: extractHeaders

 /**
  * Add the headers found to the translations instance.
  * 
  * @param string       $headers
  * @param Translations $translations
  *
  * @return array
  */
 private static function extractHeaders($headers, Translations $translations)
 {
     $headers = explode("\n", $headers);
     $currentHeader = null;
     foreach ($headers as $line) {
         $line = self::convertString($line);
         if ($line === '') {
             continue;
         }
         if (self::isHeaderDefinition($line)) {
             $header = array_map('trim', explode(':', $line, 2));
             $currentHeader = $header[0];
             $translations->setHeader($currentHeader, $header[1]);
         } else {
             $entry = $translations->getHeader($currentHeader);
             $translations->setHeader($currentHeader, $entry . $line);
         }
     }
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:27,代码来源:HeadersExtractorTrait.php

示例2: fromString

 /**
  * {@inheritdoc}
  */
 public static function fromString($string, Translations $translations, array $options = [])
 {
     $xml = new SimpleXMLElement($string, null, false);
     foreach ($xml->file as $file) {
         if (isset($file->notes)) {
             foreach ($file->notes->note as $note) {
                 $translations->setHeader($note['id'], (string) $note);
             }
         }
         foreach ($file->unit as $unit) {
             foreach ($unit->segment as $segment) {
                 $targets = [];
                 foreach ($segment->target as $target) {
                     $targets[] = (string) $target;
                 }
                 $translation = new Translation(null, (string) $segment->source);
                 $translation->setTranslation(array_shift($targets));
                 $translation->setPluralTranslations($targets);
                 if (isset($unit->notes)) {
                     foreach ($unit->notes->note as $note) {
                         switch ($note['category']) {
                             case 'context':
                                 $translation = $translation->getClone((string) $note);
                                 break;
                             case 'extracted-comment':
                                 $translation->addExtractedComment((string) $note);
                                 break;
                             case 'flag':
                                 $translation->addFlag((string) $note);
                                 break;
                             case 'reference':
                                 $ref = explode(':', (string) $note, 2);
                                 $translation->addReference($ref[0], isset($ref[1]) ? $ref[1] : null);
                                 break;
                             default:
                                 $translation->addComment((string) $note);
                                 break;
                         }
                     }
                 }
                 $translations[] = $translation;
             }
         }
     }
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:48,代码来源:Xliff.php

示例3: extract

 /**
  * Handle an array of translations and append to the Translations instance.
  *
  * @param array        $content
  * @param Translations $translations
  */
 public static function extract(array $content, Translations $translations)
 {
     $messages = current($content);
     $headers = isset($messages['']) ? $messages[''] : null;
     unset($messages['']);
     if (!empty($headers['domain'])) {
         $translations->setDomain($headers['domain']);
     }
     if (!empty($headers['lang'])) {
         $translations->setLanguage($headers['lang']);
     }
     if (!empty($headers['plural-forms'])) {
         $translations->setHeader(Translations::HEADER_PLURAL, $headers['plural-forms']);
     }
     $context_glue = '\\u0004';
     foreach ($messages as $key => $translation) {
         $key = explode($context_glue, $key);
         $context = isset($key[1]) ? array_shift($key) : '';
         $translations->insert($context, array_shift($key))->setTranslation(array_shift($translation))->setPluralTranslations($translation);
     }
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:27,代码来源:Jed.php

示例4: fromArray

 /**
  * Extract the entries from a multidimensional array.
  * 
  * @param array        $messages
  * @param Translations $translations
  */
 private static function fromArray(array $messages, Translations $translations)
 {
     if (!empty($messages['domain'])) {
         $translations->setDomain($messages['domain']);
     }
     if (!empty($messages['plural-forms'])) {
         $translations->setHeader(Translations::HEADER_PLURAL, $messages['plural-forms']);
     }
     foreach ($messages['messages'] as $context => $contextTranslations) {
         foreach ($contextTranslations as $original => $value) {
             if ($context === '' && $original === '') {
                 self::extractHeaders(is_array($value) ? array_shift($value) : $value, $translations);
                 continue;
             }
             $translation = $translations->insert($context, $original);
             if (is_array($value)) {
                 $translation->setTranslation(array_shift($value));
                 $translation->setPluralTranslations($value);
             } else {
                 $translation->setTranslation($value);
             }
         }
     }
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:30,代码来源:MultidimensionalArrayTrait.php

示例5: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $container = $this->getContainer();
     $filesystem = new Filesystem();
     $locator = $container->get("agit.common.filecollector");
     $bundles = $container->getParameter("kernel.bundles");
     $catalogPath = $container->getParameter("kernel.root_dir") . "/{$this->catalogSubdir}";
     $this->getContainer()->get("event_dispatcher")->dispatch("agit.intl.global.translations", new TranslationsEvent($this));
     foreach ($container->getParameter("agit.intl.locales") as $locale) {
         $catalog = new Translations();
         $messagesPath = "{$catalogPath}/{$locale}/LC_MESSAGES";
         $catalogFile = "{$messagesPath}/agit.po";
         $oldCatalog = $filesystem->exists($catalogFile) ? Translations::fromPoFile($catalogFile) : new Translations();
         foreach ($oldCatalog as $translation) {
             $translation->deleteReferences();
         }
         $catalog->mergeWith($oldCatalog, 0);
         foreach ($bundles as $alias => $namespace) {
             $bundlePath = $locator->resolve($alias);
             $bundleCatalogFile = "{$bundlePath}/{$this->catalogSubdir}/bundle.{$locale}.po";
             $bundleCatalog = $filesystem->exists($bundleCatalogFile) ? Translations::fromPoFile($bundleCatalogFile) : new Translations();
             $catalog->mergeWith($bundleCatalog, Merge::ADD);
         }
         if (isset($this->extraTranslations[$locale])) {
             foreach ($this->extraTranslations[$locale] as $translation) {
                 $catalog[] = $translation;
             }
         }
         // NOTE: we delete all headers and only set language in order to avoid garbage commits
         $catalog->deleteHeaders();
         $catalog->setLanguage($locale);
         $catalog->setHeader("Content-Type", "text/plain; charset=UTF-8");
         $filesystem->dumpFile($catalogFile, $catalog->toPoString());
         $filesystem->dumpFile("{$messagesPath}/agit.mo", $catalog->toMoString());
     }
 }
开发者ID:agitation,项目名称:intl-bundle,代码行数:36,代码来源:GlobalCatalogCommand.php

示例6: load

 public static function load()
 {
     $locale = self::$locale;
     # IMPORTANT: locale must be installed in server!
     # sudo locale-gen es_ES.UTF-8
     # sudo update-locale
     // $_ENV["LANG"] = $locale;
     // $_ENV["LANGUAGE"] = $locale;
     // $_ENV["LC_MESSAGES"] = $locale;
     // $_ENV["LC_PAPER"] = $locale;
     // $_ENV["LC_TIME"] = $locale;
     // $_ENV["LC_MONETARY"] = $locale;
     // setlocale(LC_MESSAGES, $locale);
     // setlocale(LC_COLLATE, $locale);
     // setlocale(LC_TIME, $locale);
     // setlocale(LC_MONETARY, $locale);
     // bindtextdomain(self::$config['domain'], self::$config['storage']);
     // bind_textdomain_codeset(self::$config['domain'], 'UTF-8');
     // textdomain(self::$config['domain']);
     # Also, we will work with gettext/gettext library
     # because PHP gones crazy when mo files are updated
     $path = base_path() . "/" . dirname(self::getFile(self::$locale));
     $file = $path . '/' . self::$config['domain'];
     if (is_file($file . '.mo')) {
         $translations = Translations::fromMoFile($file . '.mo');
     }
     if (is_file($file . '.po')) {
         $translationsPo = Translations::fromPoFile($file . '.po');
     }
     if ($translations) {
         $translations->mergeWith($translationsPo);
     } else {
         $translations = $translationsPo;
     }
     if (!$translations) {
         $translations = new Translations();
     }
     $translations->setLanguage($locale);
     $translations->setHeader('LANGUAGE', $locale);
     self::$currentTranslation = $translations;
     // $trans = new Translator();
     // $trans->loadTranslations($translations);
     // Translator::initGettextFunctions($trans);
 }
开发者ID:Krato,项目名称:LaravelPoParser,代码行数:44,代码来源:ClassPoParser.php

示例7: fromString

 /**
  * {@inheritDoc}
  */
 public static function fromString($string, Translations $translations = null, $file = '')
 {
     if ($translations === null) {
         $translations = new Translations();
     }
     $stream = new StringReader($string);
     $magic = self::readInt($stream, 'V');
     if ($magic === self::MAGIC1 || $magic === self::MAGIC3) {
         //to make sure it works for 64-bit platforms
         $byteOrder = 'V';
         //low endian
     } elseif ($magic === (self::MAGIC2 & 0xffffffff)) {
         $byteOrder = 'N';
         //big endian
     } else {
         throw new \Exception('Not MO file');
     }
     self::readInt($stream, $byteOrder);
     $total = self::readInt($stream, $byteOrder);
     //total string count
     $originals = self::readInt($stream, $byteOrder);
     //offset of original table
     $tran = self::readInt($stream, $byteOrder);
     //offset of translation table
     $stream->seekto($originals);
     $table_originals = self::readIntArray($stream, $byteOrder, $total * 2);
     $stream->seekto($tran);
     $table_translations = self::readIntArray($stream, $byteOrder, $total * 2);
     for ($i = 0; $i < $total; $i++) {
         $stream->seekto($table_originals[$i * 2 + 2]);
         $original = $stream->read($table_originals[$i * 2 + 1]);
         $stream->seekto($table_translations[$i * 2 + 2]);
         $translated = $stream->read($table_translations[$i * 2 + 1]);
         if ($original === '') {
             // Headers
             foreach (explode("\n", $translated) as $headerLine) {
                 if ($headerLine !== '') {
                     $headerChunks = preg_split('/:\\s*/', $headerLine, 2);
                     $translations->setHeader($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] : '');
                 }
             }
         } else {
             $chunks = explode("", $original, 2);
             if (isset($chunks[1])) {
                 $context = $chunks[0];
                 $original = $chunks[1];
             } else {
                 $context = '';
             }
             $chunks = explode("", $original, 2);
             if (isset($chunks[1])) {
                 $original = $chunks[0];
                 $plural = $chunks[1];
             } else {
                 $plural = '';
             }
             $translation = $translations->insert($context, $original, $plural);
             if ($translated !== '') {
                 if ($plural === '') {
                     $translation->setTranslation($translated);
                 } else {
                     foreach (explode("", $translated) as $pluralIndex => $pluralValue) {
                         if ($pluralIndex === 0) {
                             $translation->setTranslation($pluralValue);
                         } else {
                             $translation->setPluralTranslation($pluralValue, $pluralIndex - 1);
                         }
                     }
                 }
             }
         }
     }
     return $translations;
 }
开发者ID:jankal,项目名称:mvc,代码行数:77,代码来源:Mo.php

示例8: fromString

 /**
  * {@inheritdoc}
  */
 public static function fromString($string, Translations $translations, array $options = [])
 {
     $stream = new StringReader($string);
     $magic = self::readInt($stream, 'V');
     if ($magic === self::MAGIC1 || $magic === self::MAGIC3) {
         //to make sure it works for 64-bit platforms
         $byteOrder = 'V';
         //low endian
     } elseif ($magic === (self::MAGIC2 & 0xffffffff)) {
         $byteOrder = 'N';
         //big endian
     } else {
         throw new Exception('Not MO file');
     }
     self::readInt($stream, $byteOrder);
     $total = self::readInt($stream, $byteOrder);
     //total string count
     $originals = self::readInt($stream, $byteOrder);
     //offset of original table
     $tran = self::readInt($stream, $byteOrder);
     //offset of translation table
     $stream->seekto($originals);
     $table_originals = self::readIntArray($stream, $byteOrder, $total * 2);
     $stream->seekto($tran);
     $table_translations = self::readIntArray($stream, $byteOrder, $total * 2);
     for ($i = 0; $i < $total; ++$i) {
         $next = $i * 2;
         $stream->seekto($table_originals[$next + 2]);
         $original = $stream->read($table_originals[$next + 1]);
         $stream->seekto($table_translations[$next + 2]);
         $translated = $stream->read($table_translations[$next + 1]);
         if ($original === '') {
             // Headers
             foreach (explode("\n", $translated) as $headerLine) {
                 if ($headerLine === '') {
                     continue;
                 }
                 $headerChunks = preg_split('/:\\s*/', $headerLine, 2);
                 $translations->setHeader($headerChunks[0], isset($headerChunks[1]) ? $headerChunks[1] : '');
             }
             continue;
         }
         $chunks = explode("", $original, 2);
         if (isset($chunks[1])) {
             $context = $chunks[0];
             $original = $chunks[1];
         } else {
             $context = '';
         }
         $chunks = explode("", $original, 2);
         if (isset($chunks[1])) {
             $original = $chunks[0];
             $plural = $chunks[1];
         } else {
             $plural = '';
         }
         $translation = $translations->insert($context, $original, $plural);
         if ($translated === '') {
             continue;
         }
         if ($plural === '') {
             $translation->setTranslation($translated);
             continue;
         }
         $v = explode("", $translated);
         $translation->setTranslation(array_shift($v));
         $translation->setPluralTranslations($v);
     }
 }
开发者ID:parkerj,项目名称:eduTrac-SIS,代码行数:72,代码来源:Mo.php

示例9: execute


//.........这里部分代码省略.........
             // We don't want any locale
         } elseif (empty($localeOption)) {
             // List the currently package locales
             foreach ($fh->getDirectoryContents($packageLanguagesDirectory) as $item) {
                 if (is_file("{$packageLanguagesDirectory}/{$item}/LC_MESSAGES/messages.mo") || is_file("{$baseDir}/{$item}/LC_MESSAGES/messages.po")) {
                     $locales[] = $item;
                 }
             }
             if (empty($locales)) {
                 // Let's use the core locales
                 $locales = Localization::getAvailableInterfaceLanguages();
             }
         } else {
             // Normalize the locales (eg from it-it to it_IT)
             foreach ($localeOption as $lo) {
                 $chunks = array();
                 foreach (explode('_', str_replace('-', '_', $lo)) as $index => $chunk) {
                     if ($index === 0) {
                         // Language (eg zh)
                         $chunks[] = strtolower($chunk);
                     } elseif (strlen($chunk) === 4) {
                         // Script (eg Hans)
                         $chunks[] = ucfirst(strtolower($chunk));
                     } else {
                         // Territory (eg CN)
                         $chunks[] = strtoupper($chunk);
                     }
                 }
                 $locales[] = implode('_', $chunks);
             }
         }
         // Initialize the master translations file (.pot)
         $pot = new Translations();
         $pot->setHeader('Project-Id-Version', "{$packageHandle} {$packageVersion}");
         $pot->setLanguage('en_US');
         $pot->setHeader('Report-Msgid-Bugs-To', $input->getOption('contact'));
         $pot->setHeader('Last-Translator', $input->getOption('translator'));
         // Parse the package directory
         $output->writeln('Parsing package contents');
         foreach (\C5TL\Parser::getAllParsers() as $parser) {
             if ($parser->canParseDirectory()) {
                 $output->write('- running parser "' . $parser->getParserName() . '"... ');
                 $parser->parseDirectory($packageDirectory, "packages/{$packageHandle}", $pot, false, $input->getOption('exclude-3rdparty'));
                 $output->writeln('done.');
             }
         }
         // Save the pot file
         $output->write('Saving .pot file... ');
         if (!is_dir($packageLanguagesDirectory)) {
             @mkdir($packageLanguagesDirectory, 0775, true);
             if (!is_dir($packageLanguagesDirectory)) {
                 throw new Exception("Unable to create the directory {$packageLanguagesDirectory}");
             }
         }
         $potFilename = "{$packageLanguagesDirectory}/messages.pot";
         if ($pot->toPoFile($potFilename) === false) {
             throw new Exception("Unable to save the .pot file to {$potFilename}");
         }
         $output->writeln('done.');
         // Creating/updating the locale files
         foreach ($locales as $locale) {
             $output->writeln("Working on locale {$locale}");
             $poDirectory = "{$packageLanguagesDirectory}/{$locale}/LC_MESSAGES";
             $po = clone $pot;
             $po->setLanguage($locale);
             $poFile = "{$poDirectory}/messages.po";
开发者ID:digideskio,项目名称:concrete5,代码行数:67,代码来源:TranslatePackageCommand.php


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