function clean_up_global_scope() { parent::clean_up_global_scope(); $locales =& GP_Locales::instance(); $locales->locales = array(); $_GET = array(); $_POST = array(); /** * @todo re-initialize all thing objects */ GP::$translation_set = new GP_Translation_Set(); GP::$original = new GP_Original(); }
function clean_up_global_scope() { GP::$user->reintialize_wp_users_object(); $locales =& GP_Locales::instance(); $locales->locales = array(); $_GET = array(); $_POST = array(); $this->flush_cache(); /** * @todo re-initialize all thing objects */ GP::$translation_set = new GP_Translation_Set(); GP::$original = new GP_Original(); }
function test_read_translations() { $stubbed_originals = array(); foreach ($this->entries as $sample) { list($context, $original, $translation) = $sample; $stubbed_originals[] = new GP_Original(array('singular' => $original, 'context' => $context)); } GP::$original = $this->getMock('GP_Original', array('by_project_id')); GP::$original->expects($this->once())->method('by_project_id')->with($this->equalTo(2))->will($this->returnValue($stubbed_originals)); $translations = $this->properties->read_translations_from_file(GP_DIR_TESTDATA . '/translation.properties', (object) array('id' => 2)); foreach ($this->entries as $sample) { list($context, $original, $translation) = $sample; $this->assertEquals($translation, $translations->translate($original, $context)); } }
$sql_project = $gpdb->prepare('o.project_id != %d', $this->project_id); $sql_singular = $gpdb->prepare('o.singular = BINARY %s', $this->singular); $sql_plural = is_null($this->plural) ? 'o.plural IS NULL' : $gpdb->prepare('o.plural = BINARY %s', $this->plural); $sql_context = is_null($this->context) ? 'o.context IS NULL' : $gpdb->prepare('o.context = BINARY %s', $this->context); $sql = "SELECT t.*, s.locale, s.slug\n\t\t\tFROM {$this->table} o\n\t\t\t\tJOIN {$gpdb->translations} t ON o.id = t.original_id\n\t\t\t\tJOIN {$gpdb->translation_sets} s ON t.translation_set_id = s.id\n\t\t\tWHERE\n\t\t\t\t{$sql_context} AND {$sql_singular} AND {$sql_plural}\n\t\t\t\tAND o.status = '+active' AND {$sql_project}\n\t\t\t\tAND t.status = 'current'\n\t\t\tGROUP BY t.translation_0, t.translation_1, t.translation_2, t.translation_3, t.translation_4, t.translation_5, s.locale, s.slug\n\t\t\tORDER BY t.date_modified DESC, t.id DESC"; $other_project_translations = GP::$translation->many($sql); foreach ($other_project_translations as $t) { $o_translation_set = array_filter($project_translations_sets, function ($set) use($t) { return $set->locale == $t->locale && $set->slug == $t->slug; }); if (empty($o_translation_set)) { continue; } $o_translation_set = reset($o_translation_set); if (in_array($o_translation_set->id, $matched_sets)) { // We already have a translation for this set. continue; } $matched_sets[] = $o_translation_set->id; $copy_status = apply_filters('translations_from_other_projects_status', 'current'); $t->copy_into_set($o_translation_set->id, $this->id, $copy_status); } } function after_create() { do_action('original_created', $this); return true; } } GP::$original = new GP_Original();