Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge branch '2.2'

* 2.2: (70 commits)
  change wrapped exception message to be more usefull
  updated VERSION for 2.0.23
  update CONTRIBUTORS for 2.0.23
  updated CHANGELOG for 2.0.23
  [Form] fixed failing test
  [DomCrawler] added support for query string with slash
  Fixed invalid file path for hiddeninput.exe on Windows.
  fix xsd definition for strict-requirements
  [WebProfilerBundle] Fixed the toolbar styles to apply them in IE8
  [ClassLoader] fixed heredocs handling
  fixed handling of heredocs
  Add a public modifier to an interface method
  removing xdebug extension
  [HttpRequest] fixes Request::getLanguages() bug
  [HttpCache] added a test (cached content should be kept after purging)
  [DoctrineBridge] Fixed non-utf-8 recognition
  [Security] fixed HttpUtils class tests
  replaced new occurences of 'Request::create()' with '::create()'
  changed sub-requests creation to '::create()'
  fixed merge issue
  ...

Conflicts:
	src/Symfony/Bundle/FrameworkBundle/Command/TranslationUpdateCommand.php
	src/Symfony/Bundle/WebProfilerBundle/Resources/views/Profiler/toolbar.html.twig
	src/Symfony/Component/DomCrawler/Link.php
	src/Symfony/Component/Translation/Translator.php
  • Loading branch information...
commit c139710df2a915a19dbc43f63b55da5538fc5109 2 parents 6388040 + cdbeaa8
@fabpot fabpot authored
View
20 Dumper/XliffFileDumper.php
@@ -27,24 +27,30 @@ protected function format(MessageCatalogue $messages, $domain)
{
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->formatOutput = true;
+
$xliff = $dom->appendChild($dom->createElement('xliff'));
$xliff->setAttribute('version', '1.2');
$xliff->setAttribute('xmlns', 'urn:oasis:names:tc:xliff:document:1.2');
+
$xliffFile = $xliff->appendChild($dom->createElement('file'));
$xliffFile->setAttribute('source-language', $messages->getLocale());
$xliffFile->setAttribute('datatype', 'plaintext');
$xliffFile->setAttribute('original', 'file.ext');
+
$xliffBody = $xliffFile->appendChild($dom->createElement('body'));
- $id = 1;
foreach ($messages->all($domain) as $source => $target) {
- $trans = $dom->createElement('trans-unit');
- $trans->setAttribute('id', $id);
- $s = $trans->appendChild($dom->createElement('source'));
+ $translation = $dom->createElement('trans-unit');
+
+ $translation->setAttribute('id', md5($source));
+ $translation->setAttribute('resname', $source);
+
+ $s = $translation->appendChild($dom->createElement('source'));
$s->appendChild($dom->createTextNode($source));
- $t = $trans->appendChild($dom->createElement('target'));
+
+ $t = $translation->appendChild($dom->createElement('target'));
$t->appendChild($dom->createTextNode($target));
- $xliffBody->appendChild($trans);
- $id++;
+
+ $xliffBody->appendChild($translation);
}
return $dom->saveXML();
View
4 IdentityTranslator.php
@@ -59,7 +59,7 @@ public function getLocale()
*/
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
{
- return strtr($id, $parameters);
+ return strtr((string) $id, $parameters);
}
/**
@@ -69,6 +69,6 @@ public function trans($id, array $parameters = array(), $domain = 'messages', $l
*/
public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{
- return strtr($this->selector->choose($id, (int) $number, $locale), $parameters);
+ return strtr($this->selector->choose((string) $id, (int) $number, $locale), $parameters);
}
}
View
10 Loader/XliffFileLoader.php
@@ -45,10 +45,14 @@ public function load($resource, $locale, $domain = 'messages')
$catalogue = new MessageCatalogue($locale);
foreach ($xml->xpath('//xliff:trans-unit') as $translation) {
- if (!isset($translation->source) || !isset($translation->target)) {
+ $attributes = $translation->attributes();
+
+ if (!(isset($attributes['resname']) || isset($translation->source)) || !isset($translation->target)) {
continue;
}
- $catalogue->set((string) $translation->source, (string) $translation->target, $domain);
+
+ $source = isset($attributes['resname']) && $attributes['resname'] ? $attributes['resname'] : $translation->source;
+ $catalogue->set((string) $source, (string) $translation->target, $domain);
}
$catalogue->addResource(new FileResource($resource));
@@ -60,6 +64,8 @@ public function load($resource, $locale, $domain = 'messages')
*
* @param string $file
*
+ * @throws \RuntimeException
+ *
* @return \SimpleXMLElement
*
* @throws InvalidResourceException
View
41 MessageCatalogue.php
@@ -24,8 +24,8 @@ class MessageCatalogue implements MessageCatalogueInterface, MetadataAwareInterf
{
private $messages = array();
private $metadata = array();
+ private $resources = array();
private $locale;
- private $resources;
private $fallbackCatalogue;
private $parent;
@@ -41,7 +41,6 @@ public function __construct($locale, array $messages = array())
{
$this->locale = $locale;
$this->messages = $messages;
- $this->resources = array();
}
/**
@@ -177,8 +176,10 @@ public function addCatalogue(MessageCatalogueInterface $catalogue)
$this->addResource($resource);
}
- $metadata = $catalogue->getMetadata('', '');
- $this->addMetadata($metadata);
+ if ($catalogue instanceof MetadataAwareInterface) {
+ $metadata = $catalogue->getMetadata('', '');
+ $this->addMetadata($metadata);
+ }
}
/**
@@ -205,9 +206,7 @@ public function addFallbackCatalogue(MessageCatalogueInterface $catalogue)
}
/**
- * Gets the fallback catalogue.
- *
- * @return MessageCatalogueInterface A MessageCatalogueInterface instance
+ * {@inheritdoc}
*
* @api
*/
@@ -223,7 +222,7 @@ public function getFallbackCatalogue()
*/
public function getResources()
{
- return array_values(array_unique($this->resources));
+ return array_values($this->resources);
}
/**
@@ -233,7 +232,7 @@ public function getResources()
*/
public function addResource(ResourceInterface $resource)
{
- $this->resources[] = $resource;
+ $this->resources[$resource->__toString()] = $resource;
}
/**
@@ -241,19 +240,21 @@ public function addResource(ResourceInterface $resource)
*/
public function getMetadata($key = '', $domain = 'messages')
{
- if (empty($domain)) {
+ if ('' == $domain) {
return $this->metadata;
}
if (isset($this->metadata[$domain])) {
- if (!empty($key)) {
- if (isset($this->metadata[$domain][$key])) {
- return $this->metadata[$domain][$key];
- }
- } else {
+ if ('' == $key) {
return $this->metadata[$domain];
}
+
+ if (isset($this->metadata[$domain][$key])) {
+ return $this->metadata[$domain][$key];
+ }
}
+
+ return null;
}
/**
@@ -269,15 +270,13 @@ public function setMetadata($key, $value, $domain = 'messages')
*/
public function deleteMetadata($key = '', $domain = 'messages')
{
- if (empty($domain)) {
+ if ('' == $domain) {
$this->metadata = array();
- }
-
- if (empty($key)) {
+ } elseif ('' == $key) {
unset($this->metadata[$domain]);
+ } else {
+ unset($this->metadata[$domain][$key]);
}
-
- unset($this->metadata[$domain][$key]);
}
/**
View
6 MessageCatalogueInterface.php
@@ -103,7 +103,7 @@ public function get($id, $domain = 'messages');
/**
* Sets translations for a given domain.
*
- * @param string $messages An array of translations
+ * @param array $messages An array of translations
* @param string $domain The domain name
*
* @api
@@ -113,7 +113,7 @@ public function replace($messages, $domain = 'messages');
/**
* Adds translations for a given domain.
*
- * @param string $messages An array of translations
+ * @param array $messages An array of translations
* @param string $domain The domain name
*
* @api
@@ -146,7 +146,7 @@ public function addFallbackCatalogue(MessageCatalogueInterface $catalogue);
/**
* Gets the fallback catalogue.
*
- * @return MessageCatalogueInterface A MessageCatalogueInterface instance
+ * @return MessageCatalogueInterface|null A MessageCatalogueInterface instance or null when no fallback has been set
*
* @api
*/
View
25 MetadataAwareInterface.php
@@ -19,27 +19,36 @@
interface MetadataAwareInterface
{
/**
- * Gets meta data for given domain and key.
+ * Gets metadata for the given domain and key.
+ *
+ * Passing an empty domain will return an array with all metadata indexed by
+ * domain and then by key. Passing an empty key will return an array with all
+ * metadata for the given domain.
*
* @param string $domain The domain name
- * @param string $key Key
+ * @param string $key The key
+ *
+ * @return mixed The value that was set or an array with the domains/keys or null
*/
public function getMetadata($key = '', $domain = 'messages');
/**
- * Adds meta data to a message domain.
+ * Adds metadata to a message domain.
*
- * @param string $key Key
- * @param string|array $value Value
- * @param string $domain The domain name
+ * @param string $key The key
+ * @param mixed $value The value
+ * @param string $domain The domain name
*/
public function setMetadata($key, $value, $domain = 'messages');
/**
- * Deletes meta data for given key and domain.
+ * Deletes metadata for the given key and domain.
+ *
+ * Passing an empty domain will delete all metadata. Passing an empty key will
+ * delete all metadata for the given domain.
*
* @param string $domain The domain name
- * @param string $key Key
+ * @param string $key The key
*/
public function deleteMetadata($key = '', $domain = 'messages');
}
View
8 Tests/Loader/XliffFileLoaderTest.php
@@ -33,6 +33,14 @@ public function testLoad()
$this->assertEquals(array(new FileResource($resource)), $catalogue->getResources());
}
+ public function testLoadWithResname()
+ {
+ $loader = new XliffFileLoader();
+ $catalogue = $loader->load(__DIR__.'/../fixtures/resname.xlf', 'en', 'domain1');
+
+ $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz', 'baz' => 'foo'), $catalogue->all('domain1'));
+ }
+
public function testIncompleteResource()
{
$loader = new XliffFileLoader();
View
19 Tests/fixtures/resname.xlf
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
+ <file source-language="en" datatype="plaintext" original="file.ext">
+ <body>
+ <trans-unit id="1" resname="foo">
+ <source></source>
+ <target>bar</target>
+ </trans-unit>
+ <trans-unit id="2" resname="bar">
+ <source>bar source</source>
+ <target>baz</target>
+ </trans-unit>
+ <trans-unit id="3">
+ <source>baz</source>
+ <target>foo</target>
+ </trans-unit>
+ </body>
+ </file>
+</xliff>
View
4 Tests/fixtures/resources-clean.xlf
@@ -2,11 +2,11 @@
<xliff xmlns="urn:oasis:names:tc:xliff:document:1.2" version="1.2">
<file source-language="en" datatype="plaintext" original="file.ext">
<body>
- <trans-unit id="1">
+ <trans-unit id="acbd18db4cc2f85cedef654fccc4a4d8" resname="foo">
<source>foo</source>
<target>bar</target>
</trans-unit>
- <trans-unit id="2">
+ <trans-unit id="3c6e0b8a9c15224a8228b9a98ca1531d" resname="key">
<source>key</source>
<target></target>
</trans-unit>
View
12 Translator.php
@@ -56,15 +56,15 @@ class Translator implements TranslatorInterface
/**
* Constructor.
*
- * @param string $locale The locale
- * @param MessageSelector $selector The message selector for pluralization
+ * @param string $locale The locale
+ * @param MessageSelector|null $selector The message selector for pluralization
*
* @api
*/
public function __construct($locale, MessageSelector $selector = null)
{
$this->locale = $locale;
- $this->selector = null === $selector ? new MessageSelector() : $selector;
+ $this->selector = $selector ?: new MessageSelector();
}
/**
@@ -165,7 +165,7 @@ public function getFallbackLocales()
*/
public function trans($id, array $parameters = array(), $domain = 'messages', $locale = null)
{
- if (!isset($locale)) {
+ if (null === $locale) {
$locale = $this->getLocale();
}
@@ -183,7 +183,7 @@ public function trans($id, array $parameters = array(), $domain = 'messages', $l
*/
public function transChoice($id, $number, array $parameters = array(), $domain = 'messages', $locale = null)
{
- if (!isset($locale)) {
+ if (null === $locale) {
$locale = $this->getLocale();
}
@@ -203,7 +203,7 @@ public function transChoice($id, $number, array $parameters = array(), $domain =
}
}
- return strtr($this->selector->choose($catalogue->get($id, $domain), (float) $number, $locale), $parameters);
+ return strtr($this->selector->choose($catalogue->get($id, $domain), (int) $number, $locale), $parameters);
}
protected function loadCatalogue($locale)
View
4 TranslatorInterface.php
@@ -23,7 +23,7 @@
/**
* Translates the given message.
*
- * @param string $id The message id
+ * @param string $id The message id (may also be an object that can be cast to string)
* @param array $parameters An array of parameters for the message
* @param string $domain The domain for the message
* @param string $locale The locale
@@ -37,7 +37,7 @@ public function trans($id, array $parameters = array(), $domain = null, $locale
/**
* Translates the given choice message by choosing a translation according to a number.
*
- * @param string $id The message id
+ * @param string $id The message id (may also be an object that can be cast to string)
* @param integer $number The number to use to find the indice of the message
* @param array $parameters An array of parameters for the message
* @param string $domain The domain for the message
Please sign in to comment.
Something went wrong with that request. Please try again.