public function testTakesMissedContextDescriptionFromGivenArray() { $storage = m::mock(); $storage->shouldReceive('ensurePresence')->with(equalTo(String::create('order/details:title', 'Here are the order details', 'H1 title in GUI', 'vfs://templates/order/details.html')))->once(); $storage->shouldReceive('ensurePresence'); self::crawler($storage, null, self::contextDescriptions())->collectTranslations(array(vfsStream::url('templates')), '.html'); }
public function testCanPreserveTranslationWhenStringIsBeingRegistered() { $string = String::create('validation:email', 'Email for orders'); $storage = self::storage(); $storage->ensurePresence($string); $translations = $storage->mappedTranslations('validation'); $this->assertEquals('Email', $translations['validation:email']); }
public function testIteratesOverAllStringsRegisteringThem() { $storage = m::mock(); $storage->shouldReceive('setTranslationValue')->with(equalTo(String::create('yes', 'Yes')))->once(); $storage->shouldReceive('setTranslationValue')->with(equalTo(String::create('validator:notEmpty', 'Should be not empty', 'Validation error messages')))->once(); $process = new Process($storage); $process->run(array('yes' => array('Yes'), 'validator:notEmpty' => array('Should be not empty', 'Validation error messages'))); }
protected static function fillInStorage() { self::storage()->setTranslationValue(String::create('validation:email', 'Email')); self::storage()->setTranslationValue(String::create('validation/error:notEmpty', 'Should be not empty')); self::storage()->setTranslationValue(String::create('validation/error:emailFormat', 'Email format is incorrect')); self::storage()->setTranslationValue(String::create('pager:pageXFromY', 'Page %d from $d')); self::storage()->setTranslationValue(String::create('pager:totalAmountOfPages', 'Total %d page(s)')); self::storage()->setTranslationValue(String::create('yes', 'Yes')); }
public function run($source) { $count = 0; foreach ($source as $keyWithNamespace => $info) { list($translation, $description) = array_merge($info, array(null, null)); $this->storage->setTranslationValue(String::create($keyWithNamespace, $translation, $description)); $count++; } return $count; }
/** * @param \Translator\String $string * @return void */ public function setTranslationValue($string) { if (!array_key_exists($string->ns(), $this->translations)) { $this->translations[$string->ns()] = array(); } $this->translations[$string->ns()][$string->key()] = strval($string); }
public function testBulkUpdateWorks() { $string = String::create('one', 'One'); self::storage()->setTranslationValue($string); $bulkStorage = self::bulkStorage(); $bulkStorage->ensurePresence(String::create('one', 'One')); $bulkStorage->ensurePresence(String::create('two', 'Two')); $bulkStorage->commit(); $docs = $this->allButDesignDocument(); $this->assertCount(2, $docs); $this->assertSame('one', $docs[0]['doc']['key']); $this->assertStringStartsWith('2-', $docs[0]['doc']['_rev'], 'second revision'); }
/** * @param $strings * @return array */ private function loadExisting($strings) { $query = $this->db->createViewQuery('main', 'find'); $query->setKeys(array_map(function ($string) { return $string->hash(); }, $strings)); $existingStrings = array(); foreach ($query->execute() as $record) { $doc = $record['value']; $string = String::create(($doc['namespace'] ? join('/', $doc['namespace']) . ':' : '') . $doc['key'], $doc['translation'], array_key_exists('description', $doc) ? $doc['description'] : null, array_key_exists('source', $doc) ? $doc['source'] : null); $existingStrings[$string->hash()] = $doc; } return $existingStrings; }
public function decorate($keyWithNamespace, $translation) { $hash = String::create($keyWithNamespace, $translation)->hash(); return "‘{$hash}’{$translation}’"; }
/** * @param array $translations * @param array $contextDescriptions * @param $path */ private function registerAllTranslations(array $translations, array $contextDescriptions, $path) { foreach ($this->translateFinder->select($path) as $keyWithNamespace => $parameters) { $this->storage->ensurePresence(String::find($keyWithNamespace, $path, $translations, $contextDescriptions)); } }
private static function defaultTranslation($key) { return strval(String::create($key, null)); }
private static function noString() { return String::create('no', 'Nein'); }