Skip to content

Commit

Permalink
some additional features and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Nov 19, 2011
1 parent 1b572f1 commit 4265510
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
22 changes: 18 additions & 4 deletions lib/Gedmo/Translator/TranslationProxy.php
Expand Up @@ -13,7 +13,7 @@
*/
class TranslationProxy
{
protected $locale;
private $locale;
private $translatable;
private $properties = array();
private $class;
Expand Down Expand Up @@ -96,7 +96,17 @@ public function __set($property, $value)
return $this->setTranslatedValue($property, $value);
}

$this->translatable->property = $value;
$this->translatable->$property = $value;
}

/**
* Returns locale name for the current translation proxy instance.
*
* @return string
*/
public function getProxyLocale()
{
return $this->locale;
}

/**
Expand All @@ -108,7 +118,9 @@ public function __set($property, $value)
*/
public function getTranslatedValue($property)
{
return $this->findOrCreateTranslationForProperty($property, $this->locale)->getValue();
return $this
->findOrCreateTranslationForProperty($property, $this->getProxyLocale())
->getValue();
}

/**
Expand All @@ -119,7 +131,9 @@ public function getTranslatedValue($property)
*/
public function setTranslatedValue($property, $value)
{
$this->findOrCreateTranslationForProperty($property, $this->locale)->setValue($value);
$this
->findOrCreateTranslationForProperty($property, $this->getProxyLocale())
->setValue($value);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/Gedmo/Translator/Fixture/Person.php
Expand Up @@ -21,12 +21,12 @@ class Person
/**
* @ORM\Column(name="name", type="string", length=128)
*/
private $name;
public $name;

/**
* @ORM\Column(name="desc", type="string", length=128)
*/
private $description;
public $description;

public function getId()
{
Expand Down
14 changes: 14 additions & 0 deletions tests/Gedmo/Translator/TranslatableTest.php
Expand Up @@ -86,6 +86,20 @@ public function testTranslatable()
$this->assertSame('multilingual description', $person->translate('ru_RU')->getDescription());
}

public function testTranslatableWithMagicProperties()
{
$person = new Person();
$person->setName('Jen');
$person->translate('ru_RU')->name = 'Женя';
$person->translate('ru_RU')->description = 'multilingual description';

$this->assertSame('Jen', $person->name);
$this->assertSame('Jen', $person->translate()->name);
$this->assertSame('Женя', $person->translate('ru_RU')->name);
$this->assertSame('multilingual description', $person->translate('ru_RU')->description);
$this->assertSame('multilingual description', $person->description);
}

public function testTranslatableWithCustomProxy()
{
$person = new PersonCustom();
Expand Down

0 comments on commit 4265510

Please sign in to comment.