by_slug() 공개 정적인 메소드

public static by_slug ( $slug )
예제 #1
0
 public function bulk_translate($project_path)
 {
     $project_path = urldecode($project_path);
     $url = gp_url_project($project_path);
     // If we don't have rights, just redirect back to the project.
     if (!GP::$user->current()->can('write', 'project')) {
         gp_redirect($url);
     }
     // Create a project class to use to get the project object.
     $project_class = new GP_Project();
     // Get the project object from the project path that was passed in.
     $project_obj = $project_class->by_path($project_path);
     // Get the translations sets from the project ID.
     $translation_sets = GP::$translation_set->by_project_id($project_obj->id);
     // Loop through all the sets.
     foreach ($translation_sets as $set) {
         //Array ( [action] => gtranslate [priority] => 0 [redirect_to] => http://localhost/wp40/gp/projects/sample/bg/my [row-ids] => Array ( [0] => 1 [1] => 2 ) )
         $bulk = array('action' => 'gtranslate', 'priority' => 0, 'row-ids' => array());
         $translation = new GP_Translation();
         $strings = $translation->for_translation($project_obj, $set, null, array('status' => 'untranslated'));
         foreach ($strings as $string) {
             $bulk['row-ids'][] .= $string->row_id;
         }
         $locale = GP_Locales::by_slug($set->locale);
         $this->gp_translation_set_bulk_action_post($project_obj, $locale, $set, $bulk);
     }
     $url = gp_url_project($project_path);
     gp_redirect($url);
 }
예제 #2
0
 function setUp()
 {
     $this->w = new GP_Builtin_Translation_Warnings();
     $this->bg = GP_Locales::by_slug('bg');
     $this->longer_than_20 = 'The little boy hid behind the counter and then came the wizard of all green wizards!';
     $this->shorter_than_5 = 'Boom';
 }
예제 #3
0
파일: project.php 프로젝트: akirk/GlotPress
 function single($project_path)
 {
     $project = GP::$project->by_path($project_path);
     if (!$project) {
         return $this->die_with_404();
     }
     $sub_projects = $project->sub_projects();
     $translation_sets = GP::$translation_set->by_project_id($project->id);
     foreach ($translation_sets as $set) {
         $locale = GP_Locales::by_slug($set->locale);
         $set->name_with_locale = $set->name_with_locale();
         $set->current_count = $set->current_count();
         $set->untranslated_count = $set->untranslated_count();
         $set->waiting_count = $set->waiting_count();
         $set->fuzzy_count = $set->fuzzy_count();
         $set->percent_translated = $set->percent_translated();
         $set->all_count = $set->all_count();
         $set->wp_locale = $locale->wp_locale;
         if ($this->api) {
             $set->last_modified = $set->current_count ? $set->last_modified() : false;
         }
     }
     usort($translation_sets, function ($a, $b) {
         return $a->current_count < $b->current_count;
     });
     $translation_sets = apply_filters('gp_translation_sets_sort', $translation_sets);
     $title = sprintf(__('%s project ', 'glotpress'), esc_html($project->name));
     $can_write = $this->can('write', 'project', $project->id);
     $this->tmpl('project', get_defined_vars());
 }
 function test_locale_factory_create()
 {
     $locale_factory = new GP_UnitTest_Factory_For_Locale();
     $locale = $locale_factory->create();
     $this->assertEquals('aa', $locale->slug);
     $this->assertEquals('Locale 1', $locale->english_name);
     $this->assertSame($locale, GP_Locales::by_slug($locale->slug));
 }
예제 #5
0
 function setUp()
 {
     $this->is_baba = create_function('$o, $t, $l', 'return $t == "баба"? true : "error";');
     $this->is_equal = create_function('$o, $t, $l', 'return $t == $o? true : "error";');
     $this->w = new GP_Translation_Warnings();
     $this->with_equal = new GP_Translation_Warnings();
     $this->with_equal->add('is_equal', $this->is_equal);
     $this->standard_plural_locale = GP_Locales::by_slug('bg');
 }
예제 #6
0
파일: profile.php 프로젝트: akirk/GlotPress
 private function locales_known($user)
 {
     global $wpdb;
     $translations = GP::$translation_set->many_no_map("\n\t\t\tSELECT ts.locale, count(*) AS count\n\t\t\tFROM {$wpdb->gp_translations} as t\n\t\t\tINNER JOIN {$wpdb->gp_translation_sets} AS ts ON ts.id = t.translation_set_id\n\t\t\tWHERE user_id = %s\n\t\t\tGROUP BY ts.locale\n\t\t\tORDER BY count DESC\n\t\t", $user->ID);
     $locales = array();
     foreach ($translations as $data) {
         $locale = GP_Locales::by_slug($data->locale);
         $locales[$locale->english_name] = array('locale' => $data->locale, 'count' => (int) $data->count);
     }
     return $locales;
 }
예제 #7
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;
 }
예제 #8
0
 function edit_get($glossary_id)
 {
     $glossary = GP::$glossary->get($glossary_id);
     if (!$glossary) {
         $this->redirect_with_error(__('Cannot find glossary.'));
     }
     $translation_set = GP::$translation_set->get($glossary->translation_set_id);
     $locale = GP_Locales::by_slug($translation_set->locale);
     $project = GP::$project->get($translation_set->project_id);
     $this->tmpl('glossary-edit', get_defined_vars());
 }
 function action_on_translation_set($translation_set)
 {
     $project = GP::$project->get($translation_set->project_id);
     $locale = GP_Locales::by_slug($translation_set->locale);
     foreach (GP::$translation->for_translation($project, $translation_set, 'no-limit') as $entry) {
         $warnings = GP::$translation_warnings->check($entry->singular, $entry->plural, $entry->translations, $locale);
         if ($warnings != $entry->warnings) {
             $translation = new GP_Translation(array('id' => $entry->id));
             echo sprintf(__("Updating warnings for %s"), $entry->id) . "\n";
             $translation->update(array('warnings' => $warnings));
         }
     }
 }
예제 #10
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;
 }
예제 #11
0
파일: cli.php 프로젝트: ramiy/GlotPress-WP
 public function run()
 {
     if (!isset($this->options['l']) || !isset($this->options['p'])) {
         $this->usage();
     }
     $this->project = GP::$project->by_path($this->options['p']);
     if (!$this->project) {
         $this->error(__('Project not found!', 'glotpress'));
     }
     $this->locale = GP_Locales::by_slug($this->options['l']);
     if (!$this->locale) {
         $this->error(__('Locale not found!', 'glotpress'));
     }
     $this->options['t'] = gp_array_get($this->options, 't', 'default');
     $this->translation_set = GP::$translation_set->by_project_id_slug_and_locale($this->project->id, $this->options['t'], $this->locale->slug);
     if (!$this->translation_set) {
         $this->error(__('Translation set not found!', 'glotpress'));
     }
     $this->action_on_translation_set($this->translation_set);
 }
예제 #12
0
 public function single($project_path)
 {
     $project = GP::$project->by_path($project_path);
     if (!$project) {
         return $this->die_with_404();
     }
     $sub_projects = $project->sub_projects();
     $translation_sets = GP::$translation_set->by_project_id($project->id);
     foreach ($translation_sets as $set) {
         $locale = GP_Locales::by_slug($set->locale);
         $set->name_with_locale = $set->name_with_locale();
         $set->current_count = $set->current_count();
         $set->untranslated_count = $set->untranslated_count();
         $set->waiting_count = $set->waiting_count();
         $set->fuzzy_count = $set->fuzzy_count();
         $set->percent_translated = $set->percent_translated();
         $set->all_count = $set->all_count();
         $set->wp_locale = $locale->wp_locale;
         if ($this->api) {
             $set->last_modified = $set->current_count ? $set->last_modified() : false;
         }
     }
     usort($translation_sets, function ($a, $b) {
         return $a->current_count < $b->current_count;
     });
     /**
      * Filter the list of translation sets of a project.
      *
      * Can also be used to sort the sets to a custom order.
      *
      * @since 1.0.0
      *
      * @param GP_Translation_Sets[] $translation_sets An array of translation sets.
      */
     $translation_sets = apply_filters('gp_translation_sets_sort', $translation_sets);
     $title = sprintf(__('%s project ', 'glotpress'), esc_html($project->name));
     $can_write = $this->can('write', 'project', $project->id);
     $this->tmpl('project', get_defined_vars());
 }
예제 #13
0
 function get_cap_key($locale_slug)
 {
     global $gpdb;
     static $ros_blogs, $ros_locale_assoc;
     $gp_locale = GP_Locales::by_slug($locale_slug);
     if (!$gp_locale || !isset($gp_locale->wp_locale)) {
         return false;
     }
     $wp_locale = $gp_locale->wp_locale;
     if (!isset($ros_blogs)) {
         $ros_locale_assoc = $gpdb->get_results("SELECT locale, subdomain FROM locales", OBJECT_K);
         $ros_blogs = $gpdb->get_results("SELECT domain, blog_id FROM ros_blogs", OBJECT_K);
     }
     if (isset($ros_locale_assoc[$wp_locale])) {
         $subdomain = $ros_locale_assoc[$wp_locale]->subdomain;
     } else {
         return false;
     }
     if (isset($ros_blogs["{$subdomain}.wordpress.org"])) {
         return 'ros_' . $ros_blogs["{$subdomain}.wordpress.org"]->blog_id . '_capabilities';
     }
     return false;
 }
예제 #14
0
 public function for_translation($project, $translation_set, $page, $filters = array(), $sort = array())
 {
     global $wpdb;
     $locale = GP_Locales::by_slug($translation_set->locale);
     $join_type = 'INNER';
     $sort_bys = wp_list_pluck(gp_get_sort_by_fields(), 'sql_sort_by');
     $default_sort = get_user_option('gp_default_sort');
     if (!is_array($default_sort)) {
         $default_sort = array('by' => 'priority', 'how' => 'desc');
     }
     $sort_by = gp_array_get($sort_bys, gp_array_get($sort, 'by'), gp_array_get($sort_bys, $default_sort['by']));
     $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC');
     $sort_how = gp_array_get($sort_hows, gp_array_get($sort, 'how'), gp_array_get($sort_hows, $default_sort['how']));
     $collation = 'yes' === gp_array_get($filters, 'case_sensitive') ? 'BINARY' : '';
     $where = array();
     if (gp_array_get($filters, 'term')) {
         $like = "LIKE {$collation} '%" . esc_sql($wpdb->esc_like(gp_array_get($filters, 'term'))) . "%'";
         $where[] = '(' . implode(' OR ', array_map(function ($x) use($like) {
             return "({$x} {$like})";
         }, array('o.singular', 't.translation_0', 'o.plural', 't.translation_1', 'o.context', 'o.references'))) . ')';
     }
     if (gp_array_get($filters, 'before_date_added')) {
         $where[] = $wpdb->prepare('t.date_added > %s', gp_array_get($filters, 'before_date_added'));
     }
     if (gp_array_get($filters, 'translation_id')) {
         $where[] = $wpdb->prepare('t.id = %d', gp_array_get($filters, 'translation_id'));
     }
     if (gp_array_get($filters, 'original_id')) {
         $where[] = $wpdb->prepare('o.id = %d', gp_array_get($filters, 'original_id'));
     }
     if ('yes' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NOT NULL';
         $where[] = 't.warnings != ""';
     } elseif ('no' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_context')) {
         $where[] = 'o.context IS NOT NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_comment')) {
         $where[] = 'o.comment IS NOT NULL AND o.comment <> ""';
     }
     if (gp_array_get($filters, 'user_login')) {
         $user = get_user_by('login', $filters['user_login']);
         // do not return any entries if the user doesn't exist
         $where[] = $wpdb->prepare('t.user_id = %d', $user && $user->ID ? $user->ID : -1);
     }
     if (!GP::$permission->current_user_can('write', 'project', $project->id)) {
         $where[] = 'o.priority > -2';
     }
     $priorities = gp_array_get($filters, 'priority');
     if ($priorities) {
         $valid_priorities = array_keys(GP::$original->get_static('priorities'));
         $priorities = array_filter(gp_array_get($filters, 'priority'), function ($p) use($valid_priorities) {
             return in_array($p, $valid_priorities, true);
         });
         $priorities_where = array();
         foreach ($priorities as $single_priority) {
             $priorities_where[] = $wpdb->prepare('o.priority = %s', $single_priority);
         }
         if (!empty($priorities_where)) {
             $priorities_where = '(' . implode(' OR ', $priorities_where) . ')';
             $where[] = $priorities_where;
         }
     }
     $join_where = array();
     $status = gp_array_get($filters, 'status', 'current_or_waiting_or_fuzzy_or_untranslated');
     $statuses = explode('_or_', $status);
     if (in_array('untranslated', $statuses)) {
         if ($statuses == array('untranslated')) {
             $where[] = 't.translation_0 IS NULL';
         }
         $join_type = 'LEFT';
         $join_where[] = 't.status != "rejected"';
         $join_where[] = 't.status != "old"';
         $statuses = array_filter($statuses, function ($x) {
             return $x != 'untranslated';
         });
     }
     $all_statuses = $this->get_static('statuses');
     $statuses = array_filter($statuses, function ($s) use($all_statuses) {
         return in_array($s, $all_statuses);
     });
     if (!empty($statuses)) {
         $statuses_where = array();
         foreach ($statuses as $single_status) {
             $statuses_where[] = $wpdb->prepare('t.status = %s', $single_status);
         }
         $statuses_where = '(' . implode(' OR ', $statuses_where) . ')';
         $join_where[] = $statuses_where;
     }
     /**
      * Filter the SQL WHERE clause to get available translations.
      *
      * @since 1.0.0
      *
      * @param array              $where           An array of where conditions.
      * @param GP_Translation_Set $translation_set Current translation set.
      */
     $where = apply_filters('gp_for_translation_where', $where, $translation_set);
     $where = implode(' AND ', $where);
     if ($where) {
         $where = 'AND ' . $where;
     }
     $join_where = implode(' AND ', $join_where);
     if ($join_where) {
         $join_where = 'AND ' . $join_where;
     }
     $sql_sort = sprintf($sort_by, $sort_how);
     $limit = $this->sql_limit_for_paging($page, $this->per_page);
     $sql_for_translations = "\n\t\t\tSELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added\n\t\t\tFROM {$wpdb->gp_originals} as o\n\t\t\t{$join_type} JOIN {$wpdb->gp_translations} AS t ON o.id = t.original_id AND t.translation_set_id = " . (int) $translation_set->id . " {$join_where}\n\t\t\tWHERE o.project_id = " . (int) $project->id . " AND o.status = '+active' {$where} ORDER BY {$sql_sort} {$limit}";
     $rows = $this->many_no_map($sql_for_translations);
     $this->found_rows = $this->found_rows();
     $translations = array();
     foreach ((array) $rows as $row) {
         $row->user = $row->user_last_modified = null;
         if ($row->user_id && 'no-limit' !== $this->per_page) {
             $row->user = get_userdata($row->user_id);
         }
         if ($row->user_id_last_modified && 'no-limit' !== $this->per_page) {
             $row->user_last_modified = get_userdata($row->user_id_last_modified);
         }
         $row->translations = array();
         for ($i = 0; $i < $locale->nplurals; $i++) {
             $row->translations[] = $row->{"translation_" . $i};
         }
         $row->references = preg_split('/\\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY);
         $row->extracted_comments = $row->comment;
         $row->warnings = $row->warnings ? maybe_unserialize($row->warnings) : null;
         unset($row->comment);
         foreach (range(0, $this->get_static('number_of_plural_translations')) as $i) {
             $member = "translation_{$i}";
             unset($row->{$member});
         }
         $row->row_id = $row->original_id . ($row->id ? "-{$row->id}" : '');
         $translations[] = new Translation_Entry((array) $row);
     }
     unset($rows);
     return $translations;
 }
예제 #15
0
 /**
  * private functions for admin page : the language list
  * @since 0.9.0
  *
  * @update 0.9.5 : two default languages if taxonomy languages is empty
  * @update 1.8.8 : fixes slug of defaults
  * @update 1.8.9.1 : visible = *
  * @updated 2.6 : style
  * @updated 2.7.1 : default full name
  * @updated 2.11.2 : detailled counter in title
  */
 function available_languages_row()
 {
     global $wpdb;
     /*list of languages*/
     $listlanguages = get_terms_of_groups_lite($this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC');
     if (empty($listlanguages)) {
         /*create two default lines with the default language (as in config)*/
         /* language of WP */
         $term = 'en_US';
         $args = array('alias_of' => '', 'description' => 'english', 'parent' => 0, 'slug' => 'en_us');
         $term_data = $this->safe_lang_term_creation($term, $args);
         if (!is_wp_error($term_data)) {
             wp_set_object_terms($term_data['term_id'], 'the-langs-group', TAXOLANGSGROUP);
         } else {
             $inserted = $this->safe_insert_in_language_group($term_data, 0);
         }
         $term = $this->default_lang;
         $desc = isset($this->examples_list[$term]) ? $this->examples_list[$term] : $this->default_lang;
         $desc_array = explode(' (', $desc);
         $desc = $desc_array[0];
         $slug = strtolower($this->default_lang);
         // 2.3.1
         $wplang = $this->get_WPLANG();
         if ('' == $wplang || $this->default_lang == 'en_US' || $this->default_lang == '') {
             $term = 'fr_FR';
             $desc = 'French';
             $slug = 'fr_fr';
         }
         $args = array('alias_of' => '', 'description' => $desc, 'parent' => 0, 'slug' => $slug);
         $term_data = $this->safe_lang_term_creation($term, $args);
         if (!is_wp_error($term_data)) {
             wp_set_object_terms($term_data['term_id'], 'the-langs-group', TAXOLANGSGROUP);
         } else {
             $inserted = $this->safe_insert_in_language_group($term_data, 0);
         }
         $listlanguages = get_terms_of_groups_lite($this->langs_group_id, TAXOLANGSGROUP, TAXONAME, 'ASC');
     }
     $trclass = '';
     foreach ($listlanguages as $language) {
         $trclass = defined('DOING_AJAX') && DOING_AJAX || ' alternate' == $trclass ? '' : ' alternate';
         $language->count = number_format_i18n($language->count);
         // count for each CPT
         $counts = array();
         $title = array();
         $custompoststype = $this->authorized_custom_post_type(true);
         // 2.13.2 b
         foreach ($custompoststype as $key => $customtype) {
             $counts[$key] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->term_relationships}, {$wpdb->posts} WHERE {$wpdb->posts}.ID = {$wpdb->term_relationships}.object_id AND post_status = 'publish' AND term_taxonomy_id = %d AND post_type = %s", $language->term_id, $key));
             $title[] = $customtype['name'] . ' = ' . $counts[$key];
         }
         $title = implode(' | ', $title);
         $posts_count = $language->count > 0 ? '<a title= "' . $title . '" href="edit.php?lang=' . $language->slug . '">' . $language->count . '</a>' : $language->count;
         /* edit link*/
         // nounce added
         $link = wp_nonce_url("?action=edit&amp;page=language_page&amp;term_id=" . $language->term_id, "edit-" . $language->term_id);
         $edit = "<a href='" . $link . "' >" . __('Edit') . "</a>&nbsp;|";
         /* delete link*/
         // nounce added
         $link = wp_nonce_url("?action=delete&amp;page=language_page&amp;term_id=" . $language->term_id, "delete-" . $language->term_id);
         $edit .= "&nbsp;<a href='" . $link . "' class='delete'>" . __('Delete') . "</a>";
         $h = isset($this->xili_settings['lang_features'][$language->slug]['hidden']) && $this->xili_settings['lang_features'][$language->slug]['hidden'] == 'hidden' ? "&nbsp;" : "&#10004;";
         $h .= isset($this->xili_settings['lang_features'][$language->slug]['charset']) && $this->xili_settings['lang_features'][$language->slug]['charset'] != '' ? "&nbsp;+" : "";
         $is_mo = !empty($language->name) && array_key_exists($language->name, (array) $this->available_languages());
         $mo_available_for_dashboard = $is_mo ? "&#10004;" : "";
         $line = '<tr id="lang-' . $language->term_id . '" class="lang-' . $language->slug . $trclass . '" >' . '<th scope="row" class="lang-id" ><span class="lang-flag">' . $language->term_id . '<span></th>' . '<td>' . $language->name . '</td>';
         $cur_locale = GP_Locales::by_field('wp_locale', $language->name);
         if ($cur_locale) {
             $native = $cur_locale->native_name;
         } else {
             $cur_locale = GP_Locales::by_slug($language->slug);
             $native = $cur_locale ? $cur_locale->native_name . ' *' : '';
         }
         if ($this->alias_mode) {
             $alias_val = $this->lang_slug_qv_trans($language->slug) == $language->slug && 2 != strlen($language->slug) ? ' ? ' : $this->lang_slug_qv_trans($language->slug);
             $key_slug = array_keys($this->langs_slug_shortqv_array, $alias_val);
             if (count($key_slug) == 1) {
                 $line .= '<td>' . $alias_val . '</td>';
             } else {
                 $line .= '<td><span class="red-alert">' . $alias_val . '</span></td>';
             }
         }
         $line .= '<td>' . $language->description . '</td>' . '<td>' . $native . '</td>' . '<td>' . $language->slug . '</td>' . '<td>' . $language->term_order . '</td>' . '<td class="col-center" >' . $h . '</td>' . '<td class="col-center" >' . $mo_available_for_dashboard . '</td>' . '<td class="col-center" >' . $posts_count . '</td>' . '<td class="col-center" >' . $edit . "</td>\n\t</tr>\n";
         echo $line;
     }
 }
예제 #16
0
 public function single($locale_slug, $current_set_slug = 'default')
 {
     $locale = GP_Locales::by_slug($locale_slug);
     $sets = GP::$translation_set->by_locale($locale_slug);
     usort($sets, array($this, 'sort_sets_by_project_id'));
     $locale_projects = $projects_data = $projects = $parents = $set_slugs = $set_list = array();
     //TODO: switch to wp_list_pluck
     foreach ($sets as $key => $value) {
         $locale_projects[$key] = $value->project_id;
     }
     foreach ($sets as $set) {
         $set_slugs[$set->slug] = $set;
         if ($current_set_slug != $set->slug) {
             continue;
         }
         // Store project data for later use
         if (isset($projects[$set->project_id])) {
             $set_project = $projects[$set->project_id];
         } else {
             $set_project = GP::$project->get($set->project_id);
             $projects[$set->project_id] = $set_project;
         }
         // We only want to list active projects
         if (!isset($set_project->active) || $set_project->active == false) {
             continue;
         }
         $parent_id = is_null($set_project->parent_project_id) ? $set_project->id : $set_project->parent_project_id;
         // Store parent project data for later use
         if (isset($projects[$parent_id])) {
             $parent_project = $projects[$parent_id];
         } else {
             $parent_project = GP::$project->get($parent_id);
             $projects[$parent_id] = $parent_project;
         }
         // Store parent id for
         $parents[$set_project->id] = $parent_id;
         if (!in_array($set_project->parent_project_id, $locale_projects)) {
             $projects_data[$parent_id][$set_project->id]['project'] = $set_project;
             $projects_data[$parent_id][$set_project->id]['sets'][$set->id] = $this->set_data($set, $set_project);
             $projects_data[$parent_id][$set_project->id]['totals'] = $this->set_data($set, $set_project);
             if (!isset($projects_data[$parent_id][$set_project->id]['project'])) {
                 $projects_data[$parent_id][$set_project->id]['project'] = $set_project;
             }
         } else {
             while (!in_array($parent_id, array_keys($projects_data)) && isset($parents[$parent_id])) {
                 $previous_parent = $parent_id;
                 $parent_id = $parents[$parent_id];
             }
             //Orphan project - a sub project is set to active, while it's parent isn't
             if (!isset($projects_data[$parent_id])) {
                 continue;
             }
             //For when root project has sets, and sub projects.
             if (!isset($previous_parent) || !isset($projects_data[$parent_id][$previous_parent])) {
                 $previous_parent = $parent_id;
             }
             $set_data = $projects_data[$parent_id][$previous_parent]['totals'];
             $projects_data[$parent_id][$previous_parent]['sets'][$set->id] = $this->set_data($set, $set_project);
             $projects_data[$parent_id][$previous_parent]['totals'] = $this->set_data($set, $set_project, $set_data);
         }
     }
     if ('default' !== $current_set_slug && !isset($set_slugs[$current_set_slug])) {
         return $this->die_with_404();
     }
     if ($set_slugs) {
         // Make default the first item.
         if (!empty($set_slugs['default'])) {
             $default = $set_slugs['default'];
             unset($set_slugs['default']);
             array_unshift($set_slugs, $default);
         }
         foreach ($set_slugs as $set) {
             if ('default' == $set->slug) {
                 if ('default' != $current_set_slug) {
                     $set_list[$set->slug] = gp_link_get(gp_url_join('/languages', $locale->slug), __('Default'));
                 } else {
                     $set_list[$set->slug] = __('Default');
                 }
             } else {
                 if ($set->slug != $current_set_slug) {
                     $set_list[$set->slug] = gp_link_get(gp_url_join('/languages', $locale->slug, $set->slug), esc_html($set->name));
                 } else {
                     $set_list[$set->slug] = esc_html($set->name);
                 }
             }
         }
     }
     $this->tmpl('locale', get_defined_vars());
 }
 private function _export_to_file($format, $dir, $project, $locale, $set)
 {
     // Get the entries we going to export.
     $entries = GP::$translation->for_export($project, $set);
     // Get the slug for this locale.
     $locale_slug = $set->locale;
     // Get the locale object by the slug.
     $locale = GP_Locales::by_slug($locale_slug);
     // Apply any filters that other plugins may have implemented.
     $export_locale = apply_filters('export_locale', $locale->slug, $locale);
     // Get the format object to create the export with.
     $format_obj = gp_array_get(GP::$formats, gp_get('format', $format), null);
     // Create the default file name.
     $filename = sprintf('%s-%s.' . $format_obj->extension, str_replace('/', '-', $project->path), $export_locale);
     // Apply any filters that other plugins may have implemented to the filename.
     $filename = apply_filters('export_filename', $filename, $project->path, $set->slug, $export_locale, $format_obj->extension);
     // Get the contents from the formatter.
     $contents = $format_obj->print_exported_file($project, $locale, $set, $entries);
     // Write the contents out to the file.
     $fh = fopen($dir . '/' . $filename, 'w');
     fwrite($fh, $contents);
     fclose($fh);
     // Return the filename for future reference.
     return $filename;
 }
예제 #18
0
}, $temp_file_path);
// The current Jetpack translations
$current_sets = glob($jetpack_directory . '/languages/*.mo');
$current_sets = preg_replace('/.*-(\\w+)\\.mo/', '$1', $current_sets);
$keys = array_map('strtolower', $current_sets);
$current_sets = array_combine($keys, $current_sets);
unset($keys);
$source_url = apize_url(rtrim($argv[2], '/'));
$source = file_get_contents($source_url);
$available_sets = json_decode($source)->translation_sets;
// Maps source locale slugs to current Jetpack locales
$map = $language_pack = array();
foreach ($available_sets as $set) {
    $s = strtolower(str_replace('-', '_', $set->locale));
    if (GP_Locales::exists($set->locale)) {
        $locale = GP_Locales::by_slug($set->locale);
        if (in_array($set->locale, $language_packs)) {
            $language_pack[$set->locale] = $locale->wp_locale;
            continue;
        }
        $map[$set->locale] = $locale->wp_locale;
        continue;
    }
    echo "ERROR\n";
    // source's 'ja' matches Jetpack's 'ja'
    if (isset($current_sets[$s])) {
        $map[$set->locale] = $current_sets[$s];
        unset($current_sets[$s]);
        continue;
    }
    // source's 'it' matches Jetpack's 'it_IT'
 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;
 }
예제 #20
0
 function for_translation($project, $translation_set, $page, $filters = array(), $sort = array())
 {
     global $gpdb;
     $locale = GP_Locales::by_slug($translation_set->locale);
     $status_cond = '';
     $sort_bys = array('original' => 'o.singular', 'translation' => 't.translation_0', 'priority' => 'o.priority', 'random' => 'RAND()', 'translation_date_added' => 't.date_added', 'original_date_added' => 'o.date_added', 'references' => 'o.references');
     $sort_by = gp_array_get($sort_bys, gp_array_get($sort, 'by'), 'o.date_added');
     $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC');
     $sort_how = gp_array_get($sort_hows, gp_array_get($sort, 'how'), 'DESC');
     $where = array();
     if (gp_array_get($filters, 'term')) {
         // if the first letters is s, %%s is causing db::prepare trouble, capital S doesn't
         $no_leading_s_term = preg_replace('/^s/', 'S', $filters['term']);
         $like = "LIKE '%%" . $this->like_escape_printf($gpdb->escape($no_leading_s_term)) . "%%'";
         $where[] = '(' . implode(' OR ', array_map(lambda('$x', '"($x $like)"', compact('like')), array('o.singular', 't.translation_0', 'o.plural', 't.translation_1'))) . ')';
     }
     if ('yes' == gp_array_get($filters, 'translated')) {
         $where[] = 't.translation_0 IS NOT NULL';
     } elseif ('no' == gp_array_get($filters, 'translated')) {
         $where[] = 't.translation_0 IS NULL';
     }
     if (gp_array_get($filters, 'before_date_added')) {
         $where[] = $gpdb->prepare('t.date_added > %s', gp_array_get($filters, 'before_date_added'));
     }
     if (gp_array_get($filters, 'translation_id')) {
         $where[] = $gpdb->prepare('t.id = %d', gp_array_get($filters, 'translation_id'));
     }
     if (gp_array_get($filters, 'original_id')) {
         $where[] = $gpdb->prepare('o.id = %d', gp_array_get($filters, 'original_id'));
     }
     if ('yes' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NOT NULL';
     } elseif ('no' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NULL';
     }
     $join_where = array();
     $status = gp_array_get($filters, 'status', 'current_or_waiting');
     $all_in = true;
     $statuses = explode('_or_', $status);
     foreach ($statuses as $single_status) {
         if (!in_array($single_status, $this->get_static('statuses'))) {
             $all_in = false;
             break;
         }
     }
     if ($all_in) {
         $statuses_where = array();
         foreach ($statuses as $single_status) {
             $statuses_where[] = $gpdb->prepare('t.status = %s', $single_status);
         }
         $statuses_where = '(' . implode(' OR ', $statuses_where) . ')';
         $join_where[] = $statuses_where;
         /*
         	usually we want the status to be part of the ON clause, because we want to include
         	the untranslated strings in the listing. This, however is not the case if the filter
         	explictly forbids untranslated strings
         */
         if ('no' == gp_array_get($filters, 'translated')) {
             $where[] = $statuses_where;
         }
     }
     $where = implode(' AND ', $where);
     if ($where) {
         $where = 'AND ' . $where;
     }
     $join_where = implode(' AND ', $join_where);
     if ($join_where) {
         $join_where = 'AND ' . $join_where;
     }
     $limit = $this->sql_limit_for_paging($page);
     $rows = $this->many_no_map("\n\t\t    SELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added\n\t\t    FROM {$gpdb->originals} as o\n\t\t    LEFT JOIN {$gpdb->translations} AS t ON o.id = t.original_id AND t.translation_set_id = %d {$join_where}\n\t\t    WHERE o.project_id = %d AND o.status LIKE '+%%' {$where} ORDER BY {$sort_by} {$sort_how} {$limit}", $translation_set->id, $project->id);
     $this->found_rows = $this->found_rows();
     $translations = array();
     foreach ($rows as $row) {
         if ($row->user_id && $this->per_page != 'no-limit') {
             $user = GP::$user->get($row->user_id);
             if ($user) {
                 $row->user_login = $user->user_login;
             }
         } else {
             $row->user_login = '';
         }
         $row->translations = array($row->translation_0, $row->translation_1, $row->translation_2, $row->translation_3);
         $row->translations = array_slice($row->translations, 0, $locale->nplurals);
         $row->references = preg_split('/\\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY);
         $row->extracted_comment = $row->comment;
         $row->warnings = $row->warnings ? maybe_unserialize($row->warnings) : null;
         unset($row->comment);
         foreach (range(0, 3) as $i) {
             $member = "translation_{$i}";
             unset($row->{$member});
         }
         $row->row_id = $row->original_id . ($row->id ? "-{$row->id}" : '');
         $translations[] = new Translation_Entry((array) $row);
     }
     unset($rows);
     return $translations;
 }
예제 #21
0
 /**
  * Recheck warnings for the translation set
  *
  * ## OPTIONS
  *
  * <project>
  * : Project path
  *
  * <locale>
  * : Locale to export
  *
  * [--set=<set>]
  * : Translation set slug; default is "default"
  *
  * @subcommand recheck-warnings
  */
 public function recheck_warnings($args, $assoc_args)
 {
     $set_slug = isset($assoc_args['set']) ? $assoc_args['set'] : 'default';
     $translation_set = $this->get_translation_set($args[0], $args[1], $set_slug);
     if (is_wp_error($translation_set)) {
         WP_CLI::error($translation_set->get_error_message());
     }
     $project = GP::$project->get($translation_set->project_id);
     $locale = GP_Locales::by_slug($translation_set->locale);
     foreach (GP::$translation->for_translation($project, $translation_set, 'no-limit') as $entry) {
         $warnings = GP::$translation_warnings->check($entry->singular, $entry->plural, $entry->translations, $locale);
         if ($warnings == $entry->warnings) {
             continue;
         }
         $translation = new GP_Translation(array('id' => $entry->id));
         /* translators: %s: ID of a translation */
         WP_CLI::line(sprintf(__('Updating warnings for #%s', 'glotpress'), $entry->id));
         $translation->update(array('warnings' => $warnings));
     }
 }
예제 #22
0
 public function import_glossary_entries_post($project_path, $locale_slug, $translation_set_slug)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     if (!$project || !$locale) {
         return $this->die_with_404();
     }
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$translation_set) {
         return $this->die_with_404();
     }
     $glossary = GP::$glossary->by_set_id($translation_set->id);
     if (!$glossary) {
         return $this->die_with_404();
     }
     if ($this->cannot_and_redirect('approve', 'translation-set', $translation_set->id)) {
         return;
     }
     if (!is_uploaded_file($_FILES['import-file']['tmp_name'])) {
         $this->redirect_with_error(__('Error uploading the file.', 'glotpress'));
         return;
     }
     $glossary_entries_added = $this->read_glossary_entries_from_file($_FILES['import-file']['tmp_name'], $glossary->id, $locale->slug);
     if (empty($this->errors) && is_int($glossary_entries_added)) {
         $this->notices[] = sprintf(__('%s glossary entries were added', 'glotpress'), $glossary_entries_added);
     }
     $this->redirect(gp_url_join(gp_url_project_locale($project_path, $locale_slug, $translation_set_slug), array('glossary')));
 }
 function guess_locale_from_lang($lang)
 {
     if ('en' == $lang || 'en_US' == $lang || !$lang) {
         return 'en_US';
     }
     if (!class_exists('GP_Locales')) {
         if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
             return false;
         }
         require JETPACK__GLOTPRESS_LOCALES_PATH;
     }
     if (defined('IS_WPCOM') && IS_WPCOM) {
         // WP.com: get_locale() returns 'it'
         $locale = GP_Locales::by_slug($lang);
     } else {
         // Jetpack: get_locale() returns 'it_IT';
         $locale = GP_Locales::by_field('facebook_locale', $lang);
     }
     if (!$locale || empty($locale->facebook_locale)) {
         return 'en_US';
         // Facebook requires a locale when pulling their SDK.
     }
     return $locale->facebook_locale;
 }
예제 #24
0
 function update_translations()
 {
     require_once $this->glotpress_source_dir . '/locales/locales.php';
     foreach ($this->importers as $importer) {
         $project_details_json = file_get_contents($this->s($importer, $this->glotpress_api_url));
         $project_details = json_decode($project_details_json);
         if (!is_object($project_details)) {
             echo "Couldn't get project JSON from GlotPress for {$importer}.\n";
             continue;
         }
         foreach ($project_details->translation_sets as $set) {
             $locale = GP_Locales::by_slug($set->locale);
             if (!$locale->wp_locale) {
                 echo "Locale '{$set->locale}' doesn't have WordPress equivalent.\n";
                 continue;
             }
             $po_file = file_get_contents($this->s($importer, $this->glotpress_url) . "/{$locale->slug}/{$set->slug}/export-translations");
             if (!$po_file) {
                 echo "Couldn't download translation for '{$importer}' in '{$set->locale}'.\n";
                 continue;
             }
             $po_path = $this->s($importer, "%trunk%/languages/{$locale->wp_locale}.po");
             $mo_path = str_replace('.po', '.mo', $po_path);
             file_put_contents($po_path, $po_file);
             $msgfmt_output = `msgfmt --statistics {$po_path} -o {$mo_path} 2>&1`;
             preg_match('/(\\d+) translated messages(?:\\.|, (\\d+) untranslated messages)/', $msgfmt_output, $matches);
             if (isset($matches[2])) {
                 $translated_percentage = $matches[1] / ($matches[1] + $matches[2]) * 100;
                 if ($translated_percentage < $this->minimum_percentage) {
                     unlink($po_path);
                     unlink($mo_path);
                     echo "Translation of '{$importer}' in '{$locale->slug}' has only {$translated_percentage}% translated, {$this->minimum_percentage}% are required.\n";
                 }
             }
         }
     }
 }
예제 #25
0
 function for_translation($project, $translation_set, $page, $filters = array(), $sort = array())
 {
     global $gpdb;
     $locale = GP_Locales::by_slug($translation_set->locale);
     $join_type = 'INNER';
     $sort_bys = array('original' => 'o.singular %s', 'translation' => 't.translation_0 %s', 'priority' => 'o.priority %s, o.date_added DESC', 'random' => 'o.priority DESC, RAND()', 'translation_date_added' => 't.date_added %s', 'original_date_added' => 'o.date_added %s', 'references' => 'o.references');
     $default_sort = GP::$user->current()->sort_defaults();
     $sort_by = gp_array_get($sort_bys, gp_array_get($sort, 'by'), gp_array_get($sort_bys, $default_sort['by']));
     $sort_hows = array('asc' => 'ASC', 'desc' => 'DESC');
     $sort_how = gp_array_get($sort_hows, gp_array_get($sort, 'how'), gp_array_get($sort_hows, $default_sort['how']));
     $where = array();
     if (gp_array_get($filters, 'term')) {
         $like = "LIKE '%" . $gpdb->escape(like_escape(gp_array_get($filters, 'term'))) . "%'";
         $where[] = '(' . implode(' OR ', array_map(function ($x) use($like) {
             return "({$x} {$like})";
         }, array('o.singular', 't.translation_0', 'o.plural', 't.translation_1', 'o.context', 'o.references'))) . ')';
     }
     if (gp_array_get($filters, 'before_date_added')) {
         $where[] = $gpdb->prepare('t.date_added > %s', gp_array_get($filters, 'before_date_added'));
     }
     if (gp_array_get($filters, 'translation_id')) {
         $where[] = $gpdb->prepare('t.id = %d', gp_array_get($filters, 'translation_id'));
     }
     if (gp_array_get($filters, 'original_id')) {
         $where[] = $gpdb->prepare('o.id = %d', gp_array_get($filters, 'original_id'));
     }
     if ('yes' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NOT NULL';
         $where[] = 't.warnings != ""';
     } elseif ('no' == gp_array_get($filters, 'warnings')) {
         $where[] = 't.warnings IS NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_context')) {
         $where[] = 'o.context IS NOT NULL';
     }
     if ('yes' == gp_array_get($filters, 'with_comment')) {
         $where[] = 'o.comment IS NOT NULL AND o.comment <> ""';
     }
     if (gp_array_get($filters, 'user_login')) {
         $user = GP::$user->by_login($filters['user_login']);
         // do not return any entries if the user doesn't exist
         $where[] = $gpdb->prepare('t.user_id = %d', $user && $user->id ? $user->id : -1);
     }
     if (!GP::$user->current()->can('write', 'project', $project->id)) {
         $where[] = 'o.priority > -2';
     }
     $join_where = array();
     $status = gp_array_get($filters, 'status', 'current_or_waiting_or_fuzzy_or_untranslated');
     $statuses = explode('_or_', $status);
     if (in_array('untranslated', $statuses)) {
         if ($statuses == array('untranslated')) {
             $where[] = 't.translation_0 IS NULL';
         }
         $join_type = 'LEFT';
         $join_where[] = 't.status != "rejected"';
         $join_where[] = 't.status != "old"';
         $statuses = array_filter($statuses, function ($x) {
             return $x != 'untranslated';
         });
     }
     $all_statuses = $this->get_static('statuses');
     $statuses = array_filter($statuses, function ($s) use($all_statuses) {
         return in_array($s, $all_statuses);
     });
     if ($statuses) {
         $statuses_where = array();
         foreach ($statuses as $single_status) {
             $statuses_where[] = $gpdb->prepare('t.status = %s', $single_status);
         }
         $statuses_where = '(' . implode(' OR ', $statuses_where) . ')';
         $join_where[] = $statuses_where;
     }
     $where = apply_filters('for_translation_where', $where, $translation_set);
     $where = implode(' AND ', $where);
     if ($where) {
         $where = 'AND ' . $where;
     }
     $join_where = implode(' AND ', $join_where);
     if ($join_where) {
         $join_where = 'AND ' . $join_where;
     }
     $sql_sort = sprintf($sort_by, $sort_how);
     $limit = $this->sql_limit_for_paging($page, $this->per_page);
     $sql_for_translations = "\n\t\t\tSELECT SQL_CALC_FOUND_ROWS t.*, o.*, t.id as id, o.id as original_id, t.status as translation_status, o.status as original_status, t.date_added as translation_added, o.date_added as original_added\n\t\t\tFROM {$gpdb->originals} as o\n\t\t\t{$join_type} JOIN {$gpdb->translations} AS t ON o.id = t.original_id AND t.translation_set_id = " . $gpdb->escape($translation_set->id) . " {$join_where}\n\t\t\tWHERE o.project_id = " . $gpdb->escape($project->id) . " AND o.status LIKE '+%' {$where} ORDER BY {$sql_sort} {$limit}";
     $rows = $this->many_no_map($sql_for_translations);
     $this->found_rows = $this->found_rows();
     $translations = array();
     foreach ((array) $rows as $row) {
         if ($row->user_id && $this->per_page != 'no-limit') {
             $user = GP::$user->get($row->user_id);
             if ($user) {
                 $row->user_login = $user->user_login;
                 $row->user_display_name = $user->display_name;
                 $row->user_nicename = $user->user_nicename;
             }
         } else {
             $row->user_login = $row->user_display_name = $row->user_nicename = '';
         }
         $row->translations = array();
         for ($i = 0; $i < $locale->nplurals; $i++) {
             $row->translations[] = $row->{"translation_" . $i};
         }
         $row->references = preg_split('/\\s+/', $row->references, -1, PREG_SPLIT_NO_EMPTY);
         $row->extracted_comments = $row->comment;
         $row->warnings = $row->warnings ? maybe_unserialize($row->warnings) : null;
         unset($row->comment);
         foreach (range(0, $this->get_static('number_of_plural_translations')) as $i) {
             $member = "translation_{$i}";
             unset($row->{$member});
         }
         $row->row_id = $row->original_id . ($row->id ? "-{$row->id}" : '');
         $translations[] = new Translation_Entry((array) $row);
     }
     unset($rows);
     return $translations;
 }
예제 #26
0
 function discard_warning($project_path, $locale_slug, $translation_set_slug)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$project || !$locale || !$translation_set) {
         gp_tmpl_404();
     }
     $this->can_or_forbidden('write', 'project', $project->id);
     $translation = GP::$translation->get(gp_post('translation_id'));
     if (!$translation) {
         $this->die_with_error('Translation doesn&#8217;t exist!');
     }
     if (!isset($translation->warnings[gp_post('index')][gp_post('key')])) {
         $this->die_with_error('The warning doesn&#8217;exist!');
     }
     unset($translation->warnings[gp_post('index')][gp_post('key')]);
     if (empty($translation->warnings[gp_post('index')])) {
         unset($translation->warnings[gp_post('index')]);
     }
     $res = $translation->save();
     if (!$res) {
         $this->die_with_error('Error in saving the translation!');
     }
     $translations = GP::$translation->for_translation($project, $translation_set, 'no-limit', array('translation_id' => gp_post('translation_id')), array());
     if ($translations) {
         $t = $translations[0];
         $parity = returner('even');
         $can_edit = GP::$user->logged_in();
         $can_approve = $this->can('approve', 'translation-set', $translation_set->id);
         gp_tmpl_load('translation-row', get_defined_vars());
     } else {
         $this->die_with_error('Error in retrieving translation!');
     }
 }
예제 #27
0
 private function edit_single_translation($project_path, $locale_slug, $translation_set_slug, $edit_function)
 {
     $project = GP::$project->by_path($project_path);
     $locale = GP_Locales::by_slug($locale_slug);
     if (!$project || !$locale) {
         return $this->die_with_404();
     }
     $translation_set = GP::$translation_set->by_project_id_slug_and_locale($project->id, $translation_set_slug, $locale_slug);
     if (!$translation_set) {
         return $this->die_with_404();
     }
     $translation = GP::$translation->get(gp_post('translation_id'));
     if (!$translation) {
         return $this->die_with_error('Translation doesn&#8217;t exist!');
     }
     $this->can_approve_translation_or_forbidden($translation);
     call_user_func($edit_function, $project, $locale, $translation_set, $translation);
     $translations = GP::$translation->for_translation($project, $translation_set, 'no-limit', array('translation_id' => $translation->id, 'status' => 'either'), array());
     if ($translations) {
         $t = $translations[0];
         $can_edit = $this->can('edit', 'translation-set', $translation_set->id);
         $can_write = $this->can('write', 'project', $project->id);
         $can_approve = $this->can('approve', 'translation-set', $translation_set->id);
         $this->tmpl('translation-row', get_defined_vars());
     } else {
         return $this->die_with_error('Error in retrieving translation!');
     }
 }
 private function get_set_project_and_locale_from_set_id_or_404($set_id)
 {
     $set = GP::$translation_set->get($set_id);
     if (!$set) {
         $this->die_with_404(array('title' => "Translation set wasn't found"));
         return;
     }
     $project = GP::$project->get($set->project_id);
     if (!$project) {
         $this->die_with_404(array('title' => "The project associated with this translation set wasn't found"));
         return;
     }
     $locale = $locale = GP_Locales::by_slug($set->locale);
     if (!$locale) {
         $this->die_with_404(array('title' => "The locale associated with this translation set wasn't found"));
         return;
     }
     return array($set, $project, $locale);
 }
예제 #29
0
 function guess_locale_from_lang($lang)
 {
     if ('en' == $lang || 'en_US' == $lang || !$lang) {
         return 'en_US';
     }
     if (!class_exists('GP_Locales')) {
         if (!defined('JETPACK__GLOTPRESS_LOCALES_PATH') || !file_exists(JETPACK__GLOTPRESS_LOCALES_PATH)) {
             return false;
         }
         require JETPACK__GLOTPRESS_LOCALES_PATH;
     }
     if (defined('IS_WPCOM') && IS_WPCOM) {
         // WP.com: get_locale() returns 'it'
         $locale = GP_Locales::by_slug($lang);
     } else {
         // Jetpack: get_locale() returns 'it_IT';
         $locale = GP_Locales::by_field('wp_locale', $lang);
     }
     if (!$locale) {
         return false;
     }
     if (empty($locale->facebook_locale)) {
         if (empty($locale->wp_locale)) {
             return false;
         } else {
             // Facebook SDK is smart enough to fall back to en_US if a
             // locale isn't supported. Since supported Facebook locales
             // can fall out of sync, we'll attempt to use the known
             // wp_locale value and rely on said fallback.
             return $locale->wp_locale;
         }
     }
     return $locale->facebook_locale;
 }
예제 #30
0
 /**
  * Displays the delete page for glossaries.
  *
  * @since 2.0.0
  *
  * @param int $glossary_id The id of the glossary to delete.
  */
 public function delete_get($glossary_id)
 {
     $glossary = GP::$glossary->get($glossary_id);
     if (!$glossary) {
         $this->redirect_with_error(__('Cannot find glossary.', 'glotpress'));
     }
     if ($this->cannot_delete_glossary_and_redirect($glossary)) {
         return;
     }
     $translation_set = GP::$translation_set->get($glossary->translation_set_id);
     $locale = GP_Locales::by_slug($translation_set->locale);
     $project = GP::$project->get($translation_set->project_id);
     $this->tmpl('glossary-delete', get_defined_vars());
 }