Ignore:
Timestamp:
08/27/2010 02:26:28 PM (21 months ago)
Author:
ofer
Message:

Provide a working gettext interface that blends with Transposh

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/WordPress/plugin/transposh/transposh.php

    r500 r522  
    6060    /** @var transposh_3rdparty Happens after editing */ 
    6161    private $third_party; 
    62  
    6362    // list of properties 
    6463    /** @var string The site url */ 
     
    7271    /** @var boolean Enable rewriting of URLs */ 
    7372    public $enable_permalinks_rewrite; 
    74     /** @var string The language to translate the page to */ 
     73    /** @var string The language to translate the page to, from params */ 
    7574    public $target_language; 
     75    /** @var string The language extracted from the url */ 
     76    public $tgl; 
    7677    /** @var boolean Are we currently editing the page? */ 
    7778    public $edit_mode; 
     
    139140//        add_action('admin_menu', array(&$this, 'transposh_post_language')); 
    140141//        add_action('save_post', array(&$this, 'transposh_save_post_language')); 
    141  
    142142        //TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav')); 
    143143        //TODO comment_row_actions (filter) 
    144         // toying around the mo/po stuff 
    145         add_filter('gettext', array(&$this, 'transposh_gettext_filter'), 10, 3); 
     144        // Intergrating with the gettext interface 
     145        add_filter('gettext', array(&$this, 'transposh_gettext_filter'), 10, 2); 
     146        add_filter('gettext_with_context', array(&$this, 'transposh_gettext_filter'), 10, 2); 
     147        add_filter('ngettext', array(&$this, 'transposh_ngettext_filter'), 10, 3); 
     148        add_filter('ngettext_with_context', array(&$this, 'transposh_ngettext_filter'), 10, 3); 
    146149        add_filter('locale', array(&$this, 'transposh_locale_filter')); 
    147150 
     151        //CHECK TODO!!!!!!!!!!!! 
     152        $this->tgl = transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url); 
    148153 
    149154        register_activation_hook(__FILE__, array(&$this, 'plugin_activate')); 
     
    244249     */ 
    245250    function on_shutdown() { 
    246         ob_flush(); 
     251        //TODO !!!!!!!!!!!! ob_flush(); 
    247252    } 
    248253 
     
    321326 
    322327        // first we get the target language 
    323         $this->target_language = $wp->query_vars[LANG_PARAM]; 
    324         if (!$this->target_language) 
    325                 $this->target_language = $this->options->get_default_language(); 
     328        /*        $this->target_language = (isset($wp->query_vars[LANG_PARAM])) ? $wp->query_vars[LANG_PARAM] : ''; 
     329          if (!$this->target_language) 
     330          $this->target_language = $this->options->get_default_language(); 
     331          logger("requested language: {$this->target_language}"); */ 
     332        // TODO TOCHECK!!!!!!!!!!!!!!!!!!!!!!!!!!1 
     333        $this->target_language = $this->tgl; 
    326334        logger("requested language: {$this->target_language}"); 
     335 
    327336 
    328337        // make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10 
     
    676685            $n = !empty($q['exact']) ? '' : '%'; 
    677686            $searchand = ''; 
     687            $search = ''; 
    678688            foreach ((array) $q['search_terms'] as $term) { 
    679689                // now we'll get possible translations for this term 
     
    820830    } 
    821831 
    822     function transposh_gettext_filter($a, $orig, $domain) { 
    823         //logger("$a $orig $domain"); 
    824         return $a; 
     832    /** 
     833     * This function adds our markings around gettext results 
     834     * @param string $translation 
     835     * @param string $orig 
     836     * @return string 
     837     */ 
     838    function transposh_gettext_filter($translation, $orig) { 
     839        if ($this->is_special_page($_SERVER['REQUEST_URI']) || ($this->options->is_default_language($this->tgl) && !$this->options->get_enable_default_translate())) { 
     840            logger($translation); 
     841            return $translation; 
     842        } 
     843        if ($translation != $orig) { 
     844            $translation = TP_GTXT_BRK . $translation . TP_GTXT_BRK_CLOSER; 
     845        } 
     846        $translation = str_replace(array('%s', '%1$s', '%2$s', '%3$s', '%4$s', '%5$s'), array(TP_GTXT_IBRK . '%s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%1$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%2$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%3$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%4$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%5$s' . TP_GTXT_IBRK_CLOSER), $translation); 
     847        return $translation; 
     848    } 
     849 
     850    /** 
     851     * This function adds our markings around ngettext results 
     852     * @param string $translation 
     853     * @param string $single 
     854     * @param string $plural 
     855     * @return string 
     856     */ 
     857    function transposh_ngettext_filter($translation, $single, $plural) { 
     858        if ($this->is_special_page($_SERVER['REQUEST_URI']) || ($this->options->is_default_language($this->tgl) && !$this->options->get_enable_default_translate())) 
     859                return $translation; 
     860        if ($translation != $single && $translation != $plural) { 
     861            $translation = TP_GTXT_BRK . $translation . TP_GTXT_BRK_CLOSER; 
     862        } 
     863        $translation = str_replace(array('%s', '%1$s', '%2$s', '%3$s', '%4$s', '%5$s'), array(TP_GTXT_IBRK . '%s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%1$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%2$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%3$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%4$s' . TP_GTXT_IBRK_CLOSER, TP_GTXT_IBRK . '%5$s' . TP_GTXT_IBRK_CLOSER), $translation); 
     864        return $translation; 
    825865    } 
    826866 
    827867    function transposh_locale_filter($locale) { 
    828         //logger($locale); 
     868        $lang = transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url); 
     869        if (!$lang) return $locale; 
     870        list ($l, $n, $f, $locale) = explode(',', transposh_consts::$languages[$lang]); 
     871        if ($locale) { 
     872            return $locale; 
     873        } else { 
     874            return $lang; 
     875        } 
    829876        return $locale; 
    830877    } 
Note: See TracChangeset for help on using the changeset viewer.