Plugin Directory

Changeset 363827


Ignore:
Timestamp:
03/23/2011 05:30:02 PM (15 years ago)
Author:
stevevls
Message:

1.1.3:

  • General support for non-latin languages
  • Support for translation from English to Russian
  • Improved localization using dynamically-loaded .mo files
  • WP 3.1 : category and tag links weren't properly due to iternal changes and admin pages
  • WP 3.1 : avoid link rewriting for admin bar links when looking at page with non-source language.
Location:
gts-translation/trunk
Files:
113 added
8 edited

Legend:

Unmodified
Added
Removed
  • gts-translation/trunk/Gts.php

    r332072 r363827  
    3737Plugin URI: http://gts-translation.com/
    3838Description: The only translation plugin that provides human translation of your blog content using community translation (crowdsourcing). Use our community of professional translators or use your own internal community. Currently supports French, Italian, German, Spanish (FIGS). All content is cached on your Wordpress database and indexed by search engines.
    39 Version: 1.1.2
     39Version: 1.1.3
    4040Author: Steve van Loben Sels
    4141Author URI: http://gts-translation.com/
  • gts-translation/trunk/GtsPlugin.php

    r322662 r363827  
    193193        }
    194194       
    195         return strtolower( sha1( $auth['code'] . '~' . $auth['email'] . '~' . $this->do_without_language( array( $this, 'callback_get_home' ) ) ) );
     195        return strtolower( sha1( $auth['code'] . '~' . strtolower($auth['email']) . '~' . $this->do_without_language( array( $this, 'callback_get_home' ) ) ) );
    196196    }
    197197
  • gts-translation/trunk/callbacks/gts-get-terms.php

    r288004 r363827  
    3434require_once('../GtsPlugin.php');
    3535
    36 $terms = get_terms( array( 'category', 'post_tag' ), array( 'get' => 'all' ) );
     36$taxonomies = array();
     37foreach( get_taxonomies( array(), 'objects' ) as $taxonomy ) {
     38    if ( in_array( 'post', $taxonomy->object_type ) ) {
     39        array_push( $taxonomies, $taxonomy->name );
     40    }
     41}
     42
     43$terms = get_terms( $taxonomies, array( 'hide_empty' => true ) );
     44
    3745$output_xml = new com_gts_Terms();
    3846foreach( $terms as $term ) {
  • gts-translation/trunk/lib/Language.php

    r288004 r363827  
    4949    var $input;
    5050    var $output;
     51    var $latin;
    5152
    52     function __construct( $code, $name, $englishName, $input, $output ) {
     53    function __construct( $code, $name, $englishName, $input, $output, $latin ) {
    5354        $this->code = $code;
    5455        $this->name = $name;
     
    5657        $this->input = $input;
    5758        $this->output = $output;
     59        $this->latin = $latin;
    5860    }
    5961
     
    9294com_gts_Language::set_arrays(com_gts_Language::$ALL_LANGUAGES, com_gts_Language::$ALL_LANGUAGE_CODES, array(
    9395
    94     new com_gts_Language("en", "English", "English", true, false),
     96    new com_gts_Language("en", "English", "English", true, false, true),
    9597
    96     new com_gts_Language("de", "Deutsch", "German", false, true),
    97     new com_gts_Language("es", "Español", "Spanish", false, true),
    98     new com_gts_Language("fr", "Français", "French", false, true),
    99     new com_gts_Language("it", "Italiano", "Italian", false, true),
     98    new com_gts_Language("de", "Deutsch", "German", false, true, true),
     99    new com_gts_Language("es", "Español", "Spanish", false, true, true),
     100    new com_gts_Language("fr", "Français", "French", false, true, true),
     101    new com_gts_Language("it", "Italiano", "Italian", false, true, true),
     102    new com_gts_Language("ru", "русский язык", "Russian", false, true, false),
    100103));
    101104
  • gts-translation/trunk/readme.txt

    r332072 r363827  
    33Tags: translate, translation, crowdsourcing
    44Requires at least: 2.9.0
    5 Tested up to: 3.0.4
    6 Stable tag: 1.1.2
     5Tested up to: 3.1
     6Stable tag: 1.1.3
    77
    88The only translation plugin that provides human translation of your blog content using community translation
     
    160160
    161161== Changelog ==
     162
     163= 1.1.3 =
     164* General support for non-latin languages
     165* Support for translation from English to Russian
     166* Improved localization using dynamically-loaded .mo files
     167* WP 3.1 : category and tag links weren't properly due to iternal changes and admin pages
     168* WP 3.1 : avoid link rewriting for admin bar links when looking at page with non-source language.
    162169
    163170= 1.1.2 =
  • gts-translation/trunk/wordpress/GtsLinkRewriter.php

    r332072 r363827  
    6767    function register_plugin_hooks() {
    6868
     69        global $wp_version;
     70
    6971        $flush_callback = array( $this, 'flush_rewrite_rules' );
    7072
     
    8385
    8486        // these work together with the filters in GtsPluginWordpress to change the hostname.
    85         // todo : should look at unifying them!
    86         add_filter( 'option_home', array($this, 'add_language_to_home'), 1);
    87         add_filter( 'option_siteurl', array($this, 'add_language_to_home'), 1);
     87        // they're used at different times and places in WP (though i think they're trying to fix that in
     88        // some release...we still have to support 2.9+).  if we have version 3+, we'll use the siteurl filter
     89        // so that we also get the path we're modifying so we can avoid rewriting admin links.  in 2.X, it looks
     90        // like admin links go a different route, so we don't need to worry about them.  what a pain!
     91        add_filter( 'option_home', array($this, 'add_language_to_home'), 1 );
     92        add_filter( preg_match( '/^[12]\./', $wp_version ? 'option_' : '') + 'siteurl', array($this, 'add_language_to_home'), 2 );
    8893
    8994        add_filter( 'post_link', array($this, 'rewrite_post_link'), 1, 2 );
     
    96101
    97102
    98     function add_language_to_home( $link ) {
     103    function add_language_to_home( $link, $path ) {
    99104
    100105        global $gts_plugin, $wp_rewrite;
    101         if( $gts_plugin->language && $wp_rewrite->permalink_structure ) {
     106        if( $gts_plugin->language && $wp_rewrite->permalink_structure && !preg_match( '/^\/?wp\-admin\//', $path) ) {
    102107            $link = untrailingslashit($link) . '/language/' . $gts_plugin->language;
    103108        }
     
    244249        // i tried tracking down why it wasn't getting set to no avail, so the easiest thing to do is just
    245250        // insert the language right here.
    246         global $gts_plugin;
     251        global $gts_plugin, $wp_rewrite;
    247252        if( $gts_plugin->language && !$query_vars[GtsLinkRewriter::$LANG_PARAM] ) {
    248253            $query_vars[GtsLinkRewriter::$LANG_PARAM] = $gts_plugin->language;
     254        }
     255
     256        // WP 3.1 compatibility (and b/w compatibile)...  starting with WP3.1, a custom taxonomy query no longer sets
     257        // the term query var.  but our code depends on it, so we'll just fake it.  this is a two
     258        // part hack b/c later we'll have to take from the term and substitute it back into the taxonomy.
     259        $taxonomies = get_taxonomies(array(), 'objects');
     260        foreach( $taxonomies as $taxonomy ) {
     261            if( !$taxonomy->_builtin && $query_vars[ $taxonomy->query_var ] && !$query_vars[ 'term' ] ) {
     262                $query_vars[ 'term' ] = $query_vars[ $taxonomy->query_var ];
     263            }
     264        }
     265
     266        // this is for non-western character support in permalinks...  the values won't have been URL decoded
     267        // yet b/c WP is expecting ASCII...  only mess with values that we know can contain UTF-8 chars.
     268        if( $wp_rewrite->permalink_structure && $langCode = $query_vars[GtsLinkRewriter::$LANG_PARAM] ) {
     269            $langObj = com_gts_Language::get_by_code( $langCode );
     270            if( !$langObj->latin ) {
     271                foreach ( array( 'tag', 'name', 'category_name', 'term', 'pagename' ) as $param_name ) {
     272                    if ( $query_vars[ $param_name ] ) {
     273
     274                        // this value *should* be url encoded.  if it came in via get parameters, then
     275                        // it will have been decoded already, but we also wouldn't enter into this loop!
     276                        $encoded_val = $query_vars[ $param_name ];
     277                        $query_vars[ $param_name ] = urldecode( $query_vars[ $param_name ] );
     278
     279                        // more permalink madness.  when WP goes through to attempt canonicalization, it looks at the
     280                        // $_SERVER array for the REQUEST_URI.  it then "sanitizes" it, which for us means removing all
     281                        // extended UTF-8 characters.  we'll need to fix that here or risk categories not working...
     282                        if ( $encoded_val != $query_vars[ $param_name ] ) {
     283                            $_SERVER['REQUEST_URI'] = str_replace( $encoded_val, $query_vars[ $param_name ], $_SERVER['REQUEST_URI'] );
     284                        }
     285                    }
     286                }
     287            }
    249288        }
    250289
     
    252291        // difficult to tell the difference between pages and posts in that case b/c WP gets silly about matching.
    253292        // so, if we find an attachment, there's a decent chance that it's actually a nested page.  check for it!
    254         global $wp_rewrite;
    255293        if( preg_match('/^\/%postname%(\/)?$/', $wp_rewrite->permalink_structure) && $query_vars['attachment'] ) {
    256294            global $gts_plugin;
     
    289327            $query_vars[GtsLinkRewriter::$PAGEPATH_PARAM] = $query_vars['pagename'];
    290328        }
    291        
     329
     330        // WP 3.1 custom taxonomy part 2...  now that we have the original term text, overwrite the custom
     331        // taxonomy's query variable value with the source text.
     332        foreach( $taxonomies as $taxonomy ) {
     333            if( !$taxonomy->_builtin && $query_vars[ $taxonomy->query_var ] && $query_vars[ 'term' ] ) {
     334                $query_vars[ $taxonomy->query_var ] = $query_vars[ 'term' ];
     335            }
     336        }
     337
    292338        return $query_vars;
    293339    }
     
    389435        // only bother messing with this stuff if we have permalinks enabled.
    390436        // otherwise, we just do like WP and return the empty rules array.
    391         if($wp_rewrite->permalink_structure) {
     437        if( $wp_rewrite->permalink_structure ) {
    392438
    393439            $wp_rewrite->add_rewrite_tag('%'.GtsLinkRewriter::$LANG_PARAM.'%', '([a-z]{2})', GtsLinkRewriter::$LANG_PARAM . '=' );
     
    399445            $newrules = array();
    400446
     447
     448            // GENERAL NOTE : in WP < 3.1, most of the permastructs did not have a leading slash.  in 3.1, they started putting slashes on, and that of
     449            // course broke all of the rewrite rules.  accordingly, to keep compatibility between the two version, we have to make sure that every
     450            // permastruct makes sure that it has the slash...we'll do this using the leadingslashit method.
     451
    401452            // date rewrites come first because otherwise they get eaten by the permalink rewrite rule.  they
    402453            // are ordered in order of least specific to most specific.
    403             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_year_permastruct(), EP_YEAR );
    404             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_month_permastruct(), EP_MONTH );
    405             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_day_permastruct(), EP_DAY );
    406             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_date_permastruct(), EP_DATE );
     454            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_year_permastruct() ), EP_YEAR );
     455            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_month_permastruct() ), EP_MONTH );
     456            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_day_permastruct() ), EP_DAY );
     457            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_date_permastruct() ), EP_DATE );
    407458
    408459            // tags and categories also come before permalinks b/c they can otherwise be eaten by the attachments in the case
    409460            // that the permalink is *just* the postname.
    410             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_tag_permastruct(), EP_TAGS );
    411             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_category_permastruct(), EP_CATEGORIES );
     461            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_tag_permastruct() ), EP_TAGS );
     462            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_category_permastruct() ), EP_CATEGORIES );
    412463
    413464            // this seems to be for custom taxonomies (i couldn't find anything else under WP that uses it...).  it also needs
    414465            // to come before the permalink b/c it will act more or less like a normal category/tag.
    415466            foreach( $wp_rewrite->extra_permastructs as $name => $permastruct ) {
    416                 $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $permastruct[0], EP_CATEGORIES );
    417             }
    418 
    419             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_author_permastruct(), EP_AUTHORS );
    420             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->get_search_permastruct(), EP_SEARCH );
    421 
    422             $newrules += $wp_rewrite->generate_rewrite_rules( "$lang_prefix/" . $wp_rewrite->comments_base, EP_COMMENTS, true, true, true, false );
    423 
    424             $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $wp_rewrite->permalink_structure, EP_PERMALINK );
     467                $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $permastruct[0] ), EP_CATEGORIES );
     468            }
     469
     470            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_author_permastruct() ), EP_AUTHORS );
     471            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_search_permastruct() ), EP_SEARCH );
     472
     473            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->comments_base ), EP_COMMENTS, true, true, true, false );
     474
     475            $newrules += $wp_rewrite->generate_rewrite_rules( $lang_prefix . $this->leadingslashit( $wp_rewrite->permalink_structure ), EP_PERMALINK );
    425476
    426477            // this appears to be a bug in wordpress that we need to work around...  it's eating up our gts_lang variable in places relating
     
    441492
    442493            // these two go last b/c it will otherwise match some of the above patterns.
    443             $newrules += $wp_rewrite->generate_rewrite_rule( $lang_prefix . $wp_rewrite->get_page_permastruct(), EP_PAGES );
     494            $newrules += $wp_rewrite->generate_rewrite_rule( $lang_prefix . $this->leadingslashit( $wp_rewrite->get_page_permastruct() ), EP_PAGES );
    444495            $newrules += $wp_rewrite->generate_rewrite_rule( $lang_prefix, EP_ROOT );
    445496
     
    448499
    449500        return $rules;
     501    }
     502
     503    function leadingslashit( $str ) {
     504
     505        if( $str && strlen( $str ) && $str[0] != '/' ) {
     506            $str = "/$str";
     507        }
     508
     509        return $str;
    450510    }
    451511
  • gts-translation/trunk/wordpress/GtsWidgets.php

    r332072 r363827  
    3939        'fr' => 'Traduire en',
    4040        'it' => 'Traduci in',
     41        'ru' => 'Перевод на',
    4142    );
    4243
     
    4748        'fr' => 'Site traduit par',
    4849        'it' => 'Sito internet tradotto da',
     50        'ru' => 'Сайт переведен на',
    4951    );
    5052
     
    5557        'fr' => 'Choisir Langue',
    5658        'it' => 'Scegliere Lingua',
     59        'ru' => 'Выберите язык',
    5760    );
    5861
     
    302305        }
    303306
    304 
    305         $cat = get_term_by( 'slug', get_query_var( 'category_name' ), 'category' );
    306         return get_category_link( $cat ? $cat->term_id : 0 );
     307        $category = get_term_by( 'id', get_query_var( 'cat' ), 'category' );
     308        return get_category_link( $category ? $category->term_id : 0 );
    307309    }
    308310
  • gts-translation/trunk/wordpress/pages/gts-settings-options.php

    r305620 r363827  
    5151    $languages = $_POST['languages'] ? $_POST['languages'] : $_GET['languages'];
    5252
    53     if( $auth && $api_key && $languages ) {
     53    if( $auth && $blog_id && $api_key && $languages ) {
    5454
    5555        if( $gts_plugin->get_validation_code() === $auth ) {
Note: See TracChangeset for help on using the changeset viewer.