Smarty
[ class tree: Smarty ] [ index: Smarty ] [ all elements ]

Source for file prefilter.tr.php

Documentation is available at prefilter.tr.php

  1. <?php
  2. /**
  3.  * Smarty plugin
  4.  * @package Smarty
  5.  * @subpackage plugins
  6.  */
  7.  
  8. /**
  9.  * smarty_prefilter_tr
  10.  * 
  11.  * @param array $source 
  12.  * @access public
  13.  * @return full source with partially treated {tr} sections
  14.  */
  15. function smarty_prefilter_tr$source {
  16.     // Now replace the matched language strings with the entry in the file
  17.     // $return = preg_replace_callback( '#\{tr[^\{]*\}([^\{]+)\{/tr\}#', '_translate_lang', $source );
  18.     //
  19.     // correction: in order to match when a variable is inside {tr} tags.
  20.     // Example: {tr}The newsletter was sent to {$sent} email addresses{/tr},
  21.     // and where there are parameters with {tr} take away the smarty comments 
  22.     // {* *} in case they have tr tags
  23.     returnpreg_replace_callback'#(?s)(\{tr[^\}]*\})(.+?)\{/tr\}#''_translate_lang'preg_replace '#(?s)\{\*.*?\*\}#'''$source ) ) );
  24. }
  25.  
  26. /**
  27.  * _translate_lang
  28.  * 
  29.  * @param array $pKey Hash passed in by smarty_prefilter_tr() above
  30.  * @param array $pKey[0] starting {tr} tag
  31.  * @param array $pKey[1] string that needs to be translated
  32.  * @param array $pKey[2] flosing {/tr} tag
  33.  * @access protected
  34.  * @return translated string
  35.  *
  36.  *  Note: If you want to have a {tr} block interpreted AFTER variable substitution, add a parameter to {tr}
  37.  *  e.g.: {tr post=1}text {$that} needs to be {$evaluated}{/tr}
  38.  */
  39. function _translate_lang$pKey {
  40.     global $gBitLanguage$lang;
  41.  
  42.     // this is the original codeblock:
  43. //    if (strstr($pKey[2], "{\$")) {
  44. //        // We have a variable - keep the tags to be perhaps translated in block.tr.php
  45. //        return $pKey[1].$pKey[2]."{/tr}";
  46. //    } elseif ($pKey[1] == "{tr}") {
  47. //        // no more possible translation in block.tr.php
  48. //        return $trans;
  49. //    } else {
  50. //        // perhaps variable substitution to do in block.tr.php
  51. //        return $pKey[1].$trans."{/tr}";
  52. //    }
  53.     // Explanation why this doesn't work:
  54.     //  - case 1
  55.     //    returning stuff like {tr}waiting for {$number} ratings{/tr}
  56.     //    will get translated by block.tr.php but only after the {$number} has 
  57.     //    been interpreted and we will end up with master strings like:
  58.     //    waiting for 4 ratings
  59.     //    waiting for 5 ratings
  60.     //    waiting for 6 ratings
  61.     //
  62.     //  - case 2
  63.     //    this should be fine since it has been translated and the {tr} blocks 
  64.     //    have been removed i.e. block.tr.php won't be called anymore
  65.     //
  66.     //  - case 3
  67.     //    this will leave everything as is. this will work as well, but only if 
  68.     //    there is no {$var} in the string - see case 1
  69.     // --- xing
  70.  
  71.  
  72.     // if the entire string in {tr} is a variable, we pass it on to block.tr.php
  73.     // e.g. {tr}{$menu.menu_title}{/tr} in top_bar.tpl
  74.     // if you change this regexp, please modify the one in languages/BitLanguage.php as well (approx line 256)
  75.     ifpreg_match'!^(\{\$[^\}]*\})+$!'$pKey[2) ) {
  76.         return $pKey[1].$pKey[2]."{/tr}";
  77.     elseif$pKey[1== "{tr}" {
  78.         // no parameters set for block.tr.php
  79.         $trans $gBitLanguage->translate$pKey[2);
  80.         return $trans;
  81.     else {
  82.         // perhaps there are parameters set for block.tr.php
  83.         return $pKey[1].$pKey[2]."{/tr}";
  84.     }
  85. }
  86. ?>

Documentation generated on Wed, 29 Jul 2015 13:57:16 +0000 by phpDocumentor 1.5.0-lsces