[Translation] removed unneeded getter/setter
This commit is contained in:
parent
8792575795
commit
ad4624cd04
@ -23,37 +23,6 @@ use Symfony\Component\Config\Resource\FileResource;
|
|||||||
*/
|
*/
|
||||||
class XliffFileLoader implements LoaderInterface
|
class XliffFileLoader implements LoaderInterface
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
|
||||||
* Encoding specified in xlf file
|
|
||||||
*
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $encoding = null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get $encoding
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getEncoding()
|
|
||||||
{
|
|
||||||
return $this->encoding;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set $encoding
|
|
||||||
*
|
|
||||||
* @param string $encoding
|
|
||||||
* @return \Symfony\Component\Translation\Loader\XliffFileLoader
|
|
||||||
*/
|
|
||||||
public function setEncoding($encoding)
|
|
||||||
{
|
|
||||||
$this->encoding = strtoupper($encoding);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*
|
*
|
||||||
@ -68,8 +37,6 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
$xml = $this->parseFile($resource);
|
$xml = $this->parseFile($resource);
|
||||||
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
|
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
|
||||||
|
|
||||||
$encoding = $this->getEncoding();
|
|
||||||
|
|
||||||
$catalogue = new MessageCatalogue($locale);
|
$catalogue = new MessageCatalogue($locale);
|
||||||
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
||||||
$attributes = $translation->attributes();
|
$attributes = $translation->attributes();
|
||||||
@ -81,19 +48,19 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
|
$source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
|
||||||
$target = (string) $translation->target;
|
$target = (string) $translation->target;
|
||||||
|
|
||||||
// If the xlf file has another encoding specified try to convert it here because
|
// If the xlf file has another encoding specified, try to convert it because
|
||||||
// simple_xml will always return utf-8 encoded values
|
// simple_xml will always return utf-8 encoded values
|
||||||
if ($encoding !== null) {
|
if ('UTF-8' !== $this->encoding && !empty($this->encoding)) {
|
||||||
if (function_exists('mb_convert_encoding')) {
|
if (function_exists('mb_convert_encoding')) {
|
||||||
$target = mb_convert_encoding($target, $encoding, 'UTF-8');
|
$target = mb_convert_encoding($target, $this->encoding, 'UTF-8');
|
||||||
} elseif (function_exists('iconv')) {
|
} elseif (function_exists('iconv')) {
|
||||||
$target = iconv('UTF-8', $encoding, $target);
|
$target = iconv('UTF-8', $this->encoding, $target);
|
||||||
} else {
|
} else {
|
||||||
throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
|
throw new \RuntimeException('No suitable convert encoding function (use UTF-8 as your encoding or install the iconv or mbstring extension).');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$catalogue->set((string) $translation->source, $target, $domain);
|
$catalogue->set((string) $source, $target, $domain);
|
||||||
}
|
}
|
||||||
$catalogue->addResource(new FileResource($resource));
|
$catalogue->addResource(new FileResource($resource));
|
||||||
|
|
||||||
@ -123,10 +90,7 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
throw new \RuntimeException(implode("\n", $this->getXmlErrors($internalErrors)));
|
throw new \RuntimeException(implode("\n", $this->getXmlErrors($internalErrors)));
|
||||||
}
|
}
|
||||||
|
|
||||||
$encoding = strtoupper($dom->encoding);
|
$this->encoding = strtoupper($dom->encoding);
|
||||||
if (!empty($encoding) && $encoding != 'UTF-8') {
|
|
||||||
$this->setEncoding($encoding);
|
|
||||||
}
|
|
||||||
|
|
||||||
libxml_disable_entity_loader($disableEntities);
|
libxml_disable_entity_loader($disableEntities);
|
||||||
|
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
<body>
|
<body>
|
||||||
<trans-unit id="1" resname="foo">
|
<trans-unit id="1" resname="foo">
|
||||||
<source>foo</source>
|
<source>foo</source>
|
||||||
<target>bär</target>
|
<target>bär</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
<trans-unit id="2" resname="bar">
|
<trans-unit id="2" resname="bar">
|
||||||
<source>bar</source>
|
<source>bar</source>
|
||||||
<target>föö</target>
|
<target>föö</target>
|
||||||
</trans-unit>
|
</trans-unit>
|
||||||
</body>
|
</body>
|
||||||
</file>
|
</file>
|
||||||
|
Reference in New Issue
Block a user