[Translation][Loader] added XLIFF 2.0 support.
This commit is contained in:
parent
0edcc2ef10
commit
ff5d6a3a98
@ -41,10 +41,49 @@ class XliffFileLoader implements LoaderInterface
|
||||
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);
|
||||
$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, $dom));
|
||||
|
||||
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) {
|
||||
$attributes = $translation->attributes();
|
||||
|
||||
@ -69,12 +108,29 @@ class XliffFileLoader implements LoaderInterface
|
||||
|
||||
$catalogue->setMetadata((string) $source, $metadata, $domain);
|
||||
}
|
||||
}
|
||||
|
||||
if (class_exists('Symfony\Component\Config\Resource\FileResource')) {
|
||||
$catalogue->addResource(new FileResource($resource));
|
||||
/**
|
||||
* @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($translation->target) ? $translation->target : $source), $encoding);
|
||||
|
||||
$catalogue->set((string) $source, $target, $domain);
|
||||
}
|
||||
|
||||
return $catalogue;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -103,42 +159,16 @@ class XliffFileLoader implements LoaderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates and parses the given file into a SimpleXMLElement.
|
||||
*
|
||||
* @param string $file
|
||||
*
|
||||
* @throws \RuntimeException
|
||||
*
|
||||
* @return \SimpleXMLElement
|
||||
* @param \DOMDocument $dom
|
||||
* @param string $schema source of the schema
|
||||
*
|
||||
* @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);
|
||||
|
||||
$location = str_replace('\\', '/', __DIR__).'/schema/dic/xliff-core/xml.xsd';
|
||||
$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)) {
|
||||
if (!@$dom->schemaValidateSource($schema)) {
|
||||
throw new InvalidResourceException(sprintf('Invalid resource provided: "%s"; Errors: %s', $file, implode("\n", $this->getXmlErrors($internalErrors))));
|
||||
}
|
||||
|
||||
@ -146,8 +176,49 @@ class XliffFileLoader implements LoaderInterface
|
||||
|
||||
libxml_clear_errors();
|
||||
libxml_use_internal_errors($internalErrors);
|
||||
}
|
||||
|
||||
return array(simplexml_import_dom($dom), strtoupper($dom->encoding));
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getSchema($xliffVersion, $dom)
|
||||
{
|
||||
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 +249,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 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>
|
@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Translation\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Translation\Loader\XliffFileLoader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Translation\Loader\XliffFileLoader;
|
||||
|
||||
class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
@ -149,4 +149,21 @@ class XliffFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
// message with empty target
|
||||
$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']);
|
||||
|
||||
// Notes aren't assigned to specific segments, but to whole units, so there's no way to do a mapping
|
||||
$this->assertEmpty($catalogue->getMetadata());
|
||||
}
|
||||
}
|
||||
|
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>An application to manipulate and process XLIFF documents</source>
|
||||
<target>XLIFF 文書を編集、または処理 するアプリケーションです。</target>
|
||||
</segment>
|
||||
</unit>
|
||||
<unit id="3">
|
||||
<segment>
|
||||
<source>XLIFF Data Manager</source>
|
||||
<target>XLIFF データ・マネージャ</target>
|
||||
</segment>
|
||||
</unit>
|
||||
</group>
|
||||
</file>
|
||||
</xliff>
|
Reference in New Issue
Block a user