Changeset 522
- Timestamp:
- 08/27/2010 02:26:28 PM (18 months ago)
- Location:
- trunk/WordPress/plugin/transposh
- Files:
-
- 2 edited
-
core/parser.php (modified) (8 diffs)
-
transposh.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/WordPress/plugin/transposh/core/parser.php
r518 r522 270 270 //· 271 271 if (ord($char) == 194 && ord($nextchar) == 183) return 2; 272 return (strpos(',?()[]"!:|;' , $char) !== false) ? 1 : 0; // TODO: might need to add < and > here272 return (strpos(',?()[]"!:|;'.TP_GETTEXT_BREAKER.TP_GETTEXT_CLOSER.TP_GETTEXT_INNER_BREAKER.TP_GETTEXT_INNER_BREAKER_CLOSER, $char) !== false) ? 1 : 0; // TODO: might need to add < and > here 273 273 } 274 274 … … 288 288 function tag_phrase($string, $start, $end) { 289 289 $phrase = trim(substr($string, $start, $end - $start)); 290 if ($this->in_get_text && !$this->in_get_text_inner) { 290 // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string); 291 // logger ("p:$phrase, s:$logstr, st:$start, en:$end, gt:{$this->in_get_text}, gti:{$this->in_get_text_inner}"); 292 // logger (''); 293 if ($this->in_get_text > $this->in_get_text_inner) { 291 294 logger('not tagging ' . $phrase . ' assumed gettext translated', 4); 292 295 return; … … 343 346 $pos++; 344 347 $start = $pos; 345 } elseif ($string[$pos] == TP_GETTEXT_BREAKER) { 346 logger("text breaker $start $pos $string " . (($this->in_get_text) ? 'true' : 'false'), 5); 348 } elseif ($string[$pos] == TP_GTXT_BRK || $string[$pos] == TP_GTXT_BRK_CLOSER) { 349 // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string); 350 // $closers = ($string[$pos] == TP_GTXT_BRK) ? '': 'closer'; 351 // logger(" $closers TEXT breaker $logstr start:$start pos:$pos gt:" . $this->in_get_text, 3); 347 352 $this->tag_phrase($string, $start, $pos); 353 ($string[$pos] == TP_GTXT_BRK) ? $this->in_get_text += 1: $this->in_get_text -= 1; 348 354 $pos++; 349 355 $start = $pos; 350 $this->in_get_text = !$this->in_get_text; // flipping state 351 if ($pos == 1) 352 $this->in_get_text = true; // reset state based on string start 353 $this->in_get_text_inner = false; 354 } elseif ($string[$pos] == TP_GETTEXT_INNER_BREAKER) { 355 logger("inner text breaker $start $pos $string " . (($this->in_get_text_inner) ? 'true' : 'false'), 5); 356 // reset state based on string start, no need to flip 357 //$this->in_get_text = ($pos == 1); 358 //if (!$this->in_get_text) $this->in_get_text_inner = false; 359 } elseif ($string[$pos] == TP_GTXT_IBRK || $string[$pos] == TP_GTXT_IBRK_CLOSER ) { 360 // $logstr = str_replace(array(chr(1),chr(2),chr(3),chr(4)), array('[1]','[2]','[3]','[4]'), $string); 361 // $closers = ($string[$pos] == TP_GTXT_IBRK) ? '': 'closer'; 362 // logger(" $closers INNER text breaker $logstr start:$start pos:$pos gt:" . $this->in_get_text_inner, 3); 363 //logger("inner text breaker $start $pos $string " . (($this->in_get_text_inner) ? 'true' : 'false'), 5); 356 364 $this->tag_phrase($string, $start, $pos); 365 if ($this->in_get_text) 366 ($string[$pos] == TP_GTXT_IBRK) ? $this->in_get_text_inner += 1 : $this->in_get_text_inner -=1; 357 367 $pos++; 358 368 $start = $pos; 359 $this->in_get_text_inner = !$this->in_get_text_inner;369 //$this->in_get_text_inner = !$this->in_get_text_inner; 360 370 } 361 371 // will break translation unit when there's a breaker ",.[]()..." 362 372 elseif ($senb_len = $this->is_sentence_breaker($string[$pos], $string[$pos + 1], $string[$pos + 2])) { 373 // logger ("sentence breaker..."); 363 374 $this->tag_phrase($string, $start, $pos); 364 375 $pos += $senb_len; … … 368 379 // also prefixed by whitespace? 369 380 elseif ($num_len = $this->is_number($string, $pos)) { 381 // logger ("numnum... $num_len"); 370 382 // this is the case of B2 or B2, 371 383 if (($this->is_white_space($string[$pos - 1]) || ($start == $pos) … … 373 385 ($this->is_white_space($string[$pos + $num_len]) || $this->is_sentence_breaker($string[$pos + $num_len], $string[$pos + $num_len + 1], $string[$pos + $num_len + 2]))) { 374 386 // we will now compensate on the number followed by breaker case, if we need to 387 // logger ("compensate part1?"); 375 388 if (!($this->is_white_space($string[$pos - 1]) || ($start == $pos))) { 389 // logger ("compensate part2?"); 376 390 if ($this->is_sentence_breaker($string[$pos + $num_len - 1], $string[$pos + $num_len], $string[$pos + $num_len + 1])) { 391 // logger ("compensate 3?"); 377 392 $num_len--; //this makes the added number shorter by one, and the pos will be at a sentence breaker next so we don't have to compensate 378 393 } … … 381 396 } 382 397 $this->tag_phrase($string, $start, $pos); 383 $start = $pos + $num_len + 1; 384 } 385 $pos += $num_len + 1; 398 $start = $pos + $num_len /*+1*/; 399 } 400 $pos += $num_len/* + 1*/; 401 // logger ("numnumpos... $pos"); 386 402 } else { 387 403 // smarter marking of start location … … 557 573 $this->html = str_get_html($string); 558 574 // mark translateable elements 575 $this->html->find('html', 0)->lang = ''; // Document defined lang may be preset to correct lang, but should be ignored TODO: Better? 559 576 $this->translate_tagging($this->html->root); 560 577 … … 758 775 759 776 // we make sure that the result is clear from our shananigans 760 return str_replace(array(TP_G ETTEXT_BREAKER, TP_GETTEXT_INNER_BREAKER), '', $this->html->outertext);777 return str_replace(array(TP_GTXT_BRK, TP_GTXT_IBRK, TP_GTXT_BRK_CLOSER, TP_GTXT_IBRK_CLOSER), '', $this->html->outertext); 761 778 // Changed because of places where tostring failed 762 779 //return $this->html; -
trunk/WordPress/plugin/transposh/transposh.php
r500 r522 60 60 /** @var transposh_3rdparty Happens after editing */ 61 61 private $third_party; 62 63 62 // list of properties 64 63 /** @var string The site url */ … … 72 71 /** @var boolean Enable rewriting of URLs */ 73 72 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 */ 75 74 public $target_language; 75 /** @var string The language extracted from the url */ 76 public $tgl; 76 77 /** @var boolean Are we currently editing the page? */ 77 78 public $edit_mode; … … 139 140 // add_action('admin_menu', array(&$this, 'transposh_post_language')); 140 141 // add_action('save_post', array(&$this, 'transposh_save_post_language')); 141 142 142 //TODO add_action('manage_comments_nav', array(&$this,'manage_comments_nav')); 143 143 //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); 146 149 add_filter('locale', array(&$this, 'transposh_locale_filter')); 147 150 151 //CHECK TODO!!!!!!!!!!!! 152 $this->tgl = transposh_utils::get_language_from_url($_SERVER['REQUEST_URI'], $this->home_url); 148 153 149 154 register_activation_hook(__FILE__, array(&$this, 'plugin_activate')); … … 244 249 */ 245 250 function on_shutdown() { 246 ob_flush();251 //TODO !!!!!!!!!!!! ob_flush(); 247 252 } 248 253 … … 321 326 322 327 // 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; 326 334 logger("requested language: {$this->target_language}"); 335 327 336 328 337 // make themes that support rtl - go rtl http://wordpress.tv/2010/05/01/yoav-farhi-right-to-left-themes-sf10 … … 676 685 $n = !empty($q['exact']) ? '' : '%'; 677 686 $searchand = ''; 687 $search = ''; 678 688 foreach ((array) $q['search_terms'] as $term) { 679 689 // now we'll get possible translations for this term … … 820 830 } 821 831 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; 825 865 } 826 866 827 867 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 } 829 876 return $locale; 830 877 }
Note: See TracChangeset
for help on using the changeset viewer.
