ILIAS  Release_4_1_x_branch Revision 61804
 All Data Structures Namespaces Files Functions Variables Groups Pages
HTMLPurifier_Language Class Reference

Represents a language and defines localizable string formatting and other functions, as well as the localized messages for HTML Purifier. More...

+ Inheritance diagram for HTMLPurifier_Language:
+ Collaboration diagram for HTMLPurifier_Language:

Public Member Functions

 __construct ($config, $context)
 load ()
 Loads language object with necessary info from factory cache.
 getMessage ($key)
 Retrieves a localised message.
 getErrorName ($int)
 Retrieves a localised error name.
 listify ($array)
 Converts an array list into a string readable representation.
 formatMessage ($key, $args=array())
 Formats a localised message with passed parameters.

Data Fields

 $code = 'en'
 ISO 639 language code of language.
 $fallback = false
 Fallback language code.
 $messages = array()
 Array of localizable messages.
 $errorNames = array()
 Array of localizable error codes.
 $error = false
 True if no message file was found for this language, so English is being used instead.
 $_loaded = false
 Has the language object been loaded yet?
 $context

Protected Attributes

 $config
 Instances of HTMLPurifier_Config and HTMLPurifier_Context.

Detailed Description

Represents a language and defines localizable string formatting and other functions, as well as the localized messages for HTML Purifier.

Definition at line 7 of file Language.php.

Constructor & Destructor Documentation

HTMLPurifier_Language::__construct (   $config,
  $context 
)

Definition at line 48 of file Language.php.

References $config, and $context.

{
$this->config = $config;
$this->context = $context;
}

Member Function Documentation

HTMLPurifier_Language::formatMessage (   $key,
  $args = array() 
)

Formats a localised message with passed parameters.

Parameters
$keystring identifier of message
$argsParameters to substitute in
Returns
string localised message
Todo:
Implement conditionals? Right now, some messages make reference to line numbers, but those aren't always available

Definition at line 117 of file Language.php.

References listify(), and load().

{
if (!$this->_loaded) $this->load();
if (!isset($this->messages[$key])) return "[$key]";
$raw = $this->messages[$key];
$subst = array();
$generator = false;
foreach ($args as $i => $value) {
if (is_object($value)) {
if ($value instanceof HTMLPurifier_Token) {
// factor this out some time
if (!$generator) $generator = $this->context->get('Generator');
if (isset($value->name)) $subst['$'.$i.'.Name'] = $value->name;
if (isset($value->data)) $subst['$'.$i.'.Data'] = $value->data;
$subst['$'.$i.'.Compact'] =
$subst['$'.$i.'.Serialized'] = $generator->generateFromToken($value);
// a more complex algorithm for compact representation
// could be introduced for all types of tokens. This
// may need to be factored out into a dedicated class
if (!empty($value->attr)) {
$stripped_token = clone $value;
$stripped_token->attr = array();
$subst['$'.$i.'.Compact'] = $generator->generateFromToken($stripped_token);
}
$subst['$'.$i.'.Line'] = $value->line ? $value->line : 'unknown';
}
continue;
} elseif (is_array($value)) {
$keys = array_keys($value);
if (array_keys($keys) === $keys) {
// list
$subst['$'.$i] = $this->listify($value);
} else {
// associative array
// no $i implementation yet, sorry
$subst['$'.$i.'.Keys'] = $this->listify($keys);
$subst['$'.$i.'.Values'] = $this->listify(array_values($value));
}
continue;
}
$subst['$' . $i] = $value;
}
return strtr($raw, $subst);
}

+ Here is the call graph for this function:

HTMLPurifier_Language::getErrorName (   $int)

Retrieves a localised error name.

Parameters
$intinteger error number, corresponding to PHP's error reporting
Returns
string localised message

Definition at line 84 of file Language.php.

References load().

{
if (!$this->_loaded) $this->load();
if (!isset($this->errorNames[$int])) return "[Error: $int]";
return $this->errorNames[$int];
}

+ Here is the call graph for this function:

HTMLPurifier_Language::getMessage (   $key)

Retrieves a localised message.

Parameters
$keystring identifier of message
Returns
string localised message

Definition at line 72 of file Language.php.

References load().

Referenced by listify().

{
if (!$this->_loaded) $this->load();
if (!isset($this->messages[$key])) return "[$key]";
return $this->messages[$key];
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_Language::listify (   $array)

Converts an array list into a string readable representation.

Definition at line 93 of file Language.php.

References $ret, and getMessage().

Referenced by formatMessage().

{
$sep = $this->getMessage('Item separator');
$sep_last = $this->getMessage('Item separator last');
$ret = '';
for ($i = 0, $c = count($array); $i < $c; $i++) {
if ($i == 0) {
} elseif ($i + 1 < $c) {
$ret .= $sep;
} else {
$ret .= $sep_last;
}
$ret .= $array[$i];
}
return $ret;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

HTMLPurifier_Language::load ( )

Loads language object with necessary info from factory cache.

Note
This is a lazy loader

Definition at line 57 of file Language.php.

References $code, and HTMLPurifier_LanguageFactory\instance().

Referenced by formatMessage(), getErrorName(), and getMessage().

{
if ($this->_loaded) return;
$factory->loadLanguage($this->code);
foreach ($factory->keys as $key) {
$this->$key = $factory->cache[$this->code][$key];
}
$this->_loaded = true;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

HTMLPurifier_Language::$_loaded = false

Has the language object been loaded yet?

Todo:
Make it private, fix usage in HTMLPurifier_LanguageTest

Definition at line 41 of file Language.php.

HTMLPurifier_Language::$code = 'en'

ISO 639 language code of language.

Prefers shortest possible version

Definition at line 13 of file Language.php.

Referenced by load().

HTMLPurifier_Language::$config
protected

Instances of HTMLPurifier_Config and HTMLPurifier_Context.

Definition at line 46 of file Language.php.

Referenced by __construct().

HTMLPurifier_Language::$context

Definition at line 46 of file Language.php.

Referenced by __construct().

HTMLPurifier_Language::$error = false

True if no message file was found for this language, so English is being used instead.

Check this if you'd like to notify the user that they've used a non-supported language.

Definition at line 35 of file Language.php.

HTMLPurifier_Language::$errorNames = array()

Array of localizable error codes.

Definition at line 28 of file Language.php.

HTMLPurifier_Language::$fallback = false

Fallback language code.

Definition at line 18 of file Language.php.

HTMLPurifier_Language::$messages = array()

Array of localizable messages.

Definition at line 23 of file Language.php.


The documentation for this class was generated from the following file: