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


PHP MessageCatalogue::getLocale方法代码示例

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


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

示例1: dump

 /**
  * {@inheritDoc}
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     if (!array_key_exists('path', $options)) {
         throw new \InvalidArgumentException('The file dumper needs a path option.');
     }
     $path = $options['path'];
     $bundleName = isset($options['bundleName']) ? $options['bundleName'] : '';
     $generatedFiles = array();
     // save a file for each domain
     foreach ($messages->getDomains() as $domain) {
         $fileName = !empty($bundleName) ? sprintf('%s.%s.%s.xlsx', $bundleName, $domain, $messages->getLocale()) : sprintf('%s.%s.xlsx', $domain, $messages->getLocale());
         // create the exporter file
         $exporter = new ExcelExporter($path);
         // create the header row
         $row = array('key', $messages->getLocale());
         $exporter->writeRow($row);
         // format the data and write to file
         $data = $this->format($messages, $domain);
         foreach ($data as $row) {
             $exporter->writeRow($row);
         }
         $generatedFiles[] = $exporter->generateFile($fileName);
     }
     return $generatedFiles;
 }
开发者ID:prezent,项目名称:translation-bundle,代码行数:28,代码来源:ExcelFileDumper.php

示例2: loadMessages

 /**
  * Loads translation messages from a directory to the catalogue.
  *
  * @param string $directory the directory to look into
  * @param MessageCatalogue $catalogue the catalogue
  */
 public function loadMessages($directory, MessageCatalogue $catalogue)
 {
     foreach ($this->loaders as $format => $loader) {
         // load any existing translation files
         $finder = new Finder();
         $extension = $catalogue->getLocale() . '.' . $format;
         $files = $finder->files()->name('*.' . $extension)->in($directory);
         foreach ($files as $file) {
             $domain = substr($file->getFileName(), 0, -1 * strlen($extension) - 1);
             $catalogue->addCatalogue($loader->load($file->getPathname(), $catalogue->getLocale(), $domain));
         }
     }
 }
开发者ID:rikaix,项目名称:symfony,代码行数:19,代码来源:TranslationLoader.php

示例3: dump

 /**
  * Dumps the message catalogue.
  *
  * @param MessageCatalogue $messages The message catalogue
  * @param array            $options  Options that are used by the dumper
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     $this->loadAll = false;
     $locale = $messages->getLocale();
     try {
         foreach ($messages->getDomains() as $eachDomain) {
             foreach ($messages->all($eachDomain) as $eachKey => $eachTranslation) {
                 $queryBuilder = $this->entityManager->createQueryBuilder();
                 $queryBuilder->select('t')->from('MjrLibraryEntitiesBundle:System\\Translation', 't')->where($queryBuilder->expr()->andX($queryBuilder->expr()->eq('t.Identity', '?1'), $queryBuilder->expr()->eq('t.Locale', '?2')));
                 $query = $this->entityManager->createQuery($queryBuilder->getDQL());
                 $query->setParameters(array(1 => $eachKey, 2 => $locale));
                 $result = $query->getArrayResult();
                 if (count($result) < 1) {
                     $entry = new Translation();
                     $entry->setLocale($locale);
                     $entry->setIdentity($eachKey);
                     $entry->setTranslation($eachKey);
                     $this->entityManager->persist($entry);
                     $this->entityManager->flush();
                 }
                 unset($query, $queryBuilder, $entry, $eachKey, $eachTranslation);
             }
         }
     } catch (\Exception $ex) {
         var_dump($ex);
         die;
     }
 }
开发者ID:ChrisWesterfield,项目名称:MJR.ONE-CP,代码行数:34,代码来源:DbDumper.php

示例4: format

 /**
  * {@inheritDoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', $messages->getLocale());
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     $id = 1;
     foreach ($messages->all($domain) as $source => $target) {
         $trans = $dom->createElement('trans-unit');
         $trans->setAttribute('id', $id);
         $s = $trans->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         $t = $trans->appendChild($dom->createElement('target'));
         $t->appendChild($dom->createTextNode($target));
         $xliffBody->appendChild($trans);
         $id++;
     }
     return $dom->saveXML();
 }
开发者ID:laubosslink,项目名称:lab,代码行数:28,代码来源:XliffFileDumper.php

示例5: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', $messages->getLocale());
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $t = $translation->appendChild($dom->createElement('target'));
         $t->appendChild($text);
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:kchhainarong,项目名称:chantuchP,代码行数:29,代码来源:XliffFileDumper.php

示例6: dump

 /**
  * {@inheritDoc}
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     if (!array_key_exists('path', $options)) {
         throw new \InvalidArgumentException('The file dumper needs a path option.');
     }
     // save a file for each domain
     $generatedFiles = array();
     $bundleName = isset($options['bundleName']) ? $options['bundleName'] : '';
     foreach ($messages->getDomains() as $domain) {
         $fileName = !empty($bundleName) ? sprintf('%s.%s.%s.%s', $bundleName, $domain, $messages->getLocale(), $this->getExtension()) : sprintf('%s.%s.%s', $domain, $messages->getLocale(), $this->getExtension());
         $fullpath = sprintf('%s/%s', $options['path'], $fileName);
         // save file
         file_put_contents($fullpath, $this->format($messages, $domain));
         $generatedFiles[] = $fullpath;
     }
     return $generatedFiles;
 }
开发者ID:prezent,项目名称:translation-bundle,代码行数:20,代码来源:CsvFileDumper.php

示例7: loadMessages

 /**
  * Loads translation messages from a directory to the catalogue.
  * 
  * @param string $directory the directory to look into
  * @param MessageCatalogue $catalogue the catalogue
  */
 public function loadMessages($directory, MessageCatalogue $catalogue)
 {
     foreach($this->loaders as $format => $loader) {
         // load any existing translation files
         $finder = new Finder();
         $files = $finder->files()->name('*.'.$catalogue->getLocale().$format)->in($directory);
         foreach ($files as $file) {
             $domain = substr($file->getFileName(), 0, strrpos($file->getFileName(), $input->getArgument('locale').$format) - 1);
             $catalogue->addCatalogue($loader->load($file->getPathname(), $input->getArgument('locale'), $domain));
         }
     }
 }
开发者ID:ratasxy,项目名称:symfony,代码行数:18,代码来源:TranslationLoader.php

示例8: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', str_replace('_', '-', $this->defaultLocale));
     $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $targetElement = $dom->createElement('target');
         $metadata = $messages->getMetadata($source, $domain);
         if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) {
             foreach ($metadata['target-attributes'] as $name => $value) {
                 $targetElement->setAttribute($name, $value);
             }
         }
         $t = $translation->appendChild($targetElement);
         $t->appendChild($text);
         if ($this->hasMetadataArrayInfo('notes', $metadata)) {
             foreach ($metadata['notes'] as $note) {
                 if (!isset($note['content'])) {
                     continue;
                 }
                 $n = $translation->appendChild($dom->createElement('note'));
                 $n->appendChild($dom->createTextNode($note['content']));
                 if (isset($note['priority'])) {
                     $n->setAttribute('priority', $note['priority']);
                 }
                 if (isset($note['from'])) {
                     $n->setAttribute('from', $note['from']);
                 }
             }
         }
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:Nakard,项目名称:symfony,代码行数:52,代码来源:XliffFileDumper.php

示例9: dump

 /**
  * {@inheritDoc}
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     if (!array_key_exists('path', $options)) {
         throw new \InvalidArgumentException('The file dumper need a path options.');
     }
     
     // save a file for each domain
     foreach ($messages->getDomains() as $domain) {
         $file = $domain.'.'.$messages->getLocale().'.'.$this->getExtension();
         // backup
         if (file_exists($options['path'].$file)) {
             copy($options['path'].$file, $options['path'].'/'.$file.'~');
         }
         // save file
         file_put_contents($options['path'].'/'.$file, $this->format($messages, $domain));
     }
 }
开发者ID:ratasxy,项目名称:symfony,代码行数:20,代码来源:FileDumper.php

示例10: formatCatalogue

 /**
  * {@inheritdoc}
  */
 public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
 {
     $output = 'msgid ""' . "\n";
     $output .= 'msgstr ""' . "\n";
     $output .= '"Content-Type: text/plain; charset=UTF-8\\n"' . "\n";
     $output .= '"Content-Transfer-Encoding: 8bit\\n"' . "\n";
     $output .= '"Language: ' . $messages->getLocale() . '\\n"' . "\n";
     $output .= "\n";
     $newLine = false;
     foreach ($messages->all($domain) as $source => $target) {
         if ($newLine) {
             $output .= "\n";
         } else {
             $newLine = true;
         }
         $output .= sprintf('msgid "%s"' . "\n", $this->escape($source));
         $output .= sprintf('msgstr "%s"', $this->escape($target));
     }
     return $output;
 }
开发者ID:tsurune,项目名称:Pruebas,代码行数:23,代码来源:PoFileDumper.php

示例11: format

 /**
  * {@inheritdoc}
  */
 protected function format(MessageCatalogue $messages, $domain)
 {
     $dom = new \DOMDocument('1.0', 'utf-8');
     $dom->formatOutput = true;
     $xliff = $dom->appendChild($dom->createElement('xliff'));
     $xliff->setAttribute('version', '1.2');
     $xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('source-language', str_replace('_', '-', $this->defaultLocale));
     $xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
     $xliffFile->setAttribute('datatype', 'plaintext');
     $xliffFile->setAttribute('original', 'file.ext');
     $xliffBody = $xliffFile->appendChild($dom->createElement('body'));
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('trans-unit');
         $translation->setAttribute('id', md5($source));
         $translation->setAttribute('resname', $source);
         $s = $translation->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         $t = $translation->appendChild($dom->createElement('target'));
         $t->appendChild($dom->createTextNode($target));
         $metadata = $messages->getMetadata($source, $domain);
         if (null !== $metadata && array_key_exists('notes', $metadata) && is_array($metadata['notes'])) {
             foreach ($metadata['notes'] as $note) {
                 if (!isset($note['content'])) {
                     continue;
                 }
                 $n = $translation->appendChild($dom->createElement('note'));
                 $n->appendChild($dom->createTextNode($note['content']));
                 if (isset($note['priority'])) {
                     $n->setAttribute('priority', $note['priority']);
                 }
                 if (isset($note['from'])) {
                     $n->setAttribute('from', $note['from']);
                 }
             }
         }
         $xliffBody->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:alexbogo,项目名称:symfony,代码行数:44,代码来源:XliffFileDumper.php

示例12: dump

 /**
  * {@inheritdoc}
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     $connection = \Propel::getConnection($this->query->getDbName());
     $connection->beginTransaction();
     $now = new \DateTime();
     $locale = $messages->getLocale();
     foreach ($messages->getDomains() as $eachDomain) {
         foreach ($messages->all($eachDomain) as $eachKey => $eachTranslation) {
             $query = clone $this->query;
             $query->filterBy($this->getColumnPhpname('locale'), $locale)->filterBy($this->getColumnPhpname('domain'), $eachDomain)->filterBy($this->getColumnPhpname('key'), $eachKey);
             $translation = $query->findOneOrCreate($connection);
             $translation->setByName($this->getColumnPhpname('translation'), (string) $eachTranslation);
             $translation->setByName($this->getColumnPhpname('updated_at'), $now);
             $translation->save($connection);
         }
     }
     if (!$connection->commit()) {
         $connection->rollBack();
         throw new \RuntimeException(sprintf('An error occurred while committing the transaction. [%s: %s]', $connection->errorCode(), $connection->errorInfo()));
     }
 }
开发者ID:ChazalFlorian,项目名称:enjoyPangolin,代码行数:24,代码来源:ModelTranslation.php

示例13: dump

 /**
  * {@inheritDoc}
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     if (!array_key_exists('path', $options)) {
         throw new \InvalidArgumentException('The file dumper needs a path option.');
     }
     // save a file for each domain
     foreach ($messages->getDomains() as $domain) {
         // backup
         $fullpath = $options['path'] . '/' . $this->getRelativePath($domain, $messages->getLocale());
         if (file_exists($fullpath)) {
             copy($fullpath, $fullpath . '~');
         } else {
             $directory = dirname($fullpath);
             if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
                 throw new \RuntimeException(sprintf('Unable to create directory "%s".', $directory));
             }
         }
         // save file
         file_put_contents($fullpath, $this->format($messages, $domain));
     }
 }
开发者ID:romainneutron,项目名称:symfony,代码行数:24,代码来源:FileDumper.php

示例14: dump

 /**
  * {@inheritdoc}
  */
 public function dump(MessageCatalogue $messages, $options = array())
 {
     if (!array_key_exists('path', $options)) {
         throw new \InvalidArgumentException('The file dumper needs a path option.');
     }
     // save a file for each domain
     foreach ($messages->getDomains() as $domain) {
         // backup
         $fullpath = $options['path'] . '/' . $this->getRelativePath($domain, $messages->getLocale());
         if (file_exists($fullpath)) {
             if ($this->backup) {
                 @trigger_error('Creating a backup while dumping a message catalogue is deprecated since version 3.1 and will be removed in 4.0. Use TranslationWriter::disableBackup() to disable the backup.', E_USER_DEPRECATED);
                 copy($fullpath, $fullpath . '~');
             }
         } else {
             $directory = dirname($fullpath);
             if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
                 throw new \RuntimeException(sprintf('Unable to create directory "%s".', $directory));
             }
         }
         // save file
         file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
     }
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:27,代码来源:FileDumper.php

示例15: dumpXliff2

 private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
 {
     $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', str_replace('_', '-', $defaultLocale));
     $xliff->setAttribute('trgLang', str_replace('_', '-', $messages->getLocale()));
     $xliffFile = $xliff->appendChild($dom->createElement('file'));
     $xliffFile->setAttribute('id', $domain . '.' . $messages->getLocale());
     foreach ($messages->all($domain) as $source => $target) {
         $translation = $dom->createElement('unit');
         $translation->setAttribute('id', md5($source));
         $segment = $translation->appendChild($dom->createElement('segment'));
         $s = $segment->appendChild($dom->createElement('source'));
         $s->appendChild($dom->createTextNode($source));
         // Does the target contain characters requiring a CDATA section?
         $text = 1 === preg_match('/[&<>]/', $target) ? $dom->createCDATASection($target) : $dom->createTextNode($target);
         $targetElement = $dom->createElement('target');
         $metadata = $messages->getMetadata($source, $domain);
         if ($this->hasMetadataArrayInfo('target-attributes', $metadata)) {
             foreach ($metadata['target-attributes'] as $name => $value) {
                 $targetElement->setAttribute($name, $value);
             }
         }
         $t = $segment->appendChild($targetElement);
         $t->appendChild($text);
         $xliffFile->appendChild($translation);
     }
     return $dom->saveXML();
 }
开发者ID:nakashu,项目名称:symfony,代码行数:32,代码来源:XliffFileDumper.php


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