/** * Delete counts cache for all translation sets of a project * * @param int $project_id project ID */ function gp_clean_translation_sets_cache($project_id) { $translation_sets = GP::$translation_set->by_project_id($project_id); if (!$translation_sets) { return; } foreach ($translation_sets as $set) { gp_clean_translation_set_cache($set->id); } }
function set_status($status) { if ('current' == $status) { $updated = $this->set_as_current(); } else { $updated = $this->save(array('status' => $status)); } if ($updated) { gp_clean_translation_set_cache($this->translation_set_id); } return $updated; }
public function set_status($status) { if ('current' == $status) { $updated = $this->set_as_current(); } else { $updated = $this->save(array('user_id_last_modified' => get_current_user_id(), 'status' => $status)); } if ($updated) { gp_clean_translation_set_cache($this->translation_set_id); } return $updated; }
function import($translations) { @ini_set('memory_limit', '256M'); if (!isset($this->project) || !$this->project) { $this->project = GP::$project->get($this->project_id); } $locale = GP_Locales::by_slug($this->locale); $user = GP::$user->current(); $current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes')); $current_translations = new Translations(); foreach ($current_translations_list as $entry) { $current_translations->add_entry($entry); } unset($current_translations_list); $translations_added = 0; foreach ($translations->entries as $entry) { if (empty($entry->translations)) { continue; } $create = false; if ($translated = $current_translations->translate_entry($entry)) { // we have the same string translated // create a new one if they don't match $entry->original_id = $translated->original_id; $translated_is_different = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations; $create = apply_filters('translation_set_import_over_existing', $translated_is_different); } else { // we don't have the string translated, let's see if the original is there $original = GP::$original->by_project_id_and_entry($this->project->id, $entry, '+active'); if ($original) { $entry->original_id = $original->id; $create = true; } } if ($create) { if ($user) { $entry->user_id = $user->id; } $entry->translation_set_id = $this->id; $entry->status = apply_filters('translation_set_import_status', in_array('fuzzy', $entry->flags) ? 'fuzzy' : 'current'); // check for errors $translation = GP::$translation->create($entry); $translation->set_status($entry->status); $translations_added += 1; } } gp_clean_translation_set_cache($this->id); do_action('translations_imported', $this->id); return $translations_added; }
public function import($translations) { $this->set_memory_limit('256M'); if (!isset($this->project) || !$this->project) { $this->project = GP::$project->get($this->project_id); } $locale = GP_Locales::by_slug($this->locale); $user = wp_get_current_user(); $current_translations_list = GP::$translation->for_translation($this->project, $this, 'no-limit', array('status' => 'current', 'translated' => 'yes')); $current_translations = new Translations(); foreach ($current_translations_list as $entry) { $current_translations->add_entry($entry); } unset($current_translations_list); $translations_added = 0; foreach ($translations->entries as $entry) { if (empty($entry->translations)) { continue; } $is_fuzzy = in_array('fuzzy', $entry->flags); /** * Filter whether to import fuzzy translations. * * @since 1.0.0 * * @param bool $import_over Import fuzzy translation. Default true. * @param Translation_Entry $entry Translation entry object to import. * @param Translations $translations Translations collection. */ if ($is_fuzzy && !apply_filters('gp_translation_set_import_fuzzy_translations', true, $entry, $translations)) { continue; } $create = false; if ($translated = $current_translations->translate_entry($entry)) { // we have the same string translated // create a new one if they don't match $entry->original_id = $translated->original_id; $translated_is_different = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations; /** * Filter whether to import over an existing translation on a translation set. * * @since 1.0.0 * * @param bool $import_over Import over an existing translation. */ $create = apply_filters('gp_translation_set_import_over_existing', $translated_is_different); } else { // we don't have the string translated, let's see if the original is there $original = GP::$original->by_project_id_and_entry($this->project->id, $entry, '+active'); if ($original) { $entry->original_id = $original->id; $create = true; } } if ($create) { if ($user) { $entry->user_id = $user->ID; } $entry->translation_set_id = $this->id; /** * Filter the the status of imported translations of a translation set. * * @since 1.0.0 * * @param string $status The status of imported translations. */ $entry->status = apply_filters('gp_translation_set_import_status', $is_fuzzy ? 'fuzzy' : 'current'); // check for errors $translation = GP::$translation->create($entry); $translation->set_status($entry->status); $translations_added += 1; } } gp_clean_translation_set_cache($this->id); /** * Fires after translations have been imported to a translation set. * * @since 1.0.0 * * @param int $translation_set The ID of the translation set the import was made into. */ do_action('gp_translations_imported', $this->id); return $translations_added; }