| 31 |
/** |
/** |
| 32 |
* Container for the loaded domains |
* Container for the loaded domains |
| 33 |
*/ |
*/ |
| 34 |
var $text_domains; |
var $text_domains = array(); |
| 35 |
|
|
| 36 |
/** |
/** |
| 37 |
* The asssociative array of messages for the current domain |
* The asssociative array of messages for the current domain |
| 38 |
*/ |
*/ |
| 39 |
var $messages; |
var $messages = array(); |
| 40 |
|
|
| 41 |
/** |
/** |
| 42 |
* The debugging flag |
* The debugging flag |
| 94 |
* debugging function |
* debugging function |
| 95 |
* |
* |
| 96 |
*/ |
*/ |
| 97 |
function debug($message, $untranslated = false){ |
function output($message, $untranslated = false){ |
| 98 |
|
switch ($this->debug) |
| 99 |
|
{ |
| 100 |
|
case 2: |
| 101 |
$trace = debug_backtrace(); |
$trace = debug_backtrace(); |
|
$str = sprintf('T_(%s)%s',$message, $untranslated ? ';' : ''); |
|
|
if ($this->debug > 1) { |
|
| 102 |
$html = '<span style="border-bottom: thin solid %s" title="%s(%d)">T_(%s)</span>'; |
$html = '<span style="border-bottom: thin solid %s" title="%s(%d)">T_(%s)</span>'; |
| 103 |
$str = sprintf($html, ($untranslated ? 'red' : 'green'), str_replace('\\', '/', $trace[2]['file']), $trace[2]['line'], $message); |
$str = sprintf($html, ($untranslated ? 'red' : 'green'), str_replace('\\', '/', $trace[2]['file']), $trace[2]['line'], $message); |
| 104 |
|
break; |
| 105 |
|
case 1: |
| 106 |
|
$str = sprintf('T_(%s)%s',$message, $untranslated ? ';' : ''); |
| 107 |
|
break; |
| 108 |
|
case 0: |
| 109 |
|
default: |
| 110 |
|
$str = $message; |
| 111 |
|
break; |
| 112 |
} |
} |
| 113 |
return $str; |
return $str; |
| 114 |
} |
} |
| 139 |
$translation = $this->messages[$this->domain][$message]; |
$translation = $this->messages[$this->domain][$message]; |
| 140 |
} |
} |
| 141 |
$untranslated = (strcmp($translation, $message) === 0) ? true : false; |
$untranslated = (strcmp($translation, $message) === 0) ? true : false; |
| 142 |
$translation = ($this->debug) ? $this->debug($translation, $untranslated) : $translation; |
return $this->output($translation, $untranslated); |
| 143 |
|
} |
| 144 |
|
|
| 145 |
|
/** |
| 146 |
|
* Override the current domain |
| 147 |
|
* The dgettext() function allows you to override the current domain for a single message lookup. |
| 148 |
|
*/ |
| 149 |
|
function dgettext($domain, $message){ |
| 150 |
|
$translation = $message; |
| 151 |
|
if (array_key_exists($domain, $this->messages)){ |
| 152 |
|
$translation = $this->messages[$domain][$message]; |
| 153 |
|
} |
| 154 |
|
$untranslated = (strcmp($translation, $message) === 0) ? true : false; |
| 155 |
|
return $this->output($translation, $untranslated); |
| 156 |
|
} |
| 157 |
|
|
| 158 |
|
/** |
| 159 |
|
* Plural version of gettext * |
| 160 |
|
* not yet implemented |
| 161 |
|
*/ |
| 162 |
|
function ngettext($msg1, $msg2, $count){ |
| 163 |
|
$translation = $msg1; |
| 164 |
|
if ($this->has_gettext){ |
| 165 |
|
$translation = ngettext($msg1, $msg2, $count); |
| 166 |
|
} |
| 167 |
|
if (isset( $this->messages[$this->domain][$msg1])) { |
| 168 |
|
$translation = $this->messages[$this->domain][$msg1]; |
| 169 |
return $translation; |
return $translation; |
| 170 |
} |
} |
| 171 |
|
dump($this); |
| 172 |
|
$untranslated = (strcmp($translation, $message) === 0) ? true : false; |
| 173 |
|
return $this->output($translation, $untranslated); |
| 174 |
|
} |
| 175 |
|
/** |
| 176 |
|
* Plural version of dgettext . |
| 177 |
|
* not yet implemented |
| 178 |
|
*/ |
| 179 |
|
function dngettext($domain, $msg1, $msg2, $count){ |
| 180 |
|
return $msg1; |
| 181 |
|
} |
| 182 |
|
|
| 183 |
/** |
/** |
| 184 |
* Specify the character encoding in which the messages |
* Specify the character encoding in which the messages |
| 219 |
return $this->domain = $domain; |
return $this->domain = $domain; |
| 220 |
} |
} |
| 221 |
|
|
|
/** |
|
|
* Override the current domain |
|
|
* The dgettext() function allows you to override the current domain for a single message lookup. |
|
|
*/ |
|
|
function dgettext($domain, $message){ |
|
|
if (array_key_exists($domain, $this->messages)) |
|
|
$translation = $this->messages[$domain][$message]; |
|
|
if ($translation) |
|
|
return $translation; |
|
|
|
|
|
return $message; |
|
|
} |
|
|
|
|
|
/** |
|
|
* Plural version of gettext * |
|
|
* not yet implemented |
|
|
*/ |
|
|
function ngettext($msg1, $msg2, $count){ |
|
|
if ($this->has_gettext){ |
|
|
$translation = ngettext($msg1, $msg2, $count); |
|
|
} |
|
|
if (isset( $this->messages[$this->domain][$msg1])) { |
|
|
$translation = $this->messages[$this->domain][$msg1]; |
|
|
return $translation; |
|
|
} |
|
|
return $translation; |
|
|
} |
|
|
/** |
|
|
* Plural version of dgettext . |
|
|
* not yet implemented |
|
|
*/ |
|
|
function dngettext($domain, $msg1, $msg2, $count){ |
|
|
return $msg1; |
|
|
} |
|
|
|
|
|
|
|
| 222 |
function load($domain, $path) { |
function load($domain, $path) { |
| 223 |
require_once('phpgettext.catalog.php'); |
require_once('phpgettext.catalog.php'); |
| 224 |
$catalog = new PHPGettext_catalog($domain, $path); |
$catalog = new PHPGettext_catalog($domain, $path); |