function routes() { $dir = '([^/]+)'; $path = '(.+?)'; $projects = 'projects'; $project = $projects . '/' . $path; $locale = '(' . implode('|', array_map(create_function('$x', 'return $x->slug;'), GP_Locales::locales())) . ')'; // overall structure return apply_filters('routes', array('/' => array('GP_Route_Index', 'index'), 'get:/login' => array('GP_Route_Login', 'login_get'), 'post:/login' => array('GP_Route_Login', 'login_post'), 'get:/logout' => array('GP_Route_Login', 'logout'), "get:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_get'), "post:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_post'), "get:/{$project}/_edit" => array('GP_Route_Project', 'edit_get'), "post:/{$project}/_edit" => array('GP_Route_Project', 'edit_post'), "get:/{$project}/_delete" => array('GP_Route_Project', 'delete_get'), "post:/{$project}/_delete" => array('GP_Route_Project', 'delete_post'), "post:/{$project}/_personal" => array('GP_Route_Project', 'personal_options_post'), "get:/{$projects}" => array('GP_Route_Project', 'index'), "get:/{$projects}/_new" => array('GP_Route_Project', 'new_get'), "get:/{$projects}/_new" => array('GP_Route_Project', 'new_get'), "post:/{$projects}/_new" => array('GP_Route_Project', 'new_post'), "post:/{$project}/{$locale}/{$dir}/_approve" => array('GP_Route_Translation', 'approve_post'), "get:/{$project}/{$locale}/{$dir}" => array('GP_Route_Translation', 'translations_get'), "post:/{$project}/{$locale}/{$dir}" => array('GP_Route_Translation', 'translations_post'), "get:/{$project}/{$locale}/{$dir}/import-translations" => array('GP_Route_Translation', 'import_translations_get'), "post:/{$project}/{$locale}/{$dir}/import-translations" => array('GP_Route_Translation', 'import_translations_post'), "get:/{$project}/{$locale}/{$dir}/_permissions" => array('GP_Route_Translation', 'permissions_get'), "post:/{$project}/{$locale}/{$dir}/_permissions" => array('GP_Route_Translation', 'permissions_post'), "get:/{$project}/{$locale}/{$dir}/_permissions/_delete/{$dir}" => array('GP_Route_Translation', 'permissions_delete'), "post:/{$project}/{$locale}/{$dir}/_discard-warning" => array('GP_Route_Translation', 'discard_warning'), "/{$project}/{$locale}/{$dir}/export-translations" => array('GP_Route_Translation', 'export_translations_get'), "/{$project}" => array('GP_Route_Project', 'single'), "get:/sets/_new" => array('GP_Route_Translation_Set', 'new_get'), "post:/sets/_new" => array('GP_Route_Translation_Set', 'new_post'))); }
function new_get() { $set = new GP_Translation_Set(); $set->project_id = gp_get('project_id'); if ($set->project_id) { $this->can_or_redirect('write', 'project', $set->project_id, gp_url_project(GP::$project->get($set->project_id))); } $all_project_options = self::_options_from_projects(GP::$project->all()); $all_locale_options = self::_options_from_locales(GP_Locales::locales()); gp_tmpl_load('translation-set-new', get_defined_vars()); }
private function default_routes() { $dir = '([^_/][^/]*)'; $path = '(.+?)'; $projects = 'projects'; $project = $projects . '/' . $path; $id = '(\\d+)'; $locale = '(' . implode('|', wp_list_pluck(GP_Locales::locales(), 'slug')) . ')'; $set = "{$project}/{$locale}/{$dir}"; // overall structure return array('/' => array('GP_Route_Index', 'index'), 'get:/profile' => array('GP_Route_Profile', 'profile_get'), "get:/profile/{$path}" => array('GP_Route_Profile', 'profile_view'), 'post:/profile' => array('GP_Route_Profile', 'profile_post'), 'get:/languages' => array('GP_Route_Locale', 'locales_get'), "get:/languages/{$locale}/{$path}" => array('GP_Route_Locale', 'single'), "get:/languages/{$locale}" => array('GP_Route_Locale', 'single'), "get:/{$set}/glossary" => array('GP_Route_Glossary_Entry', 'glossary_entries_get'), "post:/{$set}/glossary" => array('GP_Route_Glossary_Entry', 'glossary_entries_post'), "post:/{$set}/glossary/-new" => array('GP_Route_Glossary_Entry', 'glossary_entry_add_post'), "post:/{$set}/glossary/-delete" => array('GP_Route_Glossary_Entry', 'glossary_entry_delete_post'), "get:/{$set}/glossary/-export" => array('GP_Route_Glossary_Entry', 'export_glossary_entries_get'), "get:/{$set}/glossary/-import" => array('GP_Route_Glossary_Entry', 'import_glossary_entries_get'), "post:/{$set}/glossary/-import" => array('GP_Route_Glossary_Entry', 'import_glossary_entries_post'), "get:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_get'), "post:/{$project}/import-originals" => array('GP_Route_Project', 'import_originals_post'), "get:/{$project}/-edit" => array('GP_Route_Project', 'edit_get'), "post:/{$project}/-edit" => array('GP_Route_Project', 'edit_post'), "post:/{$project}/-personal" => array('GP_Route_Project', 'personal_options_post'), "get:/{$project}/-permissions" => array('GP_Route_Project', 'permissions_get'), "post:/{$project}/-permissions" => array('GP_Route_Project', 'permissions_post'), "get:/{$project}/-permissions/-delete/{$dir}" => array('GP_Route_Project', 'permissions_delete'), "get:/{$project}/-mass-create-sets" => array('GP_Route_Project', 'mass_create_sets_get'), "post:/{$project}/-mass-create-sets" => array('GP_Route_Project', 'mass_create_sets_post'), "post:/{$project}/-mass-create-sets/preview" => array('GP_Route_Project', 'mass_create_sets_preview_post'), "get:/{$project}/-branch" => array('GP_Route_Project', 'branch_project_get'), "post:/{$project}/-branch" => array('GP_Route_Project', 'branch_project_post'), "get:/{$projects}" => array('GP_Route_Project', 'index'), "get:/{$projects}/-new" => array('GP_Route_Project', 'new_get'), "post:/{$projects}/-new" => array('GP_Route_Project', 'new_post'), "post:/{$set}/-bulk" => array('GP_Route_Translation', 'bulk_post'), "get:/{$set}/import-translations" => array('GP_Route_Translation', 'import_translations_get'), "post:/{$set}/import-translations" => array('GP_Route_Translation', 'import_translations_post'), "post:/{$set}/-discard-warning" => array('GP_Route_Translation', 'discard_warning'), "post:/{$set}/-set-status" => array('GP_Route_Translation', 'set_status'), "/{$set}/export-translations" => array('GP_Route_Translation', 'export_translations_get'), "get:/{$set}" => array('GP_Route_Translation', 'translations_get'), "post:/{$set}" => array('GP_Route_Translation', 'translations_post'), "/{$project}" => array('GP_Route_Project', 'single'), "get:/sets/-new" => array('GP_Route_Translation_Set', 'new_get'), "post:/sets/-new" => array('GP_Route_Translation_Set', 'new_post'), "get:/sets/{$id}" => array('GP_Route_Translation_Set', 'single'), "get:/sets/{$id}/-edit" => array('GP_Route_Translation_Set', 'edit_get'), "post:/sets/{$id}/-edit" => array('GP_Route_Translation_Set', 'edit_post'), "get:/glossaries/-new" => array('GP_Route_Glossary', 'new_get'), "post:/glossaries/-new" => array('GP_Route_Glossary', 'new_post'), "get:/glossaries/{$id}/-edit" => array('GP_Route_Glossary', 'edit_get'), "post:/glossaries/{$id}/-edit" => array('GP_Route_Glossary', 'edit_post'), "post:/originals/{$id}/set_priority" => array('GP_Route_Original', 'set_priority')); }
public function locales_get() { if (isset($_GET['all'])) { $locales = GP_Locales::locales(); } else { $existing_locales = GP::$translation_set->existing_locales(); $locales = array(); foreach ($existing_locales as $locale) { $locales[] = GP_Locales::by_slug($locale); } usort($locales, array($this, 'sort_locales')); } $this->tmpl('locales', get_defined_vars()); }
/** * Get the slug from a WPorg slug * * ## OPTIONS * * <wporg-locale> * : WP.org locale slug */ public function __invoke($args) { $wporg_slug = $args[0]; $slug = null; foreach (GP_Locales::locales() as $locale) { if ($locale->wp_locale == $wporg_slug) { $slug = $locale->slug; break; } } if (!$slug) { WP_CLI::error(sprintf(__('No slug match for %s.', 'glotpress'), $wporg_slug)); } WP_CLI::line($slug); }
function run() { if (!isset($this->args[0])) { $this->usage(); } $wporg_slug = $this->args[0]; $slug = null; foreach (GP_Locales::locales() as $locale) { if ($locale->wp_locale == $wporg_slug) { $slug = $locale->slug; break; } } if (!$slug) { $this->to_stderr("No slug match for {$wporg_slug}."); } else { echo $slug; } }
function gp_locales_dropdown($name_and_id, $selected_slug = null, $attrs = array()) { $locales = GP_Locales::locales(); ksort($locales); $options = array('' => __('— Locale —')); foreach ($locales as $key => $locale) { $options[$key] = sprintf('%s — %s', $locale->slug, $locale->english_name); } return gp_select($name_and_id, $options, $selected_slug, $attrs); }
/** * Returns HTML markup for a select element for all locales of a project. * * @since 1.0.0 * * @param int $project_id ID of a project. * @param string $name_and_id Name and ID of the select element. * @param string $selected_slug Slug of the current selected locale. * @param array $attrs Extra attributes. * @return string HTML markup for a select element. */ function gp_locales_by_project_dropdown($project_id, $name_and_id, $selected_slug = null, $attrs = array()) { $locales = GP_Locales::locales(); if (null != $project_id) { $sets = GP::$translation_set->by_project_id($project_id); $temp_locales = array(); foreach ($sets as $set) { $temp_locales[$set->locale] = $locales[$set->locale]; } if (count($temp_locales) > 0) { $locales = $temp_locales; } } ksort($locales); $options = array('' => __('— Locale —', 'glotpress')); foreach ($locales as $key => $locale) { $options[$key] = sprintf('%s — %s', $locale->slug, $locale->english_name); } return gp_select($name_and_id, $options, $selected_slug, $attrs); }
function gp_locales_dropdown($name_and_id, $selected_slug = null, $attrs = array()) { $locales = GP_Locales::locales(); $values = array_map(create_function('$l', 'return $l->slug;'), $locales); $labels = array_map(create_function('$l', 'return $l->slug." — ". $l->english_name;'), $locales); sort($values); sort($labels); return gp_select($name_and_id, array_merge(array('' => __('— Locale —')), array_combine($values, $labels)), $selected_slug, $attrs); }