feature #15717 [Translator][Loader] added XLIFF 2.0 support. (xphere, aitboudad)
This PR was merged into the 2.8 branch. Discussion ---------- [Translator][Loader] added XLIFF 2.0 support. | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Fixed tickets | #11853, #12853 | Tests pass? | yes | License | MIT Commits -------0c24d55
[Translation][Dumper] added XLIFF 2.0 support.7af4fc7
[XLIFF 2.0] added support for target attributes.ace6042
apply some fixes.ce540ae
update changelog.ff5d6a3
[Translation][Loader] added XLIFF 2.0 support.
This commit is contained in:
commit
7b358a144a
@ -7,6 +7,7 @@ CHANGELOG
|
|||||||
* deprecated Translator::getMessages(), rely on TranslatorBagInterface::getCatalogue() instead.
|
* deprecated Translator::getMessages(), rely on TranslatorBagInterface::getCatalogue() instead.
|
||||||
* added option `json_encoding` to JsonFileDumper
|
* added option `json_encoding` to JsonFileDumper
|
||||||
* added options `as_tree`, `inline` to YamlFileDumper
|
* added options `as_tree`, `inline` to YamlFileDumper
|
||||||
|
* added support for XLIFF 2.0.
|
||||||
* added support for XLIFF target and tool attributes.
|
* added support for XLIFF target and tool attributes.
|
||||||
* added message parameters to DataCollectorTranslator.
|
* added message parameters to DataCollectorTranslator.
|
||||||
* [DEPRECATION] The `DiffOperation` class has been deprecated and
|
* [DEPRECATION] The `DiffOperation` class has been deprecated and
|
||||||
|
@ -25,12 +25,45 @@ class XliffFileDumper extends FileDumper
|
|||||||
*/
|
*/
|
||||||
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
protected function formatCatalogue(MessageCatalogue $messages, $domain, array $options = array())
|
||||||
{
|
{
|
||||||
|
$xliffVersion = '1.2';
|
||||||
|
if (array_key_exists('xliff_version', $options)) {
|
||||||
|
$xliffVersion = $options['xliff_version'];
|
||||||
|
}
|
||||||
|
|
||||||
if (array_key_exists('default_locale', $options)) {
|
if (array_key_exists('default_locale', $options)) {
|
||||||
$defaultLocale = $options['default_locale'];
|
$defaultLocale = $options['default_locale'];
|
||||||
} else {
|
} else {
|
||||||
$defaultLocale = \Locale::getDefault();
|
$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));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function format(MessageCatalogue $messages, $domain)
|
||||||
|
{
|
||||||
|
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');
|
$toolInfo = array('tool-id' => 'symfony', 'tool-name' => 'Symfony');
|
||||||
if (array_key_exists('tool_info', $options)) {
|
if (array_key_exists('tool_info', $options)) {
|
||||||
$toolInfo = array_merge($toolInfo, $options['tool_info']);
|
$toolInfo = array_merge($toolInfo, $options['tool_info']);
|
||||||
@ -103,20 +136,46 @@ class XliffFileDumper extends FileDumper
|
|||||||
return $dom->saveXML();
|
return $dom->saveXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private function dumpXliff2($defaultLocale, MessageCatalogue $messages, $domain, array $options = array())
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function format(MessageCatalogue $messages, $domain)
|
|
||||||
{
|
{
|
||||||
return $this->formatCatalogue($messages, $domain);
|
$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();
|
||||||
* {@inheritdoc}
|
|
||||||
*/
|
|
||||||
protected function getExtension()
|
|
||||||
{
|
|
||||||
return 'xlf';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -41,10 +41,49 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
throw new NotFoundResourceException(sprintf('File "%s" not found.', $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);
|
$catalogue = new MessageCatalogue($locale);
|
||||||
|
$this->extract($resource, $catalogue, $domain);
|
||||||
|
|
||||||
|
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
|
||||||
|
$catalogue->addResource(new FileResource($resource));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $catalogue;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function extract($resource, MessageCatalogue $catalogue, $domain)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$dom = XmlUtils::loadFile($resource);
|
||||||
|
} catch (\InvalidArgumentException $e) {
|
||||||
|
throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $resource, $e->getMessage()), $e->getCode(), $e);
|
||||||
|
}
|
||||||
|
|
||||||
|
$xliffVersion = $this->getVersionNumber($dom);
|
||||||
|
$this->validateSchema($xliffVersion, $dom, $this->getSchema($xliffVersion));
|
||||||
|
|
||||||
|
if ('1.2' === $xliffVersion) {
|
||||||
|
$this->extractXliff1($dom, $catalogue, $domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ('2.0' === $xliffVersion) {
|
||||||
|
$this->extractXliff2($dom, $catalogue, $domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract messages and metadata from DOMDocument into a MessageCatalogue.
|
||||||
|
*
|
||||||
|
* @param \DOMDocument $dom Source to extract messages and metadata
|
||||||
|
* @param MessageCatalogue $catalogue Catalogue where we'll collect messages and metadata
|
||||||
|
* @param string $domain The domain
|
||||||
|
*/
|
||||||
|
private function extractXliff1(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
|
||||||
|
{
|
||||||
|
$xml = simplexml_import_dom($dom);
|
||||||
|
$encoding = strtoupper($dom->encoding);
|
||||||
|
|
||||||
|
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:1.2');
|
||||||
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
|
||||||
$attributes = $translation->attributes();
|
$attributes = $translation->attributes();
|
||||||
|
|
||||||
@ -64,17 +103,47 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
$metadata['notes'] = $notes;
|
$metadata['notes'] = $notes;
|
||||||
}
|
}
|
||||||
if (isset($translation->target) && $translation->target->attributes()) {
|
if (isset($translation->target) && $translation->target->attributes()) {
|
||||||
$metadata['target-attributes'] = $translation->target->attributes();
|
$metadata['target-attributes'] = array();
|
||||||
|
foreach ($translation->target->attributes() as $key => $value) {
|
||||||
|
$metadata['target-attributes'][$key] = (string) $value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$catalogue->setMetadata((string) $source, $metadata, $domain);
|
$catalogue->setMetadata((string) $source, $metadata, $domain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
|
|
||||||
$catalogue->addResource(new FileResource($resource));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $catalogue;
|
/**
|
||||||
|
* @param \DOMDocument $dom
|
||||||
|
* @param MessageCatalogue $catalogue
|
||||||
|
* @param string $domain
|
||||||
|
*/
|
||||||
|
private function extractXliff2(\DOMDocument $dom, MessageCatalogue $catalogue, $domain)
|
||||||
|
{
|
||||||
|
$xml = simplexml_import_dom($dom);
|
||||||
|
$encoding = strtoupper($dom->encoding);
|
||||||
|
|
||||||
|
$xml->registerXPathNamespace('xliff', 'urn:oasis:names:tc:xliff:document:2.0');
|
||||||
|
|
||||||
|
foreach ($xml->xpath('//xliff:unit/xliff:segment') as $segment) {
|
||||||
|
$source = $segment->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($segment->target) ? $segment->target : $source), $encoding);
|
||||||
|
|
||||||
|
$catalogue->set((string) $source, $target, $domain);
|
||||||
|
|
||||||
|
$metadata = array();
|
||||||
|
if (isset($segment->target) && $segment->target->attributes()) {
|
||||||
|
$metadata['target-attributes'] = array();
|
||||||
|
foreach ($segment->target->attributes() as $key => $value) {
|
||||||
|
$metadata['target-attributes'][$key] = (string) $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$catalogue->setMetadata((string) $source, $metadata, $domain);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -103,42 +172,17 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates and parses the given file into a SimpleXMLElement.
|
|
||||||
*
|
|
||||||
* @param string $file
|
* @param string $file
|
||||||
*
|
* @param \DOMDocument $dom
|
||||||
* @throws \RuntimeException
|
* @param string $schema source of the schema
|
||||||
*
|
|
||||||
* @return \SimpleXMLElement
|
|
||||||
*
|
*
|
||||||
* @throws InvalidResourceException
|
* @throws InvalidResourceException
|
||||||
*/
|
*/
|
||||||
private function parseFile($file)
|
private function validateSchema($file, \DOMDocument $dom, $schema)
|
||||||
{
|
{
|
||||||
try {
|
|
||||||
$dom = XmlUtils::loadFile($file);
|
|
||||||
} catch (\InvalidArgumentException $e) {
|
|
||||||
throw new InvalidResourceException(sprintf('Unable to load "%s": %s', $file, $e->getMessage()), $e->getCode(), $e);
|
|
||||||
}
|
|
||||||
|
|
||||||
$internalErrors = libxml_use_internal_errors(true);
|
$internalErrors = libxml_use_internal_errors(true);
|
||||||
|
|
||||||
$location = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
|
if (!@$dom->schemaValidateSource($schema)) {
|
||||||
$parts = explode('/', $location);
|
|
||||||
if (0 === stripos($location, 'phar://')) {
|
|
||||||
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
|
|
||||||
if ($tmpfile) {
|
|
||||||
copy($location, $tmpfile);
|
|
||||||
$parts = explode('/', str_replace('\\', '/', $tmpfile));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
|
|
||||||
$location = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
|
|
||||||
|
|
||||||
$source = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
|
|
||||||
$source = str_replace('http://www.w3.org/2001/xml.xsd', $location, $source);
|
|
||||||
|
|
||||||
if (!@$dom->schemaValidateSource($source)) {
|
|
||||||
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors))));
|
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors))));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,8 +190,46 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
|
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
libxml_use_internal_errors($internalErrors);
|
libxml_use_internal_errors($internalErrors);
|
||||||
|
}
|
||||||
|
|
||||||
return array(simplexml_import_dom($dom), strtoupper($dom->encoding));
|
private function getSchema($xliffVersion)
|
||||||
|
{
|
||||||
|
if ('1.2' === $xliffVersion) {
|
||||||
|
$schemaSource = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-1.2-strict.xsd');
|
||||||
|
$xmlUri = 'http://www.w3.org/2001/xml.xsd';
|
||||||
|
} elseif ('2.0' === $xliffVersion) {
|
||||||
|
$schemaSource = file_get_contents(__DIR__.'/schema/dic/xliff-core/xliff-core-2.0.xsd');
|
||||||
|
$xmlUri = 'informativeCopiesOf3rdPartySchemas/w3c/xml.xsd';
|
||||||
|
} else {
|
||||||
|
throw new \InvalidArgumentException(sprintf('No support implemented for loading XLIFF version "%s".', $xliffVersion));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->fixXmlLocation($schemaSource, $xmlUri);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Internally changes the URI of a dependent xsd to be loaded locally.
|
||||||
|
*
|
||||||
|
* @param string $schemaSource Current content of schema file
|
||||||
|
* @param string $xmlUri External URI of XML to convert to local
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function fixXmlLocation($schemaSource, $xmlUri)
|
||||||
|
{
|
||||||
|
$newPath = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
|
||||||
|
$parts = explode('/', $newPath);
|
||||||
|
if (0 === stripos($newPath, 'phar://')) {
|
||||||
|
$tmpfile = tempnam(sys_get_temp_dir(), 'sf2');
|
||||||
|
if ($tmpfile) {
|
||||||
|
copy($newPath, $tmpfile);
|
||||||
|
$parts = explode('/', str_replace('\\', '/', $tmpfile));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$drive = '\\' === DIRECTORY_SEPARATOR ? array_shift($parts).'/' : '';
|
||||||
|
$newPath = 'file:///'.$drive.implode('/', array_map('rawurlencode', $parts));
|
||||||
|
|
||||||
|
return str_replace($xmlUri, $newPath, $schemaSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -178,6 +260,39 @@ class XliffFileLoader implements LoaderInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Gets xliff file version based on the root "version" attribute.
|
||||||
|
* Defaults to 1.2 for backwards compatibility.
|
||||||
|
*
|
||||||
|
* @param \DOMDocument $dom
|
||||||
|
*
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
private function getVersionNumber(\DOMDocument $dom)
|
||||||
|
{
|
||||||
|
/** @var \DOMNode $xliff */
|
||||||
|
foreach ($dom->getElementsByTagName('xliff') as $xliff) {
|
||||||
|
$version = $xliff->attributes->getNamedItem('version');
|
||||||
|
if ($version) {
|
||||||
|
return $version->nodeValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$namespace = $xliff->attributes->getNamedItem('xmlns');
|
||||||
|
if ($namespace) {
|
||||||
|
if (substr_compare('urn:oasis:names:tc:xliff:document:', $namespace->nodeValue, 0, 34) !== 0) {
|
||||||
|
throw new \InvalidArgumentException(sprintf('Not a valid XLIFF namespace "%s"', $namespace));
|
||||||
|
}
|
||||||
|
|
||||||
|
return substr($namespace, 34);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Falls back to v1.2
|
||||||
|
return '1.2';
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
* @param \SimpleXMLElement|null $noteElement
|
* @param \SimpleXMLElement|null $noteElement
|
||||||
* @param string|null $encoding
|
* @param string|null $encoding
|
||||||
*
|
*
|
||||||
|
@ -0,0 +1,411 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
XLIFF Version 2.0
|
||||||
|
OASIS Standard
|
||||||
|
05 August 2014
|
||||||
|
Copyright (c) OASIS Open 2014. All rights reserved.
|
||||||
|
Source: http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/schemas/
|
||||||
|
-->
|
||||||
|
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
|
||||||
|
elementFormDefault="qualified"
|
||||||
|
xmlns:xlf="urn:oasis:names:tc:xliff:document:2.0"
|
||||||
|
targetNamespace="urn:oasis:names:tc:xliff:document:2.0">
|
||||||
|
|
||||||
|
<!-- Import -->
|
||||||
|
|
||||||
|
<xs:import namespace="http://www.w3.org/XML/1998/namespace"
|
||||||
|
schemaLocation="informativeCopiesOf3rdPartySchemas/w3c/xml.xsd"/>
|
||||||
|
|
||||||
|
<!-- Element Group -->
|
||||||
|
|
||||||
|
<xs:group name="inline">
|
||||||
|
<xs:choice>
|
||||||
|
<xs:element ref="xlf:cp"/>
|
||||||
|
<xs:element ref="xlf:ph"/>
|
||||||
|
<xs:element ref="xlf:pc"/>
|
||||||
|
<xs:element ref="xlf:sc"/>
|
||||||
|
<xs:element ref="xlf:ec"/>
|
||||||
|
<xs:element ref="xlf:mrk"/>
|
||||||
|
<xs:element ref="xlf:sm"/>
|
||||||
|
<xs:element ref="xlf:em"/>
|
||||||
|
</xs:choice>
|
||||||
|
</xs:group>
|
||||||
|
|
||||||
|
<!-- Attribute Types -->
|
||||||
|
|
||||||
|
<xs:simpleType name="yesNo">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="yes"/>
|
||||||
|
<xs:enumeration value="no"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="yesNoFirstNo">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="yes"/>
|
||||||
|
<xs:enumeration value="firstNo"/>
|
||||||
|
<xs:enumeration value="no"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="dirValue">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="ltr"/>
|
||||||
|
<xs:enumeration value="rtl"/>
|
||||||
|
<xs:enumeration value="auto"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="appliesTo">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="source"/>
|
||||||
|
<xs:enumeration value="target"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="userDefinedValue">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:pattern value="[^\s:]+:[^\s:]+"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="attrType_type">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="fmt"/>
|
||||||
|
<xs:enumeration value="ui"/>
|
||||||
|
<xs:enumeration value="quote"/>
|
||||||
|
<xs:enumeration value="link"/>
|
||||||
|
<xs:enumeration value="image"/>
|
||||||
|
<xs:enumeration value="other"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="typeForMrkValues">
|
||||||
|
<xs:restriction base="xs:NMTOKEN">
|
||||||
|
<xs:enumeration value="generic"/>
|
||||||
|
<xs:enumeration value="comment"/>
|
||||||
|
<xs:enumeration value="term"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="attrType_typeForMrk">
|
||||||
|
<xs:union memberTypes="xlf:typeForMrkValues xlf:userDefinedValue"/>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="priorityValue">
|
||||||
|
<xs:restriction base="xs:positiveInteger">
|
||||||
|
<xs:minInclusive value="1"/>
|
||||||
|
<xs:maxInclusive value="10"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<xs:simpleType name="stateType">
|
||||||
|
<xs:restriction base="xs:string">
|
||||||
|
<xs:enumeration value="initial"/>
|
||||||
|
<xs:enumeration value="translated"/>
|
||||||
|
<xs:enumeration value="reviewed"/>
|
||||||
|
<xs:enumeration value="final"/>
|
||||||
|
</xs:restriction>
|
||||||
|
</xs:simpleType>
|
||||||
|
|
||||||
|
<!-- Structural Elements -->
|
||||||
|
|
||||||
|
<xs:element name="xliff">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="1" maxOccurs="unbounded" ref="xlf:file"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="version" use="required"/>
|
||||||
|
<xs:attribute name="srcLang" use="required"/>
|
||||||
|
<xs:attribute name="trgLang" use="optional"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional" default="default"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="file">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:skeleton"/>
|
||||||
|
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||||
|
processContents="lax"/>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:notes"/>
|
||||||
|
<xs:choice minOccurs="1" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="xlf:unit"/>
|
||||||
|
<xs:element ref="xlf:group"/>
|
||||||
|
</xs:choice>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="original" use="optional"/>
|
||||||
|
<xs:attribute name="translate" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="srcDir" use="optional" type="xlf:dirValue" default="auto"/>
|
||||||
|
<xs:attribute name="trgDir" use="optional" type="xlf:dirValue" default="auto"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="skeleton">
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||||
|
processContents="lax"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="href" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="group">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||||
|
processContents="lax"/>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:notes"/>
|
||||||
|
<xs:choice minOccurs="0" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="xlf:unit"/>
|
||||||
|
<xs:element ref="xlf:group"/>
|
||||||
|
</xs:choice>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="name" use="optional"/>
|
||||||
|
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="srcDir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:attribute name="trgDir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:userDefinedValue"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="unit">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other"
|
||||||
|
processContents="lax"/>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:notes"/>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:originalData"/>
|
||||||
|
<xs:choice minOccurs="1" maxOccurs="unbounded">
|
||||||
|
<xs:element ref="xlf:segment"/>
|
||||||
|
<xs:element ref="xlf:ignorable"/>
|
||||||
|
</xs:choice>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="name" use="optional"/>
|
||||||
|
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="srcDir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:attribute name="trgDir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:userDefinedValue"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="segment">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="1" maxOccurs="1" ref="xlf:source"/>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:target"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="canResegment" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="state" use="optional" type="xlf:stateType" default="initial"/>
|
||||||
|
<xs:attribute name="subState" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="ignorable">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="1" maxOccurs="1" ref="xlf:source"/>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="1" ref="xlf:target"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="notes">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="1" maxOccurs="unbounded" ref="xlf:note"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="note">
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="appliesTo" use="optional" type="xlf:appliesTo"/>
|
||||||
|
<xs:attribute name="category" use="optional"/>
|
||||||
|
<xs:attribute name="priority" use="optional" type="xlf:priorityValue" default="1"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="originalData">
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="1" maxOccurs="unbounded" ref="xlf:data"/>
|
||||||
|
</xs:sequence>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="data">
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:sequence>
|
||||||
|
<xs:element minOccurs="0" maxOccurs="unbounded" ref="xlf:cp"/>
|
||||||
|
</xs:sequence>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dir" use="optional" type="xlf:dirValue" default="auto"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional" fixed="preserve"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="source">
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
<xs:attribute ref="xml:lang" use="optional"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="target">
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
<xs:attribute ref="xml:lang" use="optional"/>
|
||||||
|
<xs:attribute ref="xml:space" use="optional"/>
|
||||||
|
<xs:attribute name="order" use="optional" type="xs:positiveInteger"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<!-- Inline Elements -->
|
||||||
|
|
||||||
|
<xs:element name="cp">
|
||||||
|
<!-- Code Point -->
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:attribute name="hex" use="required" type="xs:hexBinary"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="ph">
|
||||||
|
<!-- Placeholder -->
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||||
|
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="disp" use="optional"/>
|
||||||
|
<xs:attribute name="equiv" use="optional"/>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dataRef" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="subFlows" use="optional" type="xs:NMTOKENS"/>
|
||||||
|
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="pc">
|
||||||
|
<!-- Paired Code -->
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canOverlap" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||||
|
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dispEnd" use="optional"/>
|
||||||
|
<xs:attribute name="dispStart" use="optional"/>
|
||||||
|
<xs:attribute name="equivEnd" use="optional"/>
|
||||||
|
<xs:attribute name="equivStart" use="optional"/>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dataRefEnd" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dataRefStart" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="subFlowsEnd" use="optional" type="xs:NMTOKENS"/>
|
||||||
|
<xs:attribute name="subFlowsStart" use="optional" type="xs:NMTOKENS"/>
|
||||||
|
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||||
|
<xs:attribute name="dir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="sc">
|
||||||
|
<!-- Start Code -->
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canOverlap" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||||
|
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dataRef" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:attribute name="disp" use="optional"/>
|
||||||
|
<xs:attribute name="equiv" use="optional"/>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="isolated" use="optional" type="xlf:yesNo" default="no"/>
|
||||||
|
<xs:attribute name="subFlows" use="optional" type="xs:NMTOKENS"/>
|
||||||
|
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="ec">
|
||||||
|
<!-- End Code -->
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:attribute name="canCopy" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canDelete" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canOverlap" use="optional" type="xlf:yesNo" default="yes"/>
|
||||||
|
<xs:attribute name="canReorder" use="optional" type="xlf:yesNoFirstNo" default="yes"/>
|
||||||
|
<xs:attribute name="copyOf" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dataRef" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="dir" use="optional" type="xlf:dirValue"/>
|
||||||
|
<xs:attribute name="disp" use="optional"/>
|
||||||
|
<xs:attribute name="equiv" use="optional"/>
|
||||||
|
<xs:attribute name="id" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="isolated" use="optional" type="xlf:yesNo" default="no"/>
|
||||||
|
<xs:attribute name="startRef" use="optional" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="subFlows" use="optional" type="xs:NMTOKENS"/>
|
||||||
|
<xs:attribute name="subType" use="optional" type="xlf:userDefinedValue"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:attrType_type"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="mrk">
|
||||||
|
<!-- Annotation Marker -->
|
||||||
|
<xs:complexType mixed="true">
|
||||||
|
<xs:group ref="xlf:inline" minOccurs="0" maxOccurs="unbounded"/>
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:attrType_typeForMrk"/>
|
||||||
|
<xs:attribute name="ref" use="optional" type="xs:anyURI"/>
|
||||||
|
<xs:attribute name="value" use="optional"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="sm">
|
||||||
|
<!-- Start Annotation Marker -->
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:attribute name="id" use="required" type="xs:NMTOKEN"/>
|
||||||
|
<xs:attribute name="translate" use="optional" type="xlf:yesNo"/>
|
||||||
|
<xs:attribute name="type" use="optional" type="xlf:attrType_typeForMrk"/>
|
||||||
|
<xs:attribute name="ref" use="optional" type="xs:anyURI"/>
|
||||||
|
<xs:attribute name="value" use="optional"/>
|
||||||
|
<xs:anyAttribute namespace="##other" processContents="lax"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
<xs:element name="em">
|
||||||
|
<!-- End Annotation Marker -->
|
||||||
|
<xs:complexType mixed="false">
|
||||||
|
<xs:attribute name="startRef" use="required" type="xs:NMTOKEN"/>
|
||||||
|
</xs:complexType>
|
||||||
|
</xs:element>
|
||||||
|
|
||||||
|
</xs:schema>
|
@ -45,6 +45,27 @@ class XliffFileDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
unlink($this->tempDir.'/messages.en_US.xlf');
|
unlink($this->tempDir.'/messages.en_US.xlf');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDumpXliff2()
|
||||||
|
{
|
||||||
|
$catalogue = new MessageCatalogue('en_US');
|
||||||
|
$catalogue->add(array(
|
||||||
|
'foo' => 'bar',
|
||||||
|
'key' => '',
|
||||||
|
'key.with.cdata' => '<source> & <target>',
|
||||||
|
));
|
||||||
|
$catalogue->setMetadata('key', array('target-attributes' => array('order' => 1)));
|
||||||
|
|
||||||
|
$dumper = new XliffFileDumper();
|
||||||
|
$dumper->dump($catalogue, array('path' => $this->tempDir, 'default_locale' => 'fr_FR', 'xliff_version' => '2.0'));
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
file_get_contents(__DIR__.'/../fixtures/resources-2.0-clean.xlf'),
|
||||||
|
file_get_contents($this->tempDir.'/messages.en_US.xlf')
|
||||||
|
);
|
||||||
|
|
||||||
|
unlink($this->tempDir.'/messages.en_US.xlf');
|
||||||
|
}
|
||||||
|
|
||||||
public function testDumpWithCustomToolInfo()
|
public function testDumpWithCustomToolInfo()
|
||||||
{
|
{
|
||||||
$options = array(
|
$options = array(
|
||||||
|
@ -149,4 +149,22 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
// message with empty target
|
// message with empty target
|
||||||
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1'));
|
$this->assertEquals(array('notes' => array(array('content' => 'baz'), array('priority' => 2, 'from' => 'bar', 'content' => 'qux'))), $catalogue->getMetadata('key', 'domain1'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLoadVersion2()
|
||||||
|
{
|
||||||
|
$loader = new XliffFileLoader();
|
||||||
|
$resource = __DIR__.'/../fixtures/resources-2.0.xlf';
|
||||||
|
$catalogue = $loader->load($resource, 'en', 'domain1');
|
||||||
|
|
||||||
|
$this->assertEquals('en', $catalogue->getLocale());
|
||||||
|
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
|
||||||
|
$this->assertSame(array(), libxml_get_errors());
|
||||||
|
|
||||||
|
$domains = $catalogue->all();
|
||||||
|
$this->assertCount(3, $domains['domain1']);
|
||||||
|
$this->assertContainsOnly('string', $catalogue->all('domain1'));
|
||||||
|
|
||||||
|
// target attributes
|
||||||
|
$this->assertEquals(array('target-attributes' => array('order' => 1)), $catalogue->getMetadata('bar', 'domain1'));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
23
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf
vendored
Normal file
23
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0-clean.xlf
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="fr-FR" trgLang="en-US">
|
||||||
|
<file id="messages.en_US">
|
||||||
|
<unit id="acbd18db4cc2f85cedef654fccc4a4d8">
|
||||||
|
<segment>
|
||||||
|
<source>foo</source>
|
||||||
|
<target>bar</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="3c6e0b8a9c15224a8228b9a98ca1531d">
|
||||||
|
<segment>
|
||||||
|
<source>key</source>
|
||||||
|
<target order="1"></target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="18e6a493872558d949b4c16ea1fa6ab6">
|
||||||
|
<segment>
|
||||||
|
<source>key.with.cdata</source>
|
||||||
|
<target><![CDATA[<source> & <target>]]></target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
25
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0.xlf
vendored
Normal file
25
src/Symfony/Component/Translation/Tests/fixtures/resources-2.0.xlf
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<xliff xmlns="urn:oasis:names:tc:xliff:document:2.0" version="2.0" srcLang="en-US" trgLang="ja-JP">
|
||||||
|
<file id="f1" original="Graphic Example.psd">
|
||||||
|
<skeleton href="Graphic Example.psd.skl"/>
|
||||||
|
<unit id="1">
|
||||||
|
<segment>
|
||||||
|
<source>Quetzal</source>
|
||||||
|
<target>Quetzal</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<group id="1">
|
||||||
|
<unit id="2">
|
||||||
|
<segment>
|
||||||
|
<source>foo</source>
|
||||||
|
<target>XLIFF 文書を編集、または処理 するアプリケーションです。</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
<unit id="3">
|
||||||
|
<segment>
|
||||||
|
<source>bar</source>
|
||||||
|
<target order="1">XLIFF データ・マネージャ</target>
|
||||||
|
</segment>
|
||||||
|
</unit>
|
||||||
|
</group>
|
||||||
|
</file>
|
||||||
|
</xliff>
|
Reference in New Issue
Block a user