Esempio n. 1
0
 function assertThereIsAnArrayElementContaining($text, $array, $message = null)
 {
     $this->assertGreaterThan(0, count($array), 'The array is empty.');
     $message = $message ? $message : "No array element contains '{$text}'";
     $this->assertTrue(gp_array_any(function ($e) use($text) {
         return gp_in($text, $e);
     }, $array), $message);
 }
Esempio n. 2
0
 public function warning_length($original, $translation, $locale)
 {
     if (in_array($locale->slug, $this->length_exclude_languages)) {
         return true;
     }
     if (gp_startswith($original, 'number_format_')) {
         return true;
     }
     $len_src = gp_strlen($original);
     $len_trans = gp_strlen($translation);
     if (!($this->length_lower_bound * $len_src < $len_trans && $len_trans < $this->length_upper_bound * $len_src) && (!gp_in('_abbreviation', $original) && !gp_in('_initial', $original))) {
         return __('Lengths of source and translation differ too much.', 'glotpress');
     }
     return true;
 }
Esempio n. 3
0
 public function read_originals_from_file($file_name)
 {
     $errors = libxml_use_internal_errors(true);
     $data = simplexml_load_string(file_get_contents($file_name));
     libxml_use_internal_errors($errors);
     if (!is_object($data)) {
         return false;
     }
     $entries = new Translations();
     foreach ($data->data as $string) {
         $entry = new Translation_Entry();
         if (isset($string['type']) && gp_in('System.Resources.ResXFileRef', (string) $string['type'])) {
             continue;
         }
         $entry->context = (string) $string['name'];
         $entry->singular = $this->unescape((string) $string->value);
         if (isset($string->comment) && $string->comment) {
             $entry->extracted_comments = (string) $string->comment;
         }
         $entry->translations = array();
         $entries->add_entry($entry);
     }
     return $entries;
 }
 function assertResponseNotContains($needle)
 {
     $this->assertFalse(gp_in($needle, $this->body));
 }
Esempio n. 5
0
 public function gp_translation_set_bulk_action_post($project, $locale, $translation_set, $bulk)
 {
     if ('gtranslate' != $bulk['action']) {
         return;
     }
     if (GP::$user->logged_in() && !$this->key) {
         $user_obj = GP::$user->current();
         $user = strtoupper($user_obj->user_login);
         $user_key = gp_const_get('GP_GOOGLE_TRANSLATE_KEY_' . $user);
         if ($user_key) {
             $this->key = $user_key;
         }
     }
     if (!$this->key) {
         return;
     }
     $google_errors = 0;
     $insert_errors = 0;
     $ok = 0;
     $skipped = 0;
     $singulars = array();
     $original_ids = array();
     foreach ($bulk['row-ids'] as $row_id) {
         if (gp_in('-', $row_id)) {
             $skipped++;
             continue;
         }
         $original_id = gp_array_get(explode('-', $row_id), 0);
         $original = GP::$original->get($original_id);
         if (!$original || $original->plural) {
             $skipped++;
             continue;
         }
         $singulars[] = $original->singular;
         $original_ids[] = $original_id;
     }
     $results = $this->google_translate_batch($locale, $singulars);
     if (is_wp_error($results)) {
         error_log(print_r($results, true));
         $this->errors[] = $results->get_error_message();
         return;
     }
     $items = gp_array_zip($original_ids, $singulars, $results);
     if (!$items) {
         return;
     }
     foreach ($items as $item) {
         list($original_id, $singular, $translation) = $item;
         if (is_wp_error($translation)) {
             $google_errors++;
             error_log($translation->get_error_message());
             continue;
         }
         $data = compact('original_id');
         $data['user_id'] = GP::$user->current()->id;
         $data['translation_set_id'] = $translation_set->id;
         $data['translation_0'] = $translation;
         $data['status'] = 'fuzzy';
         $data['warnings'] = GP::$translation_warnings->check($singular, null, array($translation), $locale);
         $inserted = GP::$translation->create($data);
         $inserted ? $ok++ : $insert_errors++;
     }
     if ($google_errors > 0 || $insert_errors > 0) {
         $message = array();
         if ($ok) {
             $message[] = sprintf(__('Added: %d.'), $ok);
         }
         if ($google_errors) {
             $message[] = sprintf(__('Error from Google Translate: %d.'), $google_errors);
         }
         if ($insert_errors) {
             $message[] = sprintf(__('Error adding: %d.'), $insert_errors);
         }
         if ($skipped) {
             $message[] = sprintf(__('Skipped: %d.'), $skipped);
         }
         $this->errors[] = implode('', $message);
     } else {
         $this->notices[] = sprintf(__('%d fuzzy translation from Google Translate were added.'), $ok);
     }
 }