2007-01-29 20:11:00 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
require_once 'HTMLPurifier/LanguageFactory.php';
|
|
|
|
|
|
|
|
class HTMLPurifier_Language
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
|
|
|
* ISO 639 language code of language. Prefers shortest possible version
|
|
|
|
*/
|
|
|
|
var $code = 'en';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fallback language code
|
|
|
|
*/
|
|
|
|
var $fallback = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of localizable messages
|
|
|
|
*/
|
|
|
|
var $messages = array();
|
|
|
|
|
2007-06-24 23:20:35 +00:00
|
|
|
/**
|
|
|
|
* Array of localizable error codes
|
|
|
|
*/
|
|
|
|
var $errorNames = array();
|
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
/**
|
|
|
|
* Has the language object been loaded yet?
|
|
|
|
* @private
|
|
|
|
*/
|
|
|
|
var $_loaded = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads language object with necessary info from factory cache
|
|
|
|
* @note This is a lazy loader
|
|
|
|
*/
|
|
|
|
function load() {
|
|
|
|
if ($this->_loaded) return;
|
|
|
|
$factory = HTMLPurifier_LanguageFactory::instance();
|
|
|
|
$factory->loadLanguage($this->code);
|
|
|
|
foreach ($factory->keys as $key) {
|
|
|
|
$this->$key = $factory->cache[$this->code][$key];
|
|
|
|
}
|
|
|
|
$this->_loaded = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2007-06-18 02:25:27 +00:00
|
|
|
* Retrieves a localised message.
|
2007-01-29 20:11:00 +00:00
|
|
|
* @param $key string identifier of message
|
|
|
|
* @return string localised message
|
|
|
|
*/
|
|
|
|
function getMessage($key) {
|
|
|
|
if (!$this->_loaded) $this->load();
|
2007-06-18 02:25:27 +00:00
|
|
|
if (!isset($this->messages[$key])) return "[$key]";
|
2007-01-29 20:11:00 +00:00
|
|
|
return $this->messages[$key];
|
|
|
|
}
|
|
|
|
|
2007-06-24 23:20:35 +00:00
|
|
|
/**
|
|
|
|
* Retrieves a localised error name.
|
|
|
|
* @param $int integer error number, corresponding to PHP's error
|
|
|
|
* reporting
|
|
|
|
* @return string localised message
|
|
|
|
*/
|
|
|
|
function getErrorName($int) {
|
|
|
|
if (!$this->_loaded) $this->load();
|
|
|
|
if (!isset($this->errorNames[$int])) return "[Error: $int]";
|
|
|
|
return $this->errorNames[$int];
|
|
|
|
}
|
|
|
|
|
2007-06-18 02:25:27 +00:00
|
|
|
/**
|
|
|
|
* Formats a localised message with passed parameters
|
|
|
|
* @param $key string identifier of message
|
|
|
|
* @param $param Parameter to substitute in (arbitrary number)
|
|
|
|
* @return string localised message
|
|
|
|
*/
|
|
|
|
function formatMessage($key) {
|
|
|
|
if (!$this->_loaded) $this->load();
|
|
|
|
if (!isset($this->messages[$key])) return "[$key]";
|
|
|
|
$raw = $this->messages[$key];
|
|
|
|
$args = func_get_args();
|
|
|
|
$substitutions = array();
|
|
|
|
for ($i = 1; $i < count($args); $i++) {
|
|
|
|
$substitutions['$' . $i] = $args[$i];
|
|
|
|
}
|
|
|
|
return strtr($raw, $substitutions);
|
|
|
|
}
|
|
|
|
|
2007-01-29 20:11:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
?>
|