Making WordPress.org

Changeset 1721


Ignore:
Timestamp:
07/10/2015 05:29:36 PM (9 years ago)
Author:
ocean90
Message:

Translate: Improve custom routes.

  • Don't register custom routes for API request.
  • Move locale overview to translate.wordpress.org, no redirect anymore.
  • Replace /languages prefix with /locale.
  • Redirect old /languages URLs to the new route.
  • Rename custom templates.

see #994, #1091.

Location:
sites/trunk/translate.wordpress.org
Files:
1 added
4 edited
2 moved

Legend:

Unmodified
Added
Removed
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/routes/index.php

    r1586 r1721  
    77class GP_WPorg_Route_Index extends GP_Route {
    88
    9     public function get_index() {
    10         $this->redirect( gp_url( '/languages' ) );
     9    /**
     10     * Prints all exisiting locales as cards.
     11     */
     12    public function get_locales() {
     13        $locales = array();
     14        $existing_locales = GP::$translation_set->existing_locales();
     15        foreach ( $existing_locales as $locale ) {
     16            $locales[] = GP_Locales::by_slug( $locale );
     17        }
     18        usort( $locales, array( $this, '_sort_english_name_callback') );
     19        unset( $existing_locales );
     20
     21        $contributors_count = wp_cache_get( 'contributors-count', 'wporg-translate' );
     22        if ( false === $contributors_count ) {
     23            $contributors_count = array();
     24        }
     25
     26        $translation_status = wp_cache_get( 'translation-status', 'wporg-translate' );
     27        if ( false === $translation_status ) {
     28            $translation_status = array();
     29        }
     30
     31        $this->tmpl( 'index-locales', get_defined_vars() );
     32    }
     33
     34    private function _sort_english_name_callback( $a, $b ) {
     35        return $a->english_name > $b->english_name;
    1136    }
    1237}
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/routes/locale.php

    r1686 r1721  
    33 * Locale Route Class.
    44 *
    5  * Provides the route for translate.wordpress.org/languages.
     5 * Provides the route for translate.wordpress.org/locale/$locale.
    66 */
    77class GP_WPorg_Route_Locale extends GP_Route {
    8 
    9     /**
    10      * Prints all exisiting locales as cards.
    11      */
    12     public function get_locales() {
    13         $locales = array();
    14         $existing_locales = GP::$translation_set->existing_locales();
    15         foreach ( $existing_locales as $locale ) {
    16             $locales[] = GP_Locales::by_slug( $locale );
    17         }
    18         usort( $locales, array( $this, '_sort_english_name_callback') );
    19         unset( $existing_locales );
    20 
    21         $contributors_count = wp_cache_get( 'contributors-count', 'wporg-translate' );
    22         if ( false === $contributors_count ) {
    23             $contributors_count = array();
    24         }
    25 
    26         $translation_status = wp_cache_get( 'translation-status', 'wporg-translate' );
    27         if ( false === $translation_status ) {
    28             $translation_status = array();
    29         }
    30 
    31         $this->tmpl( 'locales', get_defined_vars() );
    32     }
    338
    349    /**
     
    7853        $variants = $this->get_locale_variants( $locale_slug, array_keys( $project_status ) );
    7954
    80         $this->tmpl( 'locale', get_defined_vars() );
     55        $this->tmpl( 'locale-projects', get_defined_vars() );
    8156    }
    8257
     
    285260        return strcasecmp( $a->name, $b->name );
    286261    }
    287 
    288     private function _sort_english_name_callback( $a, $b ) {
    289         return $a->english_name > $b->english_name;
    290     }
    291262}
  • sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/wporg-routes.php

    r1684 r1721  
    11<?php
    22/**
    3  * This plugins overrides some of the default routes of GlotPress.
     3 * Register custom routes for translate.wordpress.org.
    44 *
    55 * @author ocean90
    66 */
    77
     8require_once __DIR__ . '/routes/redirector.php';
    89require_once __DIR__ . '/routes/index.php';
    910require_once __DIR__ . '/routes/locale.php';
     
    1819
    1920    public function init() {
     21        // Bail for API requests.
     22        $request_uri = GP::$router->request_uri();
     23        if ( gp_startswith( $request_uri, '/' . GP::$router->api_prefix . '/' ) ) {
     24            return;
     25        }
     26
    2027        $path = '(.+?)';
    2128        $locale = '(' . implode( '|', array_map( function( $locale ) { return $locale->slug; }, GP_Locales::locales() ) ) . ')';
    2229
    23         /*
    24          * Unset default routes.
    25          * The `routes` filter can't be used, see https://glotpress.trac.wordpress.org/ticket/249.
    26          */
     30        // Unset default routes.
    2731        unset( GP::$router->urls['/'] );
    2832        unset( GP::$router->urls["get:/languages/$locale/$path"] );
     
    3034        unset( GP::$router->urls['get:/languages'] );
    3135
    32         GP::$router->add( '/', array( 'GP_WPorg_Route_Index', 'get_index' ) );
    33         GP::$router->add( "/languages/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
    34         GP::$router->add( "/languages/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    35         GP::$router->add( "/languages/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    36         GP::$router->add( "/languages/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    37         GP::$router->add( '/languages', array( 'GP_WPorg_Route_Locale', 'get_locales' ) );
     36        // Redirect routes.
     37        GP::$router->add( "/languages/$path", array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     38        GP::$router->add( '/languages', array( 'GP_WPorg_Route_Redirector', 'redirect_languages' ) );
     39
     40        // Register custom routes.
     41        GP::$router->add( '/', array( 'GP_WPorg_Route_Index', 'get_locales' ) );
     42        GP::$router->add( "/locale/$locale/$path/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_project' ) );
     43        GP::$router->add( "/locale/$locale/$path/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     44        GP::$router->add( "/locale/$locale/$path", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
     45        GP::$router->add( "/locale/$locale", array( 'GP_WPorg_Route_Locale', 'get_locale_projects' ) );
    3846    }
    3947}
  • sites/trunk/translate.wordpress.org/public_html/gp-templates/index-locales.php

    r1706 r1721  
    3030            <div class="locale <?php echo 'percent-' . $percent_complete; ?>">
    3131                <ul class="name">
    32                     <li class="english"><?php echo gp_link_get( gp_url_join( gp_url_current(), $locale->slug ), $locale->english_name ) ?></li>
    33                     <li class="native"><?php echo gp_link_get( gp_url_join( gp_url_current(), $locale->slug ), $locale->native_name ) ?></li>
    34                     <li class="code"><?php echo gp_link_get( gp_url_join( gp_url_current(), $locale->slug ), $wp_locale ) ?></li>
     32                    <li class="english"><?php echo gp_link_get( gp_url_join( '/locale', $locale->slug ), $locale->english_name ) ?></li>
     33                    <li class="native"><?php echo gp_link_get( gp_url_join( '/locale', $locale->slug ), $locale->native_name ) ?></li>
     34                    <li class="code"><?php echo gp_link_get( gp_url_join( '/locale', $locale->slug ), $wp_locale ) ?></li>
    3535                </ul>
    3636                <div class="contributors">
     
    4848                <div class="locale-button">
    4949                    <div class="button contribute-button">
    50                         <?php echo gp_link_get( gp_url_join( gp_url_current(), $locale->slug ), 'Contribute Translation' ) ?>
     50                        <?php echo gp_link_get( gp_url_join( '/locale', $locale->slug ), 'Contribute Translation' ) ?>
    5151                    </div>
    5252                </div>
  • sites/trunk/translate.wordpress.org/public_html/gp-templates/locale-project.php

    r1685 r1721  
    33
    44$breadcrumb   = array();
    5 $breadcrumb[] = gp_link_get( '/languages', __( 'Locales' ) );
    6 $breadcrumb[] = gp_link_get( gp_url_join( '/languages', $locale_slug, $set_slug), esc_html( $locale->english_name ) );
     5$breadcrumb[] = gp_link_get( '/', __( 'Locales' ) );
     6$breadcrumb[] = gp_link_get( gp_url_join( '/locale', $locale_slug, $set_slug), esc_html( $locale->english_name ) );
    77$breadcrumb[] = $sub_project->name;
    88gp_breadcrumb( $breadcrumb );
     
    3636                                    '<option name="%s" data-project-url="%s"%s>%s</option>',
    3737                                    $variant,
    38                                     esc_url( gp_url_join( '/languages', $locale_slug, $variant, $sub_project->path ) ),
     38                                    esc_url( gp_url_join( '/locale', $locale_slug, $variant, $sub_project->path ) ),
    3939                                    ( $set_slug == $variant ) ? ' selected="selected"' : '',
    4040                                    ucfirst( $variant )
  • sites/trunk/translate.wordpress.org/public_html/gp-templates/locale-projects.php

    r1706 r1721  
    33
    44$breadcrumb   = array();
    5 $breadcrumb[] = gp_link_get( '/languages', __( 'Locales' ) );
     5$breadcrumb[] = gp_link_get( '/', __( 'Locales' ) );
    66$breadcrumb[] = esc_html( $locale->english_name );
    77gp_breadcrumb( $breadcrumb );
     
    2929                                '<option name="%s" data-project-url="%s"%s>%s</option>',
    3030                                $variant,
    31                                 esc_url( gp_url_join( '/languages', $locale_slug, $variant, $project->slug ) ),
     31                                esc_url( gp_url_join( '/locale', $locale_slug, $variant, $project->slug ) ),
    3232                                ( $set_slug == $variant ) ? ' selected="selected"' : '',
    3333                                ucfirst( $variant )
     
    5959            printf(
    6060                '<li><a href="%s"%s>%s</a></li>',
    61                 gp_url_join( '/languages', $locale_slug, $set_slug, $top_level_project->slug ),
     61                gp_url_join( '/locale', $locale_slug, $set_slug, $top_level_project->slug ),
    6262                ( $top_level_project->path == $project_path ) ? ' class="current"' : '',
    6363                $top_level_project->name
     
    8383        }
    8484
    85         $project_url = gp_url_join( '/languages', $locale_slug, $set_slug, $sub_project->path );
     85        $project_url = gp_url_join( '/locale', $locale_slug, $set_slug, $sub_project->path );
    8686
    8787        $project_icon = '';
Note: See TracChangeset for help on using the changeset viewer.