本文整理匯總了PHP中Symfony\Component\Translation\MessageCatalogue::all方法的典型用法代碼示例。如果您正苦於以下問題:PHP MessageCatalogue::all方法的具體用法?PHP MessageCatalogue::all怎麽用?PHP MessageCatalogue::all使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Symfony\Component\Translation\MessageCatalogue
的用法示例。
在下文中一共展示了MessageCatalogue::all方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: format
/**
* {@inheritDoc}
*/
protected function format(MessageCatalogue $messages, $domain)
{
$m = $messages->all($domain);
if ($this->nestLevel > 0) {
// build a message tree from the message list, with a max depth
// of $this->nestLevel
$tree = array();
foreach ($m as $key => $message) {
// dots are ignored at the beginning and at the end of a key
$key = trim($key, "\t .");
if (strlen($key) > 0) {
$codes = explode('.', $key, $this->nestLevel + 1);
$node =& $tree;
foreach ($codes as $code) {
if (strlen($code) > 0) {
if (!isset($node)) {
$node = array();
}
$node =& $node[$code];
}
}
$node = $message;
}
}
return Yaml::dump($tree, $this->nestLevel + 1);
// second parameter at 1 outputs normal line-by-line catalogue
} else {
return Yaml::dump($m, 1);
}
}
示例2: format
/**
* {@inheritdoc}
*/
protected function format(MessageCatalogue $messages, $domain)
{
if (!class_exists('Symfony\\Component\\Yaml\\Yaml')) {
throw new \LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
}
return Yaml::dump($messages->all($domain));
}
示例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;
}
}
示例4: initializeCacheCatalogue
/**
* Initialize filerev catalogue from cache
* or generate cache if not already available
*/
private function initializeCacheCatalogue()
{
if (isset($this->catalogue)) {
return;
}
$debug = $this->container->getParameter('grunt.debug');
$cache = new ConfigCache($this->getCatalogueCachePath(), $debug);
if (!$cache->isFresh()) {
$this->initializeCatalogue();
$content = sprintf(<<<EOF
<?php
use Symfony\\Component\\Translation\\MessageCatalogue;
\$catalogue = new MessageCatalogue(null, %s);
return \$catalogue;
EOF
, var_export($this->catalogue->all(), true));
$cache->write($content, $this->catalogue->getResources());
return;
}
$this->catalogue = (include $cache);
}
示例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();
}
示例6: testReplace
public function testReplace()
{
$catalogue = new MessageCatalogue('en', array('domain1' => array('foo' => 'foo'), 'domain2' => array('bar' => 'bar')));
$catalogue->replace($messages = array('foo1' => 'foo1'), 'domain1');
$this->assertEquals($messages, $catalogue->all('domain1'));
}
示例7: 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();
}
示例8: format
/**
* @param MessageCatalogue $messages
* @param string $domain
* @return array
*/
protected function format(MessageCatalogue $messages, $domain)
{
$data = array();
foreach ($messages->all($domain) as $key => $value) {
$data[] = array($key, $value);
}
return $data;
}
示例9: formatCatalogue
/**
* {@inheritdoc}
*/
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
$output = '';
foreach ($messages->all($domain) as $source => $target) {
$escapeTarget = str_replace('"', '\\"', $target);
$output .= $source . '="' . $escapeTarget . "\"\n";
}
return $output;
}
示例10: format
/**
* {@inheritDoc}
*/
public function format(MessageCatalogue $messages, $domain = 'messages')
{
$output = '';
foreach ($messages->all($domain) as $source => $target) {
$output .= sprintf("msgid \"%s\"\n", $this->escape($source));
$output .= sprintf("msgstr \"%s\"\n\n", $this->escape($target));
}
return $output;
}
示例11: format
/**
* {@inheritDoc}
*/
public function format(MessageCatalogue $messages, $domain = 'messages')
{
$output = '';
foreach ($messages->all($domain) as $source => $target) {
$escapeTarget = str_replace('"', '\\"', $target);
$output .= $source . '="' . $escapeTarget . "\"\n";
}
return $output;
}
示例12: formatCatalogue
/**
* {@inheritdoc}
*/
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
{
if (isset($options['json_encoding'])) {
$flags = $options['json_encoding'];
} else {
$flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
}
return json_encode($messages->all($domain), $flags);
}
示例13: format
/**
*
* {@inheritdoc}
*
*/
public function format(MessageCatalogue $messages, $domain = 'messages')
{
$handle = fopen('php://memory', 'rb+');
foreach ($messages->all($domain) as $source => $target) {
fputcsv($handle, array($source, $target), $this->delimiter, $this->enclosure);
}
rewind($handle);
$output = stream_get_contents($handle);
fclose($handle);
return $output;
}
示例14: 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;
}
示例15: addMessageCatalogue
/**
* @param MessageCatalogue $messageCatalogue
* @param string $language
*/
private function addMessageCatalogue(MessageCatalogue $messageCatalogue, $language)
{
if (!$messageCatalogue->all()) {
return;
}
if (isset($this->messageCatalogues[$language])) {
$this->messageCatalogues[$language]->addCatalogue($messageCatalogue);
} else {
$this->messageCatalogues[$language] = $messageCatalogue;
}
}