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


PHP MessageCatalogue::set方法代码示例

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


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

示例1: submitFormTranslate

 public function submitFormTranslate(Form $form)
 {
     $values = $form->getValues();
     //existuje preklad ?
     $translatesLocale = $this->row->related('translate_locale')->where('language_id', $this->webLanguage)->fetch();
     if ($translatesLocale) {
         if ($values['translate'] != '') {
             $translatesLocale->update(array('translate' => $values['translate']));
         } else {
             $translatesLocale->delete();
         }
     } else {
         $this->row->related('translate_locale')->insert(array('translate' => $values['translate'], 'language_id' => $this->webLanguage));
     }
     $language = $this->languages->get($this->webLanguage);
     $catalogue = new MessageCatalogue($language['translate_locale']);
     foreach ($this->model->getAll() as $translate) {
         $translatesLocale = $translate->related('translate_locale')->where('language_id', $this->webLanguage)->fetch();
         if ($translatesLocale) {
             $catalogue->set($translate['text'], $translatesLocale['translate']);
         } else {
             $catalogue->set($translate['text'], $translate['text']);
         }
     }
     $this->writer->writeTranslations($catalogue, 'neon', ['path' => $this->context->parameters['appDir'] . '/lang/']);
     $this->flashMessage($this->translator->trans('translate.translated'));
     $this->redirect('this');
 }
开发者ID:vsek,项目名称:translate,代码行数:28,代码来源:TranslatePresenter.php

示例2: extractFile

 /**
  * Extracts translation messages from a file to the catalogue.
  *
  * @param string           $file The path to look into
  * @param MessageCatalogue $catalogue The catalogue
  */
 public function extractFile($file, MessageCatalogue $catalogue)
 {
     $buffer = NULL;
     $parser = new Parser();
     $parser->shortNoEscape = TRUE;
     foreach ($tokens = $parser->parse(file_get_contents($file)) as $token) {
         if ($token->type !== $token::MACRO_TAG || !in_array($token->name, array('_', '/_'), TRUE)) {
             if ($buffer !== NULL) {
                 $buffer .= $token->text;
             }
             continue;
         }
         if ($token->name === '/_') {
             $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $buffer, $buffer);
             $buffer = NULL;
         } elseif ($token->name === '_' && empty($token->value)) {
             $buffer = '';
         } else {
             $args = new MacroTokens($token->value);
             $writer = new PhpWriter($args, $token->modifiers);
             $message = $writer->write('%node.word');
             if (in_array(substr(trim($message), 0, 1), array('"', '\''), TRUE)) {
                 $message = substr(trim($message), 1, -1);
             }
             $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $message, $message);
         }
     }
 }
开发者ID:tomasstrejcek,项目名称:Translation,代码行数:34,代码来源:LatteExtractor.php

示例3: load

 public function load($resource = null, $culture = null, $version = 0)
 {
     $resourceName = $resource === null ? 'Global * Debug' : $resource . '/' . $culture;
     $cacheFile = $this->cacheDir . '/translations/resource-' . ($resource === null ? 'global' : $resource) . '-' . $culture . '-v' . $version . '.php';
     if (!$this->cache || !file_exists($cacheFile) || filemtime($cacheFile) + self::TTL * 3600 < time()) {
         try {
             // Delete Symfony Catalogue
             $fs = new Filesystem();
             $finder = new Finder();
             $sfCacheFiles = $finder->in($this->cacheDir . '/translations/')->name('catalogue.' . $culture . '.*');
             $fs->remove($sfCacheFiles);
         } catch (Exception $e) {
         }
         $catalogue = new MessageCatalogue($culture);
         if ($resource === null) {
             $nodesSql = 'SELECT N.node_name, N.node_type, A.attrib_name, A.attrib_original, NULL AS value_translation FROM translation_node N INNER JOIN translation_attribute A ON N.node_id = A.attrib_node';
             $nodesStmt = $this->doctrine->getManager()->getConnection()->prepare($nodesSql);
             $nodesStmt->execute();
         } else {
             $nodesSql = 'SELECT N.node_name, N.node_type, A.attrib_name, A.attrib_original, V.value_translation FROM translation_node N INNER JOIN translation_attribute A ON N.node_id=A.attrib_node LEFT JOIN translation_value V ON A.attrib_id = V.value_attribute AND (V.value_resource = :resource OR V.value_resource IS NULL)';
             $nodesStmt = $this->doctrine->getManager()->getConnection()->prepare($nodesSql);
             $nodesStmt->execute(['resource' => $resource]);
         }
         $nodes = $nodesStmt->fetchAll();
         foreach ($nodes as $node) {
             $id = $node['node_name'] . '.' . $node['attrib_name'];
             $value = $node['value_translation'];
             $type = $node['node_type'];
             if ($value != null) {
                 $catalogue->set($id, $value, $type);
             } else {
                 if ($resource != null) {
                     if ($this->debug) {
                         $this->logger->warning('Translation for key "' . $id . '" and region "' . $resourceName . '" not found!');
                     }
                 }
                 if ($this->debug) {
                     $catalogue->set($id, '[--' . $node['attrib_original'] . '--]', $type);
                 } else {
                     $catalogue->set($id, $node['attrib_original'], $type);
                 }
             }
         }
         // Save Cache
         $cacheContent = '<?php ' . PHP_EOL . 'use Symfony\\Component\\Translation\\MessageCatalogue; ' . PHP_EOL . '$catalogue = new MessageCatalogue(\'' . $culture . '\', ' . var_export($catalogue->all(), true) . '); ' . PHP_EOL . 'return $catalogue;';
         if (!is_dir($this->cacheDir . '/translations')) {
             mkdir($this->cacheDir . '/translations');
         }
         file_put_contents($cacheFile, $cacheContent);
     } else {
         $catalogue = (include $cacheFile);
     }
     return $catalogue;
 }
开发者ID:rodmen,项目名称:TranslationBundle,代码行数:54,代码来源:Loader.php

示例4: extractFile

 /**
  * Extracts translation messages from a file to the catalogue.
  *
  * @param string           $file The path to look into
  * @param MessageCatalogue $catalogue The catalogue
  */
 public function extractFile($file, MessageCatalogue $catalogue)
 {
     $pInfo = pathinfo($file);
     $tokens = token_get_all(file_get_contents($file));
     $data = array();
     foreach ($tokens as $c) {
         if (is_array($c)) {
             if ($c[0] != T_STRING && $c[0] != T_CONSTANT_ENCAPSED_STRING) {
                 continue;
             }
             if ($c[0] == T_STRING && in_array($c[1], $this->keywords)) {
                 $next = true;
                 continue;
             }
             if ($c[0] == T_CONSTANT_ENCAPSED_STRING && $next == true) {
                 $data[substr($c[1], 1, -1)][] = $pInfo['basename'] . ':' . $c[2];
                 $next = false;
             }
         } else {
             if ($c == ')') {
                 $next = false;
             }
         }
     }
     foreach ($data as $d => $value) {
         $catalogue->set(($this->prefix ? $this->prefix . '.' : '') . $d, $d);
     }
 }
开发者ID:vsek,项目名称:translate,代码行数:34,代码来源:PhpExtractor.php

示例5: testGetSet

 public function testGetSet()
 {
     $catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
     $catalogue->set('foo1', 'foo1', 'domain1');
     $this->assertEquals('foo', $catalogue->get('foo', 'domain1'));
     $this->assertEquals('foo1', $catalogue->get('foo1', 'domain1'));
 }
开发者ID:Ener-Getick,项目名称:symfony,代码行数:7,代码来源:MessageCatalogueTest.php

示例6: load

    /**
     * Loads a locale.
     *
     * @param mixed $resource A resource
     * @param string $locale A locale
     * @param string $domain The domain
     *
     * @return MessageCatalogue A MessageCatalogue instance
     *
     * @throws NotFoundResourceException when the resource cannot be found
     * @throws InvalidResourceException  when the resource cannot be loaded
     */
    public function load($resource, $locale, $domain = 'messages')
    {
        if ($this->loadAll !== true) {
            return new MessageCatalogue($locale);
        }
        $dql = <<<'DQL'
                SELECT
                  t
                FROM
                  MjrLibraryEntitiesBundle:System\Translation t
              WHERE
                  t.Locale = :locale
              ORDER BY t.Id ASC
DQL;
        $query = $this->entityManager->createQuery($dql);
        $query->setParameter(':locale', $locale);
        /** @var Translation[] $results */
        $results = $query->getResult();
        $catalogue = new MessageCatalogue($locale);
        if (count($results) > 0) {
            foreach ($results as $result) {
                $catalogue->set($result->getIdentity(), $result->getTranslation(), $domain);
            }
        }
        return $catalogue;
    }
开发者ID:ChrisWesterfield,项目名称:MJR.ONE-CP,代码行数:38,代码来源:DbLoader.php

示例7: execute

 /**
  * @param InputInterface  $input
  * @param OutputInterface $output
  */
 public function execute(InputInterface $input, OutputInterface $output)
 {
     $writer = $this->getContainer()->get('translation.writer');
     if (!$this->checkParameters($input, $output, $writer)) {
         return 1;
     }
     // get bundle directory
     $foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
     $bundleTransPath = $foundBundle->getPath() . '/Resources/translations';
     $output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $input->getArgument('locale'), $foundBundle->getName()));
     // create catalogue
     $catalogue = new MessageCatalogue($input->getArgument('locale'));
     $output->writeln('Parsing templates');
     $annotations = $this->getContainer()->get('oro_security.acl.annotation_provider')->getBundleAnnotations(array($foundBundle->getPath()));
     /** @var  $annotation Acl*/
     /** @var  $annotations AclAnnotationStorage*/
     foreach ($annotations->getAnnotations() as $annotation) {
         if ($label = $annotation->getLabel()) {
             $catalogue->set($label, $input->getOption('prefix') . $label);
         }
     }
     // load any existing messages from the translation files
     $output->writeln('Loading translation files');
     $loader = $this->getContainer()->get('translation.loader');
     $loader->loadMessages($bundleTransPath, $catalogue);
     // show compiled list of messages
     if ($input->getOption('dump-messages') === true) {
         $this->dumpMessages($input, $output, $catalogue);
     }
     // save the files
     if ($input->getOption('force') === true) {
         $this->saveMessages($input, $output, $catalogue, $writer, $bundleTransPath);
     }
 }
开发者ID:ashutosh-srijan,项目名称:findit_akeneo,代码行数:38,代码来源:AclTranslationUpdateCommand.php

示例8: applyVersion

 /**
  * Applies version to the supplied path.
  *
  * @param string $path A path
  *
  * @return string The versionized path
  */
 public function applyVersion($path)
 {
     $file = $path;
     // apply the base path
     if ('/' !== substr($path, 0, 1)) {
         $file = '/' . $path;
     }
     $reved = $this->getRevedFilename($file);
     $absPath = $this->rootDir . $file;
     $absReved = $this->rootDir . $reved;
     // $reved or unversioned
     if (file_exists($absReved)) {
         return $reved;
         // look in filesystem
     } else {
         $pattern = preg_replace('/\\.([^\\.]+$)/', '.*.$1', $absPath);
         $regex = preg_replace('/\\.([^\\.]+$)/', '\\.[\\d\\w]{' . $this->hashLength . '}\\.$1', $absPath);
         $base = str_replace($path, '', $absPath);
         foreach (glob($pattern) as $filepath) {
             if (preg_match('#' . $regex . '#', $filepath, $match)) {
                 $result = str_replace($base, '', $filepath);
                 $this->summary->set($file, $result);
                 return $filepath;
             }
         }
     }
     return $path;
 }
开发者ID:kuborgh-bzoerb,项目名称:FilerevBundle,代码行数:35,代码来源:JsonVersionStrategy.php

示例9: applyVersion

 /**
  * Applies version to the supplied path.
  *
  * @param string           $path    A path
  * @param string|bool|null $version A specific version
  *
  * @return string The versionized path
  */
 protected function applyVersion($path, $version = null)
 {
     $file = $path;
     // apply the base path
     if ('/' !== substr($path, 0, 1)) {
         $file = $this->basePath . $path;
     }
     $reved = $this->summary->get($file);
     $fullpath = $this->getRoot() . $file;
     $fullreved = $this->getRoot() . $reved;
     // $reved or unversioned
     if (file_exists($fullreved)) {
         return $reved;
         // fallback
     } else {
         $pattern = preg_replace('/\\.([^\\.]+$)/', '.*.$1', $fullpath);
         $regex = preg_replace('/\\.([^\\.]+$)/', '\\.[\\d\\w]{8}\\.$1', $fullpath);
         $base = str_replace($path, '', $fullpath);
         foreach (glob($pattern) as $filepath) {
             if (preg_match('#' . $regex . '#', $filepath)) {
                 $result = str_replace($base, '', $filepath);
                 $this->summary->set($file, $result);
                 return $result;
             }
         }
     }
     return $path;
 }
开发者ID:kuborgh-xalejado,项目名称:generator-grunt-symfony,代码行数:36,代码来源:FilerevPackage.php

示例10: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     list($xml, $encoding) = $this->parseFile($resource);
     $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     $catalogue = new MessageCatalogue($locale);
     foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
         $attributes = $translation->attributes();
         if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
             continue;
         }
         $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
         $target = (string) $translation->target;
         // If the xlf file has another encoding specified, try to convert it because
         // simple_xml will always return utf-8 encoded values
         if ('UTF-8' !== $encoding && !empty($encoding)) {
             if (function_exists('mb_convert_encoding')) {
                 $target = mb_convert_encoding($target, $encoding, 'UTF-8');
             } elseif (function_exists('iconv')) {
                 $target = iconv('UTF-8', $encoding, $target);
             } else {
                 throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
             }
         }
         $catalogue->set((string) $source, $target, $domain);
     }
     $catalogue->addResource(new FileResource($resource));
     return $catalogue;
 }
开发者ID:peintune,项目名称:Ternado,代码行数:39,代码来源:XliffFileLoader.php

示例11: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     try {
         $dom = XmlUtils::loadFile($resource);
     } catch (\InvalidArgumentException $e) {
         throw new InvalidResourceException(sprintf('Unable to load "%s".', $resource), $e->getCode(), $e);
     }
     $internalErrors = libxml_use_internal_errors(true);
     libxml_clear_errors();
     $xpath = new \DOMXPath($dom);
     $nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]');
     $catalogue = new MessageCatalogue($locale);
     if ($nodes->length == 1) {
         $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message');
         foreach ($translations as $translation) {
             $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue;
             if (!empty($translationValue)) {
                 $catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain);
             }
             $translation = $translation->nextSibling;
         }
         $catalogue->addResource(new FileResource($resource));
     }
     libxml_use_internal_errors($internalErrors);
     return $catalogue;
 }
开发者ID:EnmanuelCode,项目名称:backend-laravel,代码行数:37,代码来源:QtFileLoader.php

示例12: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     $dom = new \DOMDocument();
     $current = libxml_use_internal_errors(true);
     if (!@$dom->load($resource, defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0)) {
         throw new InvalidResourceException(implode("\n", $this->getXmlErrors()));
     }
     $xpath = new \DOMXPath($dom);
     $nodes = $xpath->evaluate('//TS/context/name[text()="' . $domain . '"]');
     $catalogue = new MessageCatalogue($locale);
     if ($nodes->length == 1) {
         $translations = $nodes->item(0)->nextSibling->parentNode->parentNode->getElementsByTagName('message');
         foreach ($translations as $translation) {
             $translationValue = (string) $translation->getElementsByTagName('translation')->item(0)->nodeValue;
             if (!empty($translationValue)) {
                 $catalogue->set((string) $translation->getElementsByTagName('source')->item(0)->nodeValue, $translationValue, $domain);
             }
             $translation = $translation->nextSibling;
         }
         $catalogue->addResource(new FileResource($resource));
     }
     libxml_use_internal_errors($current);
     return $catalogue;
 }
开发者ID:dev-lav,项目名称:htdocs,代码行数:35,代码来源:QtFileLoader.php

示例13: load

 /**
  * {@inheritdoc}
  *
  * @api
  */
 public function load($resource, $locale, $domain = 'messages')
 {
     if (!stream_is_local($resource)) {
         throw new InvalidResourceException(sprintf('This is not a local file "%s".', $resource));
     }
     if (!file_exists($resource)) {
         throw new NotFoundResourceException(sprintf('File "%s" not found.', $resource));
     }
     list($xml, $encoding) = $this->parseFile($resource);
     $xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
     $catalogue = new MessageCatalogue($locale);
     foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
         $attributes = $translation->attributes();
         if (!(isset($attributes['resname']) || isset($translation->source))) {
             continue;
         }
         $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
         // If the xlf file has another encoding specified, try to convert it because
         // simple_xml will always return utf-8 encoded values
         $target = $this->utf8ToCharset((string) (isset($translation->target) ? $translation->target : $source), $encoding);
         $catalogue->set((string) $source, $target, $domain);
         $metadata = array();
         if ($notes = $this->parseNotesMetadata($translation->note, $encoding)) {
             $metadata['notes'] = $notes;
         }
         if ($translation->target->attributes()) {
             $metadata['target-attributes'] = $translation->target->attributes();
         }
         $catalogue->setMetadata((string) $source, $metadata, $domain);
     }
     if (class_exists('Symfony\\Component\\Config\\Resource\\FileResource')) {
         $catalogue->addResource(new FileResource($resource));
     }
     return $catalogue;
 }
开发者ID:symstriker,项目名称:symfony,代码行数:40,代码来源:XliffFileLoader.php

示例14: execute

 /**
  * {@inheritDoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // get bundle directory
     $foundBundle = $this->getApplication()->getKernel()->getBundle($input->getArgument('bundle'));
     $bundleTransPath = $foundBundle->getPath() . '/Resources/translations';
     $writer = $this->getContainer()->get('translation.writer');
     $supportedFormats = $writer->getFormats();
     if (!in_array($input->getOption('output-format'), $supportedFormats)) {
         $output->writeln('<error>Wrong output format</error>');
         $output->writeln('Supported formats are ' . implode(', ', $supportedFormats) . '.');
         return 1;
     }
     $this->orm = $this->getContainer()->get('doctrine.orm.default_entity_manager');
     $languages = $this->orm->getRepository('RaindropTranslationBundle:Language')->findAll();
     $tokens = $this->orm->getRepository('RaindropTranslationBundle:LanguageToken')->findAll();
     foreach ($languages as $language) {
         $output->writeln(sprintf('Generating "<info>%s</info>" translation files for "<info>%s</info>"', $language, $foundBundle->getName()));
         // create catalogue
         $catalogue = new MessageCatalogue($language);
         foreach ($tokens as $token) {
             $translation = $this->orm->getRepository('RaindropTranslationBundle:LanguageTranslation')->findOneBy(array('language' => $language, 'languageToken' => $token, 'catalogue' => $token->getCatalogue()));
             if (!empty($translation)) {
                 $content = $translation->getTranslation() != '' ? $translation->getTranslation() : null;
                 $catalogue->set($token->getToken(), $content);
             }
         }
         $writer->writeTranslations($catalogue, $input->getOption('output-format'), array('path' => $bundleTransPath));
     }
 }
开发者ID:kyaroslav,项目名称:RaindropTranslationBundle,代码行数:32,代码来源:ExportLanguageTranslationCommand.php

示例15: getCatalogue

 protected function getCatalogue($locale, $messages)
 {
     $catalogue = new MessageCatalogue($locale);
     foreach ($messages as $key => $translation) {
         $catalogue->set($key, $translation);
     }
     return $catalogue;
 }
开发者ID:nicodmf,项目名称:symfony,代码行数:8,代码来源:TranslatorTest.php


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