Laravel version update
Laravel version update
This commit is contained in:
@@ -44,8 +44,8 @@ class CsvFileDumper extends FileDumper
|
||||
/**
|
||||
* Sets the delimiter and escape character for CSV.
|
||||
*
|
||||
* @param string $delimiter delimiter character
|
||||
* @param string $enclosure enclosure character
|
||||
* @param string $delimiter Delimiter character
|
||||
* @param string $enclosure Enclosure character
|
||||
*/
|
||||
public function setCsvControl($delimiter = ';', $enclosure = '"')
|
||||
{
|
||||
|
38
vendor/symfony/translation/Dumper/FileDumper.php
vendored
38
vendor/symfony/translation/Dumper/FileDumper.php
vendored
@@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Dumper;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Translation\Exception\RuntimeException;
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
|
||||
/**
|
||||
* FileDumper is an implementation of DumperInterface that dump a message catalogue to file(s).
|
||||
* Performs backup of already existing files.
|
||||
*
|
||||
* Options:
|
||||
* - path (mandatory): the directory where the files should be saved
|
||||
@@ -31,13 +32,6 @@ abstract class FileDumper implements DumperInterface
|
||||
*/
|
||||
protected $relativePathTemplate = '%domain%.%locale%.%extension%';
|
||||
|
||||
/**
|
||||
* Make file backup before the dump.
|
||||
*
|
||||
* @var bool
|
||||
*/
|
||||
private $backup = true;
|
||||
|
||||
/**
|
||||
* Sets the template for the relative paths to files.
|
||||
*
|
||||
@@ -52,10 +46,16 @@ abstract class FileDumper implements DumperInterface
|
||||
* Sets backup flag.
|
||||
*
|
||||
* @param bool
|
||||
*
|
||||
* @deprecated since Symfony 4.1
|
||||
*/
|
||||
public function setBackup($backup)
|
||||
{
|
||||
$this->backup = $backup;
|
||||
@trigger_error(sprintf('The "%s()" method is deprecated since Symfony 4.1.', __METHOD__), E_USER_DEPRECATED);
|
||||
|
||||
if (false !== $backup) {
|
||||
throw new \LogicException('The backup feature is no longer supported.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -64,21 +64,16 @@ abstract class FileDumper implements DumperInterface
|
||||
public function dump(MessageCatalogue $messages, $options = array())
|
||||
{
|
||||
if (!array_key_exists('path', $options)) {
|
||||
throw new \InvalidArgumentException('The file dumper needs a path option.');
|
||||
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) {
|
||||
copy($fullpath, $fullpath.'~');
|
||||
}
|
||||
} else {
|
||||
$directory = dirname($fullpath);
|
||||
if (!file_exists($fullpath)) {
|
||||
$directory = \dirname($fullpath);
|
||||
if (!file_exists($directory) && !@mkdir($directory, 0777, true)) {
|
||||
throw new \RuntimeException(sprintf('Unable to create directory "%s".', $directory));
|
||||
throw new RuntimeException(sprintf('Unable to create directory "%s".', $directory));
|
||||
}
|
||||
}
|
||||
// save file
|
||||
@@ -106,13 +101,8 @@ abstract class FileDumper implements DumperInterface
|
||||
|
||||
/**
|
||||
* Gets the relative file path using the template.
|
||||
*
|
||||
* @param string $domain The domain
|
||||
* @param string $locale The locale
|
||||
*
|
||||
* @return string The relative file path
|
||||
*/
|
||||
private function getRelativePath($domain, $locale)
|
||||
private function getRelativePath(string $domain, string $locale): string
|
||||
{
|
||||
return strtr($this->relativePathTemplate, array(
|
||||
'%domain%' => $domain,
|
||||
|
@@ -33,8 +33,8 @@ class IcuResFileDumper extends FileDumper
|
||||
$data = $indexes = $resources = '';
|
||||
|
||||
foreach ($messages->all($domain) as $source => $target) {
|
||||
$indexes .= pack('v', strlen($data) + 28);
|
||||
$data .= $source."\0";
|
||||
$indexes .= pack('v', \strlen($data) + 28);
|
||||
$data .= $source."\0";
|
||||
}
|
||||
|
||||
$data .= $this->writePadding($data);
|
||||
@@ -44,7 +44,7 @@ class IcuResFileDumper extends FileDumper
|
||||
foreach ($messages->all($domain) as $source => $target) {
|
||||
$resources .= pack('V', $this->getPosition($data));
|
||||
|
||||
$data .= pack('V', strlen($target))
|
||||
$data .= pack('V', \strlen($target))
|
||||
.mb_convert_encoding($target."\0", 'UTF-16LE', 'UTF-8')
|
||||
.$this->writePadding($data)
|
||||
;
|
||||
@@ -52,7 +52,7 @@ class IcuResFileDumper extends FileDumper
|
||||
|
||||
$resOffset = $this->getPosition($data);
|
||||
|
||||
$data .= pack('v', count($messages))
|
||||
$data .= pack('v', \count($messages->all($domain)))
|
||||
.$indexes
|
||||
.$this->writePadding($data)
|
||||
.$resources
|
||||
@@ -63,11 +63,11 @@ class IcuResFileDumper extends FileDumper
|
||||
$root = pack('V7',
|
||||
$resOffset + (2 << 28), // Resource Offset + Resource Type
|
||||
6, // Index length
|
||||
$keyTop, // Index keys top
|
||||
$bundleTop, // Index resources top
|
||||
$bundleTop, // Index bundle top
|
||||
count($messages), // Index max table length
|
||||
0 // Index attributes
|
||||
$keyTop, // Index keys top
|
||||
$bundleTop, // Index resources top
|
||||
$bundleTop, // Index bundle top
|
||||
\count($messages->all($domain)), // Index max table length
|
||||
0 // Index attributes
|
||||
);
|
||||
|
||||
$header = pack('vC2v4C12@32',
|
||||
@@ -84,7 +84,7 @@ class IcuResFileDumper extends FileDumper
|
||||
|
||||
private function writePadding($data)
|
||||
{
|
||||
$padding = strlen($data) % 4;
|
||||
$padding = \strlen($data) % 4;
|
||||
|
||||
if ($padding) {
|
||||
return str_repeat("\xAA", 4 - $padding);
|
||||
@@ -93,7 +93,7 @@ class IcuResFileDumper extends FileDumper
|
||||
|
||||
private function getPosition($data)
|
||||
{
|
||||
return (strlen($data) + 28) / 4;
|
||||
return (\strlen($data) + 28) / 4;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -28,7 +28,7 @@ class JsonFileDumper extends FileDumper
|
||||
if (isset($options['json_encoding'])) {
|
||||
$flags = $options['json_encoding'];
|
||||
} else {
|
||||
$flags = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
|
||||
$flags = JSON_PRETTY_PRINT;
|
||||
}
|
||||
|
||||
return json_encode($messages->all($domain), $flags);
|
||||
|
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Dumper;
|
||||
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
use Symfony\Component\Translation\Loader\MoFileLoader;
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
|
||||
/**
|
||||
* MoFileDumper generates a gettext formatted string representation of a message catalogue.
|
||||
@@ -26,7 +26,7 @@ class MoFileDumper extends FileDumper
|
||||
*/
|
||||
public function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||
{
|
||||
$output = $sources = $targets = $sourceOffsets = $targetOffsets = '';
|
||||
$sources = $targets = $sourceOffsets = $targetOffsets = '';
|
||||
$offsets = array();
|
||||
$size = 0;
|
||||
|
||||
@@ -47,7 +47,7 @@ class MoFileDumper extends FileDumper
|
||||
'offsetHashes' => MoFileLoader::MO_HEADER_SIZE + (16 * $size),
|
||||
);
|
||||
|
||||
$sourcesSize = strlen($sources);
|
||||
$sourcesSize = \strlen($sources);
|
||||
$sourcesStart = $header['offsetHashes'] + 1;
|
||||
|
||||
foreach ($offsets as $offset) {
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Dumper;
|
||||
|
||||
use Symfony\Component\Translation\Exception\InvalidArgumentException;
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
|
||||
/**
|
||||
@@ -43,7 +44,7 @@ class XliffFileDumper extends FileDumper
|
||||
return $this->dumpXliff2($defaultLocale, $messages, $domain, $options);
|
||||
}
|
||||
|
||||
throw new \InvalidArgumentException(sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion));
|
||||
throw new InvalidArgumentException(sprintf('No support implemented for dumping XLIFF version "%s".', $xliffVersion));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +85,7 @@ class XliffFileDumper extends FileDumper
|
||||
foreach ($messages->all($domain) as $source => $target) {
|
||||
$translation = $dom->createElement('trans-unit');
|
||||
|
||||
$translation->setAttribute('id', md5($source));
|
||||
$translation->setAttribute('id', strtr(substr(base64_encode(hash('sha256', $source, true)), 0, 7), '/+', '._'));
|
||||
$translation->setAttribute('resname', $source);
|
||||
|
||||
$s = $translation->appendChild($dom->createElement('source'));
|
||||
@@ -144,7 +145,29 @@ class XliffFileDumper extends FileDumper
|
||||
|
||||
foreach ($messages->all($domain) as $source => $target) {
|
||||
$translation = $dom->createElement('unit');
|
||||
$translation->setAttribute('id', md5($source));
|
||||
$translation->setAttribute('id', strtr(substr(base64_encode(hash('sha256', $source, true)), 0, 7), '/+', '._'));
|
||||
$name = $source;
|
||||
if (\strlen($source) > 80) {
|
||||
$name = substr(md5($source), -7);
|
||||
}
|
||||
$translation->setAttribute('name', $name);
|
||||
$metadata = $messages->getMetadata($source, $domain);
|
||||
|
||||
// Add notes section
|
||||
if ($this->hasMetadataArrayInfo('notes', $metadata)) {
|
||||
$notesElement = $dom->createElement('notes');
|
||||
foreach ($metadata['notes'] as $note) {
|
||||
$n = $dom->createElement('note');
|
||||
$n->appendChild($dom->createTextNode(isset($note['content']) ? $note['content'] : ''));
|
||||
unset($note['content']);
|
||||
|
||||
foreach ($note as $name => $value) {
|
||||
$n->setAttribute($name, $value);
|
||||
}
|
||||
$notesElement->appendChild($n);
|
||||
}
|
||||
$translation->appendChild($notesElement);
|
||||
}
|
||||
|
||||
$segment = $translation->appendChild($dom->createElement('segment'));
|
||||
|
||||
@@ -155,7 +178,6 @@ class XliffFileDumper extends FileDumper
|
||||
$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);
|
||||
@@ -178,6 +200,6 @@ class XliffFileDumper extends FileDumper
|
||||
*/
|
||||
private function hasMetadataArrayInfo($key, $metadata = null)
|
||||
{
|
||||
return null !== $metadata && array_key_exists($key, $metadata) && ($metadata[$key] instanceof \Traversable || is_array($metadata[$key]));
|
||||
return null !== $metadata && array_key_exists($key, $metadata) && ($metadata[$key] instanceof \Traversable || \is_array($metadata[$key]));
|
||||
}
|
||||
}
|
||||
|
@@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Dumper;
|
||||
|
||||
use Symfony\Component\Translation\Exception\LogicException;
|
||||
use Symfony\Component\Translation\MessageCatalogue;
|
||||
use Symfony\Component\Translation\Util\ArrayConverter;
|
||||
use Symfony\Component\Yaml\Yaml;
|
||||
@@ -22,13 +23,20 @@ use Symfony\Component\Yaml\Yaml;
|
||||
*/
|
||||
class YamlFileDumper extends FileDumper
|
||||
{
|
||||
private $extension;
|
||||
|
||||
public function __construct(string $extension = 'yml')
|
||||
{
|
||||
$this->extension = $extension;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
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.');
|
||||
throw new LogicException('Dumping translations in the YAML format requires the Symfony Yaml component.');
|
||||
}
|
||||
|
||||
$data = $messages->all($domain);
|
||||
@@ -49,6 +57,6 @@ class YamlFileDumper extends FileDumper
|
||||
*/
|
||||
protected function getExtension()
|
||||
{
|
||||
return 'yml';
|
||||
return $this->extension;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user