Пример #1
0
 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);
         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;
             $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;
             $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);
     do_action('gp_translations_imported', $this->id);
     return $translations_added;
 }
Пример #2
0
 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);
     $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;
         }
         if (in_array('fuzzy', $entry->flags)) {
             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;
             $create = array_pad($entry->translations, $locale->nplurals, null) != $translated->translations;
         } 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);
             if ($original) {
                 $entry->original_id = $original->id;
                 $create = true;
             }
         }
         if ($create) {
             $entry->translation_set_id = $this->id;
             $entry->status = 'current';
             // check for errors
             $translation = GP::$translation->create($entry);
             $translation->set_as_current();
             $translations_added += 1;
         }
     }
     wp_cache_delete($this->id, 'translation_set_status_breakdown');
     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;
 }