WordPress.org

Making WordPress.org


Ignore:
Timestamp:
05/15/2015 07:19:57 PM (6 years ago)
Author:
ocean90
Message:

Translate: "Locales & Languages" page:

  • Copy GlotPress' locale template to our theme.
  • Move index and locale routes do its own files.
  • Register routes for /language/$locale/$set/$project.

see #994.

Location:
sites/trunk/translate.wordpress.org/includes/gp-plugins/wporg-routes/routes
Files:
1 added
1 copied

Legend:

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

    r1580 r1586  
    11<?php
    22/**
    3  * This plugins overrides some of the default routes of GlotPress.
     3 * Index Route Class.
    44 *
    5  * @author ocean90
     5 * Provides the route for translate.wordpress.org/.
    66 */
    7 class GP_WPorg_Routes extends GP_Plugin {
    8     public $id = 'wporg-routes';
    9 
    10     public function __construct() {
    11         parent::__construct();
    12         $this->add_action( 'init' );
    13     }
    14 
    15     public function init() {
    16         /*
    17          * Unset default routes.
    18          * The `routes` filter can't be used, see https://glotpress.trac.wordpress.org/ticket/249.
    19          */
    20         unset( GP::$router->urls['/'] );
    21         unset( GP::$router->urls['get:/languages'] );
    22 
    23         GP::$router->add( '/', array( 'GP_WPorg_Route_Index', 'index' ) );
    24         GP::$router->add( '/languages', array( 'GP_WPorg_Route_Locale', 'locales_get' ) );
    25     }
    26 }
    27 
    28 class GP_WPorg_Route_Locale extends GP_Route {
    29 
    30     public function locales_get() {
    31         $locales = array();
    32         $existing_locales = GP::$translation_set->existing_locales();
    33         foreach ( $existing_locales as $locale ) {
    34             $locales[] = GP_Locales::by_slug( $locale );
    35         }
    36         usort( $locales, array( $this, 'sort_locales') );
    37         unset( $existing_locales );
    38 
    39         $contributors_count = wp_cache_get( 'contributors-count', 'wporg-translate' );
    40         if ( false === $contributors_count ) {
    41             $contributors_count = array();
    42         }
    43 
    44         $translation_status = wp_cache_get( 'translation-status', 'wporg-translate' );
    45         if ( false === $translation_status ) {
    46             $translation_status = array();
    47         }
    48 
    49         $this->tmpl( 'locales', get_defined_vars() );
    50     }
    51 
    52     private function sort_locales( $a, $b ) {
    53         return $a->english_name > $b->english_name;
    54     }
    55 }
    56 
    577class GP_WPorg_Route_Index extends GP_Route {
    588
    59     public function index() {
     9    public function get_index() {
    6010        $this->redirect( gp_url( '/languages' ) );
    6111    }
    6212}
    63 
    64 GP::$plugins->wporg_routes = new GP_WPorg_Routes;
Note: See TracChangeset for help on using the changeset viewer.