public function testExportOfEmptyLocale()
 {
     $unit1 = new Unit('messages', 'locale');
     $unit1->setTranslation('fr', null);
     $zip = $this->getZipFromUnit(array($unit1));
     $this->assertEquals(array(), $zip->getFileList());
 }
 /**
  * Create a ModelUnit representation of a this object
  *
  * @return ModelUnit
  */
 public function convertToModel()
 {
     $unit = new \Liip\TranslationBundle\Model\Unit($this->getDomain(), $this->getKey(), $this->getMetadata());
     foreach ($this->getTranslations() as $translation) {
         $unit->setTranslation($translation->getLocale(), $translation->getValue());
     }
     return $unit;
 }
 /**
  * Update the current object from a ModelUnit
  *
  * @param ModelUnit $unit
  */
 public function updateFromModel(ModelUnit $unit)
 {
     $this->setDomain($unit->getDomain());
     $this->setKey($unit->getKey());
     $this->setMetadata($unit->getMetadata());
 }
 protected function createUnitObject($domain, $key, $metadata, $translations)
 {
     $unit = new Unit($domain, $key, $metadata, false);
     if (isset($translations[$domain][$key])) {
         foreach ($translations[$domain][$key] as $locale => $data) {
             list($value, $metadata) = $data;
             $unit->addTranslation(new Translation($value, $locale, $unit, $metadata), false);
         }
     }
     return $unit;
 }
 /**
  * @dataProvider getUnit
  */
 public function testEmptyTranslation(Unit $unit)
 {
     $unit->setTranslation(self::LOCALE1, '');
     $this->assertTrue($unit->hasTranslation(self::LOCALE1));
     $this->assertTrue(isset($unit[self::LOCALE1]));
     $this->assertEquals('', $unit->getTranslation(self::LOCALE1));
     $count = 0;
     foreach ($unit->getTranslations() as $t) {
         ++$count;
     }
     $this->assertEquals(1, $count);
 }
 public function testFindTranslation()
 {
     $u = new Unit('domain', 'key', array());
     $u->setTranslation('en', 'some translation');
     $u->setTranslation('fr', 'une traduction');
     $repo = $this->getRepository(array($u));
     $this->assertEquals('some translation', $repo->findTranslation('domain', 'key', 'en')->getValue());
     $this->assertEquals('une traduction', $repo->findTranslation('domain', 'key', 'fr')->getValue());
     $this->assertNull($repo->findTranslation('domain', 'key', 'non-existing locale'));
 }
 protected function createZip()
 {
     // Then we create the zip
     $unit1 = new Unit('functional', 'key1');
     $unit1->setTranslation('en', 'value1');
     $unit1->setTranslation('fr', 'value_fr');
     $unit2 = new Unit('functional', 'key2');
     $unit2->setTranslation('en', 'new_value2');
     $unit2->setTranslation('fr', 'value2_fr');
     $unit3 = new Unit('functional', 'compound.translation2');
     $unit3->setTranslation('en', 'compound 2 en');
     $unit3->setTranslation('fr', 'compound 2 fr');
     $unit4 = new Unit('functional', 'compound.translation1');
     $unit4->setTranslation('en', 'new compound 2 en');
     $exporter = new ZipExporter();
     $exporter->setUnits(array($unit1, $unit2, $unit3, $unit4));
     return new UploadedFile($exporter->createZipFile(sys_get_temp_dir() . '/trans.zip'), 'trans.zip');
 }
 public function deleteUnit(Unit $unit)
 {
     UnitQuery::create()->findOneByDomainAndKey($unit->getDomain(), $unit->getKey())->delete();
 }