25 public $keys = array(
'fallback',
'messages',
'errorNames');
59 public static function instance($prototype = null)
61 static $instance = null;
62 if ($prototype !== null) {
63 $instance = $prototype;
64 } elseif ($instance === null || $prototype ==
true) {
78 $this->dir = HTMLPURIFIER_PREFIX .
'/HTMLPurifier';
88 public function create($config, $context, $code =
false)
91 if ($code ===
false) {
92 $code = $this->validator->validate(
93 $config->get(
'Core.Language'),
98 $code = $this->validator->validate($code, $config, $context);
100 if ($code ===
false) {
104 $pcode = str_replace(
'-',
'_', $code);
110 $class =
'HTMLPurifier_Language_' . $pcode;
111 $file = $this->dir .
'/Language/classes/' . $code .
'.php';
112 if (file_exists(
$file) || class_exists($class,
false)) {
113 $lang =
new $class($config, $context);
117 $fallback = $raw_fallback ? $raw_fallback :
'en';
120 if (!$raw_fallback) {
139 return $this->cache[$code][
'fallback'];
148 static $languages_seen = array();
151 if (isset($this->cache[$code])) {
156 $filename = $this->dir .
'/Language/messages/' . $code .
'.php';
159 $fallback = ($code !=
'en') ?
'en' :
false;
164 $filename = $this->dir .
'/Language/messages/en.php';
168 $cache = compact($this->keys);
175 if (isset($languages_seen[$code])) {
177 'Circular fallback reference in language ' .
183 $language_seen[$code] =
true;
187 $fallback_cache = $this->cache[
$fallback];
190 foreach ($this->keys as $key) {
191 if (isset(
$cache[$key]) && isset($fallback_cache[$key])) {
192 if (isset($this->mergeable_keys_map[$key])) {
194 } elseif (isset($this->mergeable_keys_list[$key])) {
195 $cache[$key] = array_merge($fallback_cache[$key],
$cache[$key]);
198 $cache[$key] = $fallback_cache[$key];
204 $this->cache[$code] =
$cache;