Update to Drupal 8.1.0. For more information, see https://www.drupal.org/drupal-8.1.0-release-notes
This commit is contained in:
parent
b11a755ba8
commit
c0a0d5a94c
6920 changed files with 64395 additions and 57312 deletions
|
@ -27,6 +27,16 @@ class CsvFileDumper extends FileDumper
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$handle = fopen('php://memory', 'rb+');
|
||||
|
||||
|
|
27
vendor/symfony/translation/Dumper/FileDumper.php
vendored
27
vendor/symfony/translation/Dumper/FileDumper.php
vendored
|
@ -82,10 +82,28 @@ abstract class FileDumper implements DumperInterface
|
|||
}
|
||||
}
|
||||
// save file
|
||||
file_put_contents($fullpath, $this->format($messages, $domain));
|
||||
file_put_contents($fullpath, $this->formatCatalogue($messages, $domain, $options));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a domain of a message catalogue to its string representation.
|
||||
*
|
||||
* Override this function in child class if $options is used for message formatting.
|
||||
*
|
||||
* @param MessageCatalogue $messages
|
||||
* @param string $domain
|
||||
* @param array $options
|
||||
*
|
||||
* @return string representation
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method will replace the format method in 3.0. You should overwrite it instead of overwriting format instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->format($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms a domain of a message catalogue to its string representation.
|
||||
*
|
||||
|
@ -93,8 +111,13 @@ abstract class FileDumper implements DumperInterface
|
|||
* @param string $domain
|
||||
*
|
||||
* @return string representation
|
||||
*
|
||||
* @deprecated since version 2.8, to be removed in 3.0. Overwrite formatCatalogue() instead.
|
||||
*/
|
||||
abstract protected function format(MessageCatalogue $messages, $domain);
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
throw new \LogicException('The "FileDumper::format" method needs to be overwritten, you should implement either "format" or "formatCatalogue".');
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the file extension of the dumper.
|
||||
|
|
|
@ -29,6 +29,16 @@ class IcuResFileDumper extends FileDumper
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$data = $indexes = $resources = '';
|
||||
|
||||
|
@ -79,11 +89,7 @@ class IcuResFileDumper extends FileDumper
|
|||
1, 4, 0, 0 // Unicode version
|
||||
);
|
||||
|
||||
$output = $header
|
||||
.$root
|
||||
.$data;
|
||||
|
||||
return $output;
|
||||
return $header.$root.$data;
|
||||
}
|
||||
|
||||
private function writePadding($data)
|
||||
|
@ -97,9 +103,7 @@ class IcuResFileDumper extends FileDumper
|
|||
|
||||
private function getPosition($data)
|
||||
{
|
||||
$position = (strlen($data) + 28) / 4;
|
||||
|
||||
return $position;
|
||||
return (strlen($data) + 28) / 4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,16 @@ class IniFileDumper extends FileDumper
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = '';
|
||||
|
||||
|
|
|
@ -25,7 +25,23 @@ class JsonFileDumper extends FileDumper
|
|||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
return json_encode($messages->all($domain), defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0);
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -25,6 +25,16 @@ class MoFileDumper extends FileDumper
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
|
||||
$offsets = array();
|
||||
|
|
|
@ -25,9 +25,17 @@ class PhpFileDumper extends FileDumper
|
|||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
$output = "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $output;
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
return "<?php\n\nreturn ".var_export($messages->all($domain), true).";\n";
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -24,6 +24,16 @@ class PoFileDumper extends FileDumper
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain = 'messages')
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = 'msgid ""'."\n";
|
||||
$output .= 'msgstr ""'."\n";
|
||||
|
|
|
@ -24,6 +24,16 @@ class QtFileDumper extends FileDumper
|
|||
* {@inheritdoc}
|
||||
*/
|
||||
public function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$dom = new \DOMDocument('1.0', 'utf-8');
|
||||
$dom->formatOutput = true;
|
||||
|
|
|
@ -20,23 +20,30 @@ use Symfony\Component\Translation\MessageCatalogue;
|
|||
*/
|
||||
class XliffFileDumper extends FileDumper
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $defaultLocale;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function dump(MessageCatalogue $messages, $options = array())
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
if (array_key_exists('default_locale', $options)) {
|
||||
$this->defaultLocale = $options['default_locale'];
|
||||
} else {
|
||||
$this->defaultLocale = \Locale::getDefault();
|
||||
$xliffVersion = '1.2';
|
||||
if (array_key_exists('xliff_version', $options)) {
|
||||
$xliffVersion = $options['xliff_version'];
|
||||
}
|
||||
|
||||
parent::dump($messages, $options);
|
||||
if (array_key_exists('default_locale', $options)) {
|
||||
$defaultLocale = $options['default_locale'];
|
||||
} else {
|
||||
$defaultLocale = \Locale::getDefault();
|
||||
}
|
||||
|
||||
if ('1.2' === $xliffVersion) {
|
||||
return $this->dumpXliff1($defaultLocale, $messages, $domain, $options);
|
||||
}
|
||||
if ('2.0' === $xliffVersion) {
|
||||
return $this->dumpXliff2($defaultLocale, $messages, $domain, $options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -44,6 +51,26 @@ class XliffFileDumper extends FileDumper
|
|||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExtension()
|
||||
{
|
||||
return 'xlf';
|
||||
}
|
||||
|
||||
private function dumpXliff1($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$toolInfo = array('tool-id' => 'symfony', 'tool-name' => 'Symfony');
|
||||
if (array_key_exists('tool_info', $options)) {
|
||||
$toolInfo = array_merge($toolInfo, $options['tool_info']);
|
||||
}
|
||||
|
||||
$dom = new \DOMDocument('1.0', 'utf-8');
|
||||
$dom->formatOutput = true;
|
||||
|
||||
|
@ -52,11 +79,17 @@ class XliffFileDumper extends FileDumper
|
|||
$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('source-language', str_replace('_', '-', $defaultLocale));
|
||||
$xliffFile->setAttribute('target-language', str_replace('_', '-', $messages->getLocale()));
|
||||
$xliffFile->setAttribute('datatype', 'plaintext');
|
||||
$xliffFile->setAttribute('original', 'file.ext');
|
||||
|
||||
$xliffHead = $xliffFile->appendChild($dom->createElement('header'));
|
||||
$xliffTool = $xliffHead->appendChild($dom->createElement('tool'));
|
||||
foreach ($toolInfo as $id => $value) {
|
||||
$xliffTool->setAttribute($id, $value);
|
||||
}
|
||||
|
||||
$xliffBody = $xliffFile->appendChild($dom->createElement('body'));
|
||||
foreach ($messages->all($domain) as $source => $target) {
|
||||
$translation = $dom->createElement('trans-unit');
|
||||
|
@ -70,11 +103,17 @@ class XliffFileDumper extends FileDumper
|
|||
// 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'));
|
||||
$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);
|
||||
|
||||
$metadata = $messages->getMetadata($source, $domain);
|
||||
if (null !== $metadata && array_key_exists('notes', $metadata) && is_array($metadata['notes'])) {
|
||||
if ($this->hasMetadataArrayInfo('notes', $metadata)) {
|
||||
foreach ($metadata['notes'] as $note) {
|
||||
if (!isset($note['content'])) {
|
||||
continue;
|
||||
|
@ -99,11 +138,56 @@ class XliffFileDumper extends FileDumper
|
|||
return $dom->saveXML();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function getExtension()
|
||||
private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
return 'xlf';
|
||||
$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();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param array|null $metadata
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
private function hasMetadataArrayInfo($key, $metadata = null)
|
||||
{
|
||||
return null !== $metadata && array_key_exists($key, $metadata) && ($metadata[$key] instanceof \Traversable || is_array($metadata[$key]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
namespace Symfony\Component\Translation\Dumper;
|
||||
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
use Symfony\Component\Translation\Util\ArrayConverter;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
/**
|
||||
|
@ -24,13 +25,33 @@ class YamlFileDumper extends FileDumper
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
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));
|
||||
$data = $messages->all($domain);
|
||||
|
||||
if (isset($options['as_tree']) && $options['as_tree']) {
|
||||
$data = ArrayConverter::expandToTree($data);
|
||||
}
|
||||
|
||||
if (isset($options['inline']) && ($inline = (int) $options['inline']) > 0) {
|
||||
return Yaml::dump($data, $inline);
|
||||
}
|
||||
|
||||
return Yaml::dump($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function format(MessageCatalogue $messages, $domain)
|
||||
{
|
||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0. Use the formatCatalogue() method instead.', E_USER_DEPRECATED);
|
||||
|
||||
return $this->formatCatalogue($messages, $domain);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Reference in a new issue