Plugin Directory

Changeset 676953

Timestamp:
03/06/2013 04:56:12 PM (11 years ago)
Author:
stephenh1988
Message:

Merging 1.7.1

Location:
wcm-user-language-switcher/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • wcm-user-language-switcher/trunk/.gitignore

    r654894 r676953  
    22.DSSTORE
    33.gitignore
     4
     5
     6
    47
    58# SVN
     
    2023.settings
    2124
    22 # PSD
    23 .psd/*
    24 .psd
     25# PSD
     26/*
     27.
  • wcm-user-language-switcher/trunk/README.md

    r654894 r676953  
    33<img width="150" height="150" src="https://raw.github.com/wecodemore/wcm_lang_switch/master/assets/logo.png" />
    44
    5 **Contributors:** [Stephen Harris](https://github.com/stephenh1988), [Franz Josef Kaiser](https://github.com/franz-josef-kaiser)
     5**Contributors:** [Stephen Harris](https://github.com/stephenh), [Franz Josef Kaiser](https://github.com/franz-josef-kaiser)
    66**Tags:** Language, switcher, localisation
    7 **Tested up to:** 3.5
    8 **Stable tag:** 1.6.1
    9 **Requires at least:** 3.5
     7**Tested up to:** 3.5
     8**Stable tag:** 1..1
     9**Requires at least:** 3.5
    1010**License:** GPL3
    1111**License URI:** http://www.gnu.org/licenses/gpl-3.0.html
     
    2828Extract the zip file and just drop the contents in the `~/wp-content/plugins/` directory of your WordPress installation and then activate the Plugin from Plugins page.
    2929
    30     It scans the language directory to build the list of available languages. To add a language, simple [download the appropriate mo file](http://codex.wordpress.org/WordPress_in_Your_Language) and add to your WordPress `languages` folder.
     30It scans the language directory to build the list of available languages. To add a language, simple [download the appropriate mo file](http://codex.wordpress.org/WordPress_in_Your_Language) and add to your WordPress `languages` folder.
    3131
    3232This plugin was originally built as a means of plugin and theme developers to test translations of their plugins or themes.
     
    4040    <?php
    4141    /* Plugin Name:** (WCM) Add additional languages */
    42     add_filter( 'uls_get_langs', 'wcm_add_languages' );
     42    add_filter( '_get_langs', 'wcm_add_languages' );
    4343    function wcm_add_languages( $languages )
    4444    {
     
    5757
    5858## Changelog ##
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
    5994
    6095### 1.6 ###
  • wcm-user-language-switcher/trunk/dev_tools.class.php

    r654894 r676953  
    88 * @since      1.3
    99 */
    10 class WCMUserLangSelectDevTools extends WCMUserLangSelect
     10class WCM
    1111{
    1212    public function __construct()
     
    7171                // If we found one, assign it to the array, else empty
    7272                $nn = ! $nn ? $string : ucwords( $native[ $nn ]['nativeName'] );
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
     91
     92
     93
     94
     95
     96
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
    73126                $output[ $l ] = array(
    74                      'int'    => $string
    75                     ,'native' => $nn
     127                     'int'    =>
     128                    ,'native' =>
    76129                );
    77130            }
     
    81134            return;
    82135
    83         # Test if native strings work
    84         # foreach ( $output as $k => $v )
    85         #   printf ( "<p>%s</p>", $v['native'] );
    86 
    87         $output = json_encode( $output );
    88         $output_raw = $this->beautify_json( $output );
    89 
     136        # Output for a complete ISO 639-2 list
     137        /* printf(
     138            '<textarea rows="5" cols="104">%s</textarea>'
     139            ,json_encode( $output )
     140        );*/
     141
     142        // Only use the first string for WP UI
     143        foreach ( $output as $code => $out )
     144            foreach ( $out as $k => $o )
     145            {
     146                $output[ $code ][ $k ] = array_shift( $o );
     147            }
     148
     149        printf ( '<p>%s</p>', 'Number of languages' );
     150        printf(
     151            '<input type="text" value="%s" />'
     152            ,count( $output )
     153        );
    90154        printf ( '<p>%s</p>', 'Readable' );
    91155        printf(
    92156            '<textarea rows="5" cols="104">%s</textarea>'
    93             ,$output_raw
     157            ,$
    94158        );
    95159        printf ( '<p>%s</p>', 'Compressed' );
    96160        printf(
    97161             '<textarea rows="5" cols="104">%s</textarea>'
    98             ,$output
     162            ,
    99163        );
    100164
    101165        return;
    102166        # Remove the above `return;` to get a DIFF of the changes
    103         $this->diff_json( $output_raw );
     167        $this->diff_json( $ );
    104168    }
    105169
     
    143207        $output_current = file_get_contents( plugin_dir_path( __FILE__ ).'/json/lang_codes.json' );
    144208        print wp_text_diff(
    145             var_export( $output_current, true )
     209            var_export( $output_current, true )
    146210            ,var_export( $output_remote, true )
    147211            ,array(
    148                 'title'       => 'Dev: Changes since last JSON file fetch'
    149             ,'title_left'  => 'Current data'
    150             ,'title_right' => 'New fetched data'
     212                'title'       => 'Dev: Changes since last JSON file fetch'
     213            ,'title_left'  => 'Current data'
     214            ,'title_right' => 'New fetched data'
    151215            )
    152216        );
  • wcm-user-language-switcher/trunk/readme.txt

    r654894 r676953  
    22Contributors: stephenharris, F J Kaiser
    33Tags: Language, switcher, localisation
    4 Tested up to: 3.5
    5 Stable tag: 1.6.1
     4Tested up to: 3.5
     5Stable tag: 1..1
    66Requires at least: 3.5
    77License: GPL3
     
    3838    <?php
    3939    /* Plugin Name: (WCM) Add additional languages */
    40     add_filter( 'uls_get_langs', 'wcm_add_languages' );
     40    add_filter( '_get_langs', 'wcm_add_languages' );
    4141    function wcm_add_languages( $languages )
    4242    {
     
    5454
    5555== Changelog ==
     56
     57
     58
     59
     60
     61
     62
     63
     64
     65
     66
     67
     68
     69
     70
     71
     72
     73
     74
     75
     76
     77
     78
     79
     80
     81
     82
     83
     84
     85
     86
     87
     88
     89
     90
    5691
    5792= 1.6 =
  • wcm-user-language-switcher/trunk/wcm_lang_switch.class.php

    r654894 r676953  
    11<?php
    2 ! defined( 'ABSPATH' ) AND exit;
     2 exit;
    33/*
    44Plugin Name:  User Language Switcher
     
    77Author:       Stephen Harris
    88Author URI:   https://plus.google.com/b/109907580576615571040/109907580576615571040/posts
    9 Contributors: Franz Josef Kaiser
    10 Version:      1.6.1
     9Contributors: Franz Josef Kaiser
     10Version:      1..1
    1111License:      GNU GPL 3
    1212*/
     
    1414
    1515# PUBLIC API #
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
    1628/**
    1729 * A function returns with returns the user's selected locale, if stored.
    1830 *
    1931 * @since  0.1
    20  *
    2132 * @param  bool $locale
    22  * @return mixed string/bool $locale
     33 * @return mixed string/bool $locale
    2334 */
    24 function wcm_get_user_locale( $locale = false )
     35function wcm_get_user_l( $locale = false )
    2536{
    26     if ( $new_locale = get_user_meta(
     37    if ( $ = get_user_meta(
    2738         get_current_user_id()
    2839        ,'user_language'
    2940        ,true
    3041    ) )
    31          return $new_locale;
     42         return $;
    3243
    3344    return $locale;
    3445}
    3546
    36 add_action( 'plugins_loaded', array( 'WCMUserLangSelect', 'init' ) );
    37 
     47add_action( 'plugins_loaded', array( 'WCM_User_Lang_Switch', 'init' ), 5 );
    3848/**
    3949 * Allows the user to change the systems language.
     
    4858 * @subpackage User Language Change
    4959 */
    50 class WCMUserLangSelect
     60class WCM
    5161{
    5262    /**
     
    6575     * @var    string
    6676     */
    67     static public $name = 'uls_pick_lang';
     77    static public $name = '_lang';
    6878
    6979    /**
     
    8898     * @since  0.2
    8999     * @static
    90      * @return void
     100     * @return
    91101     */
    92102    static public function init()
    93103    {
    94         is_null( self :: $instance ) AND self :: $instance = new self;
    95         return self :: $instance;
     104        $instance = new self;
     105        return self$instance;
    96106    }
    97107
     
    118128        }
    119129
    120         ! defined( 'WPLANG' ) AND define( 'WPLANG', $meta );
     130        defined( 'WPLANG' )
     131            OR define( 'WPLANG', $meta );
    121132
    122133        // Use the global $locale instead of get_locale() to prevent endless loops
     
    130141     * Hook the functions
    131142     * @since  0.1
    132      * @return \WCMUserLangSelect
     143     * @return \WCM
    133144     */
    134145    public function __construct()
    135146    {
    136         if ( isset( $_REQUEST[ self :: $name ] ) )
     147        if ( isset( $_REQUEST[ self$name ] ) )
    137148            add_action( 'locale', array( $this, 'update_user' ) );
    138149
    139         add_filter( 'locale', 'wcm_get_user_locale', 20 );
     150        add_filter( 'locale', 'wcm_get_user_l', 20 );
    140151        add_action( 'wp_before_admin_bar_render', array( $this, 'admin_bar') );
    141152
     
    158169             get_current_user_id()
    159170            ,'user_language'
    160             ,$_REQUEST[ self :: $name ]
     171            ,$_REQUEST[ self$name ]
    161172        );
    162173
    163         return wcm_get_user_locale( $locale );
     174        return wcm_get_user_l( $locale );
    164175    }
    165176
     
    168179     * The 'drop down' for the admin bar
    169180     *
    170      * Based on Thomas "toscho" Scholz answer on the following WPSE question by Stephen Harris:
    171      * @link http://wordpress.stackexchange.com/questions/57606/obtain-a-list-of-available-translations/57609
     181     * Based on Thomas "toscho" Scholz answer on the following WPSE question by Stephen Harris:
     182     * @link http://
    172183     *
    173184     * @since   0.1
     
    184195        $locale  = get_locale();
    185196
    186         $wp_admin_bar->add_menu( array(
    187              'id'    => 'user_lang_pick'
    188             ,'title' => $this->format_code_lang( $locale )
     197        $current = $this->format_code_lang( $locale );
     198        $wp_admin_bar->add_node( array(
     199             'id'    => 'wcm_user_lang_pick'
     200            ,'title' => $current
    189201            ,'href'  => '#'
     202
     203
     204
    190205        ) );
    191206
     
    194209            $name = $this->format_code_lang( $lang );
    195210            $link = add_query_arg(
    196                  self :: $name
     211                 self$name
    197212                ,$lang
    198213            );
    199214
    200             $locale == $lang AND $name = sprintf(
     215            $locale == $lang AND $name = sprintf(
    201216                 '<strong> %s </strong>'
    202217                ,$name
    203             );
    204 
    205             $wp_admin_bar->add_menu( array(
    206                  'parent' => 'user_lang_pick'
    207                 ,'id'     => "user_lang_pick_lang_{$lang}"
     218            );*/
     219
     220            // Don't add the current language as menu item
     221            if ( $lang === wcm_get_user_lang( 'en_US' ) )
     222                continue;
     223
     224            $wp_admin_bar->add_node( array(
     225                 'parent' => 'wcm_user_lang_pick'
     226                ,'id'     => "wcm_user_lang_pick-{$lang}"
    208227                ,'title'  => $name
    209228                ,'href'   => $link
     229
     230
     231
     232
     233
     234
     235
     236
    210237            ) );
    211238        }
     
    216243     * Get Languages
    217244     * @since  0.3
    218      * @return void
     245     * @return
    219246     */
    220247    public function get_langs()
    221248    {
    222         return apply_filters( 'uls_get_langs', array_merge(
     249        return apply_filters( '_get_langs', array_merge(
    223250             get_available_languages()
    224251            ,array( 'en_US' )
     
    236263     * @since  0.2
    237264     * @link   http://codex.wordpress.org/Function_Reference/format_code_lang
    238          *
     265     *
    239266     * @param  string $code Language code, e.g. en_US or en
    240      * @return string The human readable language name, e.g. 'English' or the input on Error.
     267     * @param  string $part Which part to return: International or native name?
     268     * @return string The human readable language name, e.g. 'English', or the input on Error.
    241269    */
    242     public function format_code_lang( $code = '' )
    243     {
    244 
     270    public function format_code_lang( $code = '', $part = 'native' )
     271    {
    245272        $label_code = strtok( strtolower( $code ), "_" );
    246         if ( is_null( self :: $lang_codes ) )
    247             self :: $lang_codes =  json_decode( reset( file( plugin_dir_path( __FILE__ ).'/json/lang_codes.min.json' ) ), true );
    248 
    249         if ( 0 !== json_last_error() )
     273        if ( null === self::$lang_codes )
     274        {
     275            $iso_639_2 = file( plugin_dir_path( __FILE__ ).'/json/lang_codes.min.json' );
     276            self::$lang_codes = json_decode( reset( $iso_639_2 ), true );
     277        }
     278
     279        # PHP >= 5.3.0 only...
     280        # if ( 0 !== json_last_error() )
     281        if ( ! empty( self::$lang_codes['error'] ) )
    250282            return $code;
    251283
    252         $lang_codes = apply_filters( 'lang_codes', self :: $lang_codes, $code );
    253         $user_locale = wcm_get_user_locale( 'en_US' );
     284        $lang_codes = apply_filters( 'wcm_lang_codes', self::$lang_codes, $code );
    254285
    255286        if ( ! isset( $lang_codes[ $label_code ] ) )
    256287            return $code;
    257         if( $user_locale == $code )
    258             return $lang_codes[ $label_code ][ 'native' ];
    259         else
    260             return $lang_codes[ $label_code ][ 'int' ];
     288
     289        return $lang_codes[ $label_code ][ $part ];
    261290    }
    262291
     
    270299
    271300        include_once plugin_dir_path( __FILE__ ).'/dev_tools.class.php';
    272         new WCMUserLangSelectDevTools();
     301        new WCMDevTools();
    273302    }
    274303}
Note: See TracChangeset for help on using the changeset viewer.