Source for file phpgettext.class.php

Documentation is available at phpgettext.class.php

  1. <?php
  2. /**
  3.  * @version        0.9
  4.  * @author      Carlos Souza
  5.  * @copyright   Copyright (c) 2005 Carlos Souza <csouza@web-sense.net>
  6.  * @package     PHPGettext
  7.  * @license        MIT License (http://www.opensource.org/licenses/mit-license.php)
  8.  * @link        http://phpgettext.web-sense.net
  9.  *
  10.  *
  11.  */
  12. defined'_VALID_MOS' or die'Direct Access to this location is not allowed.' );
  13. class PHPGettext
  14. {
  15.     var $has_gettext;
  16.  
  17.     /**
  18.      * The current locale. eg: en-GB
  19.      */
  20.     var $lang;
  21.     /**
  22.      * The current locale. eg: en-GB
  23.      */
  24.     var $locale;
  25.  
  26.     /**
  27.      * The current domain
  28.      */
  29.     var $domain;
  30.  
  31.     /**
  32.      * The current character set
  33.      */
  34.     var $charset;
  35.  
  36.     /**
  37.      * Container for the loaded domains
  38.      */
  39.     var $text_domains = array();
  40.  
  41.     /**
  42.      * The asssociative array of headers for the current domain
  43.      */
  44.     var $headers = array();
  45.     /**
  46.      * The asssociative array of messages for the current domain
  47.      */
  48.     var $messages = array();
  49.  
  50.     /**
  51.      * The debugging flag
  52.      */
  53.     var $debug;
  54.  
  55.     function PHPGettext({}
  56.  
  57.     /**
  58.      *
  59.      * Set and lookup the locale from the environment variables.
  60.      * Priority order for gettext is:
  61.      * 1. LANGUAGE
  62.      * 2. LC_ALL
  63.      * 3. LC_MESSAGE
  64.      * 4. LANG
  65.      *
  66.      * @return unknown 
  67.      */
  68.  
  69.     function setVariable($variable){
  70.         if ($this->has_gettext){
  71.             $this->has_gettext = $this->has_gettext && @putenv($variable);
  72.         }
  73.     }
  74.     
  75.     function setlocale($lang$locale=false{
  76.         $this->setvariable("LANGUAGE=$lang");
  77.         $this->setvariable("LC_ALL=$lang");
  78.         $this->setvariable("LC_MESSAGE=$lang");
  79.         $this->setvariable("LANG=$lang");
  80.         $this->lang =  $lang;
  81.         if ($locale{
  82.             $this->locale =  setlocale(LC_ALL,$locale);
  83.         }
  84.     }
  85.  
  86.     function getlocale({
  87.         if (empty($this->locale)) {
  88.             $langs arraygetenv('LANGUAGE'),
  89.             getenv('LC_ALL'),
  90.             getenv('LC_MESSAGE'),
  91.             getenv('LANG')
  92.             );
  93.             foreach ($langs as $lang)
  94.             if ($lang){
  95.                 $this->locale = $lang;
  96.                 break;
  97.             }
  98.         }
  99.         return $this->locale;
  100.     }
  101.  
  102.     /**
  103.      * debugging function
  104.      *
  105.      */
  106.     function output($message$untranslated false){
  107.         switch ($this->debug)
  108.         {
  109.             case 2:
  110.             $trace debug_backtrace();
  111.             $html '<span style="border-bottom: thin solid %s" title="%s(%d)">T_(%s)</span>';
  112.             $str sprintf($html($untranslated 'red' 'green')str_replace('\\''/'$trace[2]['file'])$trace[2]['line']$message);
  113.             break;
  114.             case 1:
  115.             $str    sprintf('%sT_(%s)',$untranslated '!' ''$message);
  116.             break;
  117.             case 0:
  118.             default:
  119.             $str    $message;
  120.             break;
  121.         }
  122.         return $str;
  123.     }
  124.  
  125.     /**
  126.      * Alias for gettext
  127.      * will also output the result if $output = true
  128.      */
  129.     function _($message$output false){
  130.         $return $this->gettext($message);
  131.         if ($output{
  132.             echo $return;
  133.             return true;
  134.         }
  135.         return $return;
  136.     }
  137.  
  138.     /**
  139.      * Lookup a message in the current domain
  140.      * returns translation if it exists or original message
  141.      */
  142.     function gettext($message){
  143.         $translation $message;
  144.         if ($this->has_gettext){
  145.             $translation gettext($message);
  146.         }
  147.         else{
  148.            $message addslashes($message);
  149.            $message str_replace("\n"'\n'$message);
  150.            $message str_replace("\r"'\r'$message);
  151.            if (isset($this->messages[$this->domain][$message])) {
  152.             $translation !empty($this->messages[$this->domain][$message]$this->messages[$this->domain][$message$message;
  153.             }
  154.         }
  155.         $untranslated (strcmp($translation$message=== 0true false;
  156.         return $this->output($translation$untranslated);
  157.     }
  158.  
  159.     /**
  160.      * Override the current domain
  161.      * The dgettext() function allows you to override the current domain for a single message lookup.
  162.      */
  163.     function dgettext($domain$message){
  164.         $translation $message;
  165.         if (array_key_exists($domain$this->messages)){
  166.             if (isset($this->messages[$domain][$message]))
  167.             $translation !empty($this->messages[$domain][$message]$this->messages[$domain][$message$message;
  168.         }
  169.         $untranslated (strcmp($translation$message=== 0true false;
  170.         return $this->output($translation$untranslated);
  171.     }
  172.  
  173.     /**
  174.      * Plural version of gettext
  175.      */
  176.     function ngettext($msgid$msgid_plural$count){
  177.         if ($this->has_gettext){
  178.             $translation ngettext($msgid$msgid_plural$count);
  179.         }else{
  180.             $msgid addslashes($msgid);
  181.             $msgid str_replace("\n"'\n'$msgid);
  182.             $msgid str_replace("\r"'\r'$msgid);
  183.             $plural $this->getplural($count$this->domain);
  184.             $original array($msgid$msgid_plural);
  185.             if (isset($this->messages[$this->domain][$msgid][$plural])) {
  186.                 $translation  $this->messages[$this->domain][$msgid][$plural];
  187.             else {
  188.                 $original   array($msgid$msgid_plural);
  189.                 $translation  $original[$plural];
  190.             }
  191.         }
  192.         $untranslated = isset($original[$plural]&& (strcmp($translation$original[$plural]=== 0true false;
  193.         return $this->output($translation$untranslated);
  194.     }
  195.     /**
  196.      * Plural version of dgettext
  197.      */
  198.     function dngettext($domain$msgid$msgid_plural$count){
  199.         $original   array($msgid$msgid_plural);
  200.         $plural $this->getplural($count$domain);
  201.         if ($this->has_gettext){
  202.             $translation dngettext($domain$msgid$msgid_plural$count);
  203.         else {
  204.             $msgid addslashes($msgid);
  205.             $msgid str_replace("\n"'\n'$msgid);
  206.             $msgid str_replace("\r"'\r'$msgid);
  207.             if (isset($this->messages[$domain][$msgid][$plural])) {
  208.                 $translation  $this->messages[$domain][$msgid][$plural];
  209.             else {
  210.                 $translation  $original[$plural];
  211.             }
  212.         }
  213.         $untranslated (strcmp($translation$original[$plural]=== 0true false;
  214.         return $this->output($translation$untranslated);
  215.     }
  216.  
  217.     /**
  218.      * Specify the character encoding in which the messages
  219.      * from the DOMAIN message catalog will be returned
  220.      *
  221.      */
  222.     function bind_textdomain_codeset($domain$charset){
  223.         if ($this->has_gettext){
  224.             bind_textdomain_codeset($domain$charset);
  225.         }
  226.         return $this->text_domains[$domain]["charset"$charset;
  227.     }
  228.  
  229.     /**
  230.      * Sets the path for a domain
  231.      * if gettext is unavailable, translation files will be loaded here
  232.      *
  233.      */
  234.     function bindtextdomain($domain$path){
  235.         if ($this->has_gettext){
  236.             bindtextdomain($domain$path);
  237.         else {
  238.             $this->load($domain$path);
  239.         }
  240.         return $this->text_domains[$domain]["path"$path;
  241.     }
  242.  
  243.     /**
  244.      * Sets the default domain textdomain
  245.      */
  246.     function textdomain($domain null){
  247.         if ($this->has_gettext{
  248.           $this->domain = textdomain($domain);
  249.         }
  250.         elseif (!is_null($domain)) {
  251.             $this->domain = $domain;
  252.             $this->load($domain$this->text_domains[$this->domain]['path']);
  253.         }
  254.         return $this->domain;
  255.     }
  256.  
  257.     /**
  258.      * Overrides the domain for a single lookup
  259.      * This function allows you to override the current domain for a single message lookup.
  260.      * It also allows you to specify a category.
  261.      * Categories are folders within the languages directory  .
  262.      * currently, only LC_MESSAGES is implemented
  263.      *
  264.      *   The values for categories are:
  265.      *   LC_CTYPE        0
  266.      *   LC_NUMERIC      1
  267.      *   LC_TIME         2
  268.      *   LC_COLLATE      3
  269.      *   LC_MONETARY     4
  270.      *   LC_MESSAGES     5
  271.      *   LC_ALL          6
  272.      *
  273.      *   not yet implemented
  274.      */
  275.     function dcgettext($domain$message$category){
  276.         return $message;
  277.     }
  278.  
  279.     /**
  280.      * dcngettext -- Plural version of dcgettext
  281.      * not yet implemented
  282.      */
  283.     function dcngettext($domain$msg1$msg2$count$category){
  284.         return $msg1;
  285.     }
  286.  
  287.  
  288.     /**
  289.      * Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;
  290.      *
  291.      * nplurals - total number of plurals
  292.      * plural   - the plural index
  293.      *
  294.      * Plural-Forms: nplurals=1; plural=0;
  295.      * 1 form only
  296.      *
  297.      * Plural-Forms: nplurals=2; plural=n == 1 ? 0 : 1;
  298.      * Plural-Forms: nplurals=2; plural=n != 1;
  299.      * 2 forms, singular used for one only
  300.      *
  301.      * Plural-Forms: nplurals=2; plural=n>1;
  302.      * 2 forms, singular used for zero and one
  303.      *
  304.      * Plural-Forms: nplurals=3; plural=n%10==1 && n%100!=11 ? 0 : n != 0 ? 1 : 2;
  305.      * 3 forms, special case for zero
  306.      *
  307.      * Plural-Forms: nplurals=3; plural=n==1 ? 0 : n==2 ? 1 : 2;
  308.      * 3 forms, special cases for one and two
  309.      *
  310.      * Plural-Forms: nplurals=4; plural=n%100==1 ? 0 : n%100==2 ? 1 : n%100==3 || n%100==4 ? 2 : 3;
  311.      * 4 forms, special case for one and all numbers ending in 02, 03, or 04
  312.      */
  313.     function getplural($count$domain{
  314.         if (isset($this->headers[$domain]['Plural-Forms'])) {
  315.             $plural_forms $this->headers[$domain]['Plural-Forms'];
  316.             preg_match('/nplurals[\s]*[=]{1}[\s]*([\d]+);[\s]*plural[\s]*[=]{1}[\s]*(.*);/'$plural_forms$matches);
  317.             $nplurals   $matches[1];
  318.             $plural_exp $matches[2];
  319.             if ($nplurals && strpos($plural_exp':'=== false{
  320.                 $plural =  'return ('.preg_replace('/n/'$count$plural_exp).') ? 1 : 0;';
  321.             else {
  322.                 $plural 'return '.preg_replace('/n/'$count$plural_exp).';';
  323.             }
  324.         else {
  325.             $plural 'return '.preg_replace('/n/'$count'n != 1 ? 1 : 0;');
  326.         }
  327.         return eval($plural);
  328.     }
  329.  
  330.     function load($domain$path{
  331.         $root dirname(__FILE__);
  332.         require_once($root.'/phpgettext.catalog.php');
  333.         $catalog new PHPGettext_catalog($domain$path);
  334.         $catalog->setproperty('mode'_MODE_MO_);
  335.         $catalog->setproperty('lang'$this->lang);
  336.         $catalog->load();
  337.         $this->headers[$domain$catalog->headers;
  338.         foreach ($catalog->strings as $string)
  339.         $this->messages[$domain][$string->msgid$string->msgstr;
  340.     }
  341.     //Thank you - Inicio Agregado Andres Felipe Vargas
  342.     function add($domain{
  343.         $catalog new PHPGettext_catalog($domain$this->text_domains[$this->domain]["path"]);
  344.         $catalog->setproperty('mode'_MODE_MO_);
  345.         $catalog->setproperty('lang'$this->lang);
  346.         $catalog->load();
  347.         foreach ($catalog->strings as $string)
  348.         $this->messages[$this->domain][$string->msgid$string->msgstr;
  349.     }
  350.     //end Inicio Agregado Andres Felipe Vargas
  351.  
  352. }
  353.  
  354.  
  355. {
  356.     var $has_gettext    = false;
  357.     var $gettext_path   = '';
  358.     var $debug          = false;
  359.     var $is_windows     = false;
  360.  
  361.     function PHPGettextAdmin($debug false)
  362.     {
  363.         if (ini_get('open_basedir'|| ini_get('safe_mode'|| strstr(ini_get("disable_functions"),"exec")) {
  364.             $this->has_gettext = false;
  365.             return false;
  366.         }
  367.         
  368.         if (substr(strtoupper(PHP_OS)03== 'WIN'){
  369.             $this->is_windows = true;
  370.         }
  371.         
  372.         $cmd 'xgettext --help';
  373.         exec($cmd$output$return);
  374.         if ($output{
  375.             $this->has_gettext = true;
  376.         }
  377.         if ($debug{
  378.             $this->debug = $debug;
  379.         }
  380.     }
  381.  
  382.     /**
  383.      * Enter description here...
  384.      *
  385.      * @param unknown_type $domain 
  386.      * @param unknown_type $langdir 
  387.      */
  388.     function message_format ($domain$textdomain$lang$enc='utf-8')
  389.     {
  390.         $path   "$textdomain/$lang";
  391.         if ($this->has_gettext{
  392.             $cmd $this->escCommand("msgfmt")." -o ".$this->escPath("{$path}/LC_MESSAGES/{$domain}.mo")." ".$this->escPath("{$path}/{$domain}.po");
  393.             return $this->execute($cmd);
  394.         }
  395.         $catalog new PHPGettext_catalog($domain$textdomain);
  396.         $catalog->setproperty('mode'_MODE_PO_);
  397.         $catalog->setproperty('lang'$lang);
  398.         $catalog->load();
  399.         $catalog->setproperty('mode'_MODE_MO_);
  400.         $catalog->save();
  401.         return true;
  402.     }
  403.     /**
  404.      * Enter description here...
  405.      *
  406.      * @param unknown_type $domain 
  407.      * @param unknown_type $langdir 
  408.      */
  409.     function compile($lang$textdomain$enc='utf-8'{
  410.         if (!is_dir("$textdomain/$lang/LC_MESSAGES")) {
  411.             mkdir("$textdomain/$lang/LC_MESSAGES/");
  412.         }
  413.         $catalog new PHPGettext_catalog($lang$textdomain);
  414.         $catalog->setproperty('mode'_MODE_PO_);
  415.         $catalog->setproperty('lang'$lang);
  416.         $headers $this->header();
  417.         $catalog->setproperty('comments'$headers[0]);
  418.         $catalog->setproperty('headers'$headers[1]);
  419.         $catalog->load();
  420.         $d dir($textdomain."/".$lang);
  421.         while (false !== ($file $d->read())){
  422.            if (preg_match('/.po$/'$file)){
  423.                 list($file,$extexplode(".",$file);
  424.                 $catalog_aux new PHPGettext_catalog($file$textdomain);
  425.                 $catalog_aux->setproperty('mode'_MODE_PO_);
  426.                 $catalog_aux->setproperty('lang'$lang);
  427.                 $catalog_aux->load();
  428.                 foreach ($catalog_aux->strings as $msgid => $string){
  429.                    if (!$string->is_fuzzy){
  430.                         if (is_array($string->msgstr) ){
  431.                             if(in_array("",$string->msgstr)){
  432.                                 continue;
  433.                             }
  434.                         else if (!$string->msgstr){
  435.                             continue;
  436.                         }
  437.                        $catalog->addentry($string->msgid$string->msgid_plural,$string->msgstr$string->comments );
  438.                    }
  439.                 }
  440.            }
  441.         }
  442.         $catalog->setproperty('mode'_MODE_MO_);
  443.         $catalog->save();
  444.         return true;
  445.     }
  446.  
  447.     /**
  448.      * Enter description here...
  449.      *
  450.      * @param unknown_type $domain 
  451.      * @param unknown_type $langdir 
  452.      */
  453.     function initialize_translation ($domain$textdomain$lang$enc='utf-8')
  454.     {
  455.         if (!$this->has_gettext{
  456.             return false;
  457.         }
  458.         set_time_limit(120);
  459.         $path   "$textdomain/$lang";
  460.         copy("$textdomain/untranslated/$domain.pot""$path/ref.po");
  461.         $cmd $this->escCommand("msgmerge")." --width=80 --compendium ".$this->escPath("{$textdomain}/glossary/{$lang}.{$enc}.po")." -o ".$this->escPath("{$path}/{$domain}.po")." ".$this->escPath("{$path}/ref.po")." ".$this->escPath("{$textdomain}/untranslated/{$domain}.pot");
  462.         $this->execute($cmd);
  463.         unlink("$textdomain/$lang/ref.po");
  464.     }
  465.  
  466.     /**
  467.      * Enter description here...
  468.      *
  469.      * @param unknown_type $domain 
  470.      * @param unknown_type $langdir 
  471.      */
  472.     
  473.     function update_translation($domain$textdomain$lang$enc='utf-8')
  474.     {
  475.         if (!file_exists("$textdomain/glossary/$lang.$enc.po")) return false;
  476.         $catalog_aux new PHPGettext_catalog($lang.".".$enc$textdomain);
  477.         $catalog_aux->setproperty('mode'_MODE_GLO_);
  478.         $catalog_aux->setproperty('lang'$lang);
  479.         $catalog_aux->load();
  480.         foreach ($catalog_aux->strings as $msgid => $string){
  481.            if (!$string->is_fuzzy){
  482.               $trans[$string->msgid$string->msgstr;
  483.            }
  484.         }
  485.         $catalog new PHPGettext_catalog($domain$textdomain);
  486.         $catalog->setproperty('mode'_MODE_PO_);
  487.         $catalog->setproperty('lang'$lang);
  488.         $catalog->load();
  489.         global $mapcharset;
  490.         $charsets explode("=",$catalog->headers["Content-Type"]);
  491.         $codecharset str_replace("\\n","",strtolower($charsets[1]));
  492.         $NewEncoding new ConvertCharset();
  493.         foreach ($trans as $key => $tran){
  494.                if(trim($mapcharset[$codecharset])!="utf-8")
  495.                     $trans[$key$NewEncoding->Convert($tran,"utf-8",trim($mapcharset[$codecharset]),false);
  496.         }
  497.         $catalog->translate($trans );
  498.         $catalog->save();
  499.         return true;
  500.     }
  501.     
  502.     /**
  503.      * Enter description here...
  504.      *
  505.      * @param unknown_type $domain 
  506.      * @param unknown_type $langdir 
  507.      */
  508.  
  509.     function add_to_dict($domain$textdomain$lang$enc='utf-8'{
  510.         $textdomain rtrim($textdomain'\/');
  511.         $path "$textdomain/$lang";
  512.  
  513.         if (!is_dir("$textdomain/glossary/")) {
  514.             mkdir("$textdomain/glossary/");
  515.         }
  516.         
  517.         $catalog new PHPGettext_catalog($domain$textdomain);
  518.         $catalog->setproperty('mode'_MODE_PO_);
  519.         $catalog->setproperty('lang'$lang);
  520.         $catalog->setproperty('charset'$enc);
  521.         $catalog->load();
  522.  
  523.         foreach ($catalog->strings as $msgid => $string){
  524.            if (!$string->is_fuzzy){
  525.               if (is_array($string->msgstr) ){
  526.                   if(in_array("",$string->msgstr)){
  527.                   continue;
  528.                   }
  529.               else if (!$string->msgstr){
  530.                   continue;
  531.               }
  532.               $new[$string->msgid$string;
  533.            }
  534.         }
  535.  
  536.         $glossary new PHPGettext_catalog($lang.".".$enc$textdomain);
  537.         $glossary->setproperty('mode'_MODE_GLO_);
  538.         $glossary->setproperty('lang'$lang);        
  539.         if (!file_exists("$textdomain/glossary/$lang.$enc.po")) {
  540.             $headers $this->header();
  541.             $glossary->setproperty('comments'$headers[0]);
  542.             $glossary->setproperty('headers'$headers[1]);
  543.             $glossary->save();
  544.         }else{
  545.             $glossary->load();
  546.         }
  547.         
  548.         $glossary->merge($new );
  549.         $glossary->save();
  550.         
  551.         $language new mamboLanguage($lang);
  552.         $language->save();
  553.         return true;
  554.     }
  555.     /**
  556.      * Enter description here...
  557.      *
  558.      * @param unknown_type $domain 
  559.      * @param unknown_type $langdir 
  560.      */
  561.     function convert_charset($domain$textdomain$lang$from_charset$to_charset{
  562.  
  563.         $path "$textdomain/$lang";
  564.         if ($this->has_gettext{
  565.             $cmd $this->escCommand("msgconv")." --to-code=$to_charset -o ".$this->escPath("{$path}/{$domain}.po")." ".$this->escPath("{$path}/{$domain}.po");
  566.             $ret $this->execute($cmd);
  567.             return $ret;
  568.         }
  569.  
  570.         if (!class_exists('ConvertCharset')) {
  571.             return false;
  572.         }
  573.  
  574.         $catalog new PHPGettext_catalog($domain$textdomain);
  575.         $catalog->setproperty('mode'_MODE_PO_);
  576.         $catalog->setproperty('lang'$lang);
  577.         $catalog->load();
  578.         $catalog->headers['Content-Type'"text/plain; charset=$to_charset\n";
  579.         $NewEncoding new ConvertCharset();
  580.         foreach ($catalog->strings as $index => $message{
  581.             if (empty($message->msgid_plural)) {
  582.                 $catalog->strings[$index]->msgstr $NewEncoding->Convert($message->msgstr,$from_charset,$to_charset,false);
  583.             }
  584.         }
  585.         $catalog->save();
  586.         return true;
  587.     }
  588.  
  589.  
  590.     /**
  591.      * Invoke the xgettext utility with $args
  592.      * the xgettext executable must be in PATH
  593.      *
  594.      * @param string the commandline arguments to gettext
  595.      * @return unknown 
  596.      */
  597.     function xgettext($domain$textdomain$php_sources$lang='untranslated'{
  598.         $path mamboCore::get('rootPath');
  599.         $n=count($php_sources);
  600.         if (!$nreturn false;
  601.         $cmd  $this->escCommand("xgettext");
  602.         if (file_exists("$textdomain/$lang/$domain.pot")) $cmd  .= ' -j ';
  603.         $cmd  .= " -n -c --sort-by-file --keyword=T_ --keyword=Tn_:1,2 --keyword=Td_:2 --keyword=Tdn_:2,3 --output-dir=".$this->escPath("{$textdomain}/{$lang}")." -o {$domain}.pot";
  604.         if (count($php_sources10{
  605.             $tmp_name substr(uniqid(),0,8).".txt";
  606.             $tmpfile $path."/media/$tmp_name";
  607.             $fp fopen($tmpfile"w");
  608.             fwrite($fpimplode("\r\n"$php_sources));
  609.             fclose($fp);
  610.             $cmd $cmd." --files-from=".$this->escPath($tmpfile);
  611.         else {
  612.             for($i=0;$i<$n;$i++)
  613.                 $php_sources[$i$this->escPath($php_sources[$i]);
  614.             }
  615.             $cmd $cmd." ".implode(" "$php_sources);
  616.         }
  617.         $ret $this->execute($cmd);
  618.         @unlink($tmpfile);
  619.  
  620.         return $ret;
  621.     }
  622.  
  623.     
  624.     /**
  625.      * Enter description here...
  626.      *
  627.      * @param unknown_type $domain 
  628.      * @param unknown_type $langdir 
  629.      */
  630.     function execute($cmd{
  631.  
  632.         if (!$this || !$this->has_gettextreturn false;
  633.  
  634.         $lastline exec($cmd$output$retval);
  635.         if ($this->debug || $retval 0{
  636.             $trace debug_backtrace();
  637.             $msg "<div style=\"border: thin solid silver; text-align:left;margin-left:10px\">";
  638.             $msg .= "<p><span style=\"font-weight:bold\">PHPGettextAdmin->execute('</span><i>$cmd</i><span style=\"font-weight:bold\">')</span><br/>in ".str_replace($_SERVER['DOCUMENT_ROOT']''$trace[1]['file']).":{$trace[1]['line']}</p>";
  639.             $msg .= "<p><i><b>trace:</b></i></p><ul>";
  640.             for ($a=1$a 3$a++)  {
  641.                 $called = isset($trace[$a]['class']$trace[$a]['class''';
  642.                 $called .= $trace[$a]['type'].$trace[$a]['function']."(".@implode(', ',$trace[$a]['args']).")";
  643.                 $msg .= "<li>$called in ".str_replace($_SERVER['DOCUMENT_ROOT']''$trace[$a]['file'])." : {$trace[$a]['line']}</li>";
  644.             }
  645.             $msg .= "</ul>";
  646.             $msg .= "<p><i><b>return value:</b></i>  $retval</p>";
  647.             $msg .= "<p><i><b>output:</b></i> </p><pre>".implode("<br/>",$output)."</pre>";
  648.             $msg .= "</div>";
  649.             echo $msg;
  650.         }
  651.         return $retval == 0;
  652.     }
  653.     
  654.     function escCommand($command){
  655.         if ($this->is_windows){
  656.            $command "call \"{$command}\"";
  657.         }
  658.         return $command;
  659.     }
  660.  
  661.     function escPath($path){
  662.         if ($this->is_windows){
  663.            $path "\"".str_replace("/","\\",$path)."\"";
  664.         }
  665.         return $path;
  666.     }
  667.  
  668.     function header($charset='utf-8'$plurals='nplurals=2; plural=n == 1 ? 0 : 1;'){
  669.         $year date('Y');
  670.         $comments = <<<EOT
  671. # Mambo Open Source.
  672. # Copyright (C) 2005 - $year Mambo Foundation Inc.
  673. # This file is distributed under the same license as the Mambo package.
  674. # Translation Team <translation@mambo-foundation.org>, $year#
  675. #
  676. #, fuzzy
  677. EOT;
  678.         $comments explode("\n"$comments);
  679.         $headers array(
  680.         'Project-Id-Version'    => 'Mambo 4.6',
  681.         'Report-Msgid-Bugs-To'  => 'translation@mambo-foundation.org',
  682.         'POT-Creation-Date'     => date('Y-m-d h:iO'),
  683.         'PO-Revision-Date'      => date('Y-m-d h:iO'),
  684.         'Last-Translator'       => 'Translation <translation@mambo-foundation.org>',
  685.         'Language-Team'         => 'Translation <translation@mambo-foundation.org>',
  686.         'MIME-Version'          => '1.0',
  687.         'Content-Type'          => 'text/plain; charset='.$charset,
  688.         'Content-Transfer-Encoding' => '8bit',
  689.         'Plural-Forms'              => $plurals
  690.         );
  691.         return array($comments$headers);
  692.     }
  693. }
  694.  
  695. /**
  696.  * Enter description here...
  697.  *
  698.  * @return unknown 
  699.  */
  700. function &phpgettext(){
  701.     static $gettext;
  702.     $root dirname(__FILE__);
  703.     if (is_null($gettext)) {
  704.         require_once($root.'/phpgettext.class.php');
  705.         $gettext new PHPGettext();
  706.         $gettext->has_gettext true;
  707.         if (!function_exists("gettext"|| !function_exists("_")) {
  708.             $gettext->has_gettext false;
  709.             require_once($root.'/phpgettext.compat.php');
  710.         }
  711.     }
  712.     return $gettext;
  713. }
  714. function T_($message{
  715.     $gettext =phpgettext();
  716.     $trans $gettext->gettext($message);
  717.     return $trans;
  718. }
  719. function Tn_($msg1$msg2$count{
  720.     $gettext =phpgettext();
  721.     return $gettext->ngettext($msg1$msg2$count);
  722. }
  723. function Td_($domain$message{
  724.     $gettext =phpgettext();
  725.     return $gettext->dgettext($domain$message);
  726. }
  727. function Tdn_($domain$msg1$msg2$count{
  728.     $gettext =phpgettext();
  729.     return $gettext->dngettext($domain$msg1$msg2$count);
  730. }
  731. ?>

Documentation generated on Mon, 05 May 2008 16:22:25 +0400 by phpDocumentor 1.4.0