Erebot  latest
A modular IRC bot for PHP 5.3+
Erebot\Intl Class Reference

A class which provides translations for messages used by the core and modules. More...

+ Inheritance diagram for Erebot\Intl:

Public Member Functions

 _ ($message)
 
 __construct ($component)
 
 getLocale ($category)
 
 gettext ($message)
 
 setLocale ($category, $candidates)
 

Static Public Member Functions

static categoryToName ($category)
 
static clearCache ()
 
static nameToCategory ($name)
 

Public Attributes

const EXPIRE_CACHE = 60
 Expiration time of entries in the cache (in seconds).
 
- Public Attributes inherited from Erebot\IntlInterface
const LC_ADDRESS = 9
 Address formats and location information.
 
const LC_ALL = 6
 Overrides the value for all the other LC_* constants.
 
const LC_COLLATE = 3
 Collation order.
 
const LC_CTYPE = 0
 Character classification and case conversion.
 
const LC_IDENTIFICATION = 12
 Metadata about the locale information.
 
const LC_MEASUREMENT = 11
 Measurement units (Metric or Other).
 
const LC_MESSAGES = 5
 
const LC_MONETARY = 4
 Monetary formats.
 
const LC_NAME = 8
 Name formats.
 
const LC_NUMERIC = 1
 Non-monetary numeric formats.
 
const LC_PAPER = 7
 Paper size.
 
const LC_TELEPHONE = 10
 Telephone number formats.
 
const LC_TIME = 2
 Date and time formats.
 

Protected Member Functions

 getTranslation ($component, $message)
 
 reallyGetText ($message, $component)
 

Protected Attributes

 $component
 The component to get translations from (a module name or "Erebot").
 
 $locales
 The actual locales used for i18n.
 

Static Protected Attributes

static $cache = array()
 A cache for translation catalogs, with some additional metadata.
 

Private Member Functions

 getBaseDir ($component)
 

Detailed Description

A class which provides translations for messages used by the core and modules.

Definition at line 28 of file Intl.php.

Constructor & Destructor Documentation

Erebot\Intl::__construct (   $component)

Creates a new translator for messages.

Parameters
string$componentThe name of the component to use for translations. This should be set to the name of the module or "Erebot" for the core.

Definition at line 50 of file Intl.php.

Member Function Documentation

Erebot\Intl::_ (   $message)

Translates the given message using the translations for the current component.

Parameters
string$messageThe original message to translate, in US English.
Return values
stringThe message, translated into the selected locale.
Note
This method is an alias for Erebot::IntlInterface::gettext

Implements Erebot\IntlInterface.

Definition at line 349 of file Intl.php.

static Erebot\Intl::categoryToName (   $category)
static

Returns the name associated with a given category.

Parameters
opaque$categoryOne of the constants defined in Erebot::IntlInterface, eg. Erebot::IntlInterface::LC_MESSAGES.
Return values
stringThe name of that category (eg. "LC_MESSAGES").

Implements Erebot\IntlInterface.

Definition at line 97 of file Intl.php.

static Erebot\Intl::clearCache ( )
static

Clears the cache used for translation catalogs.

Return values
Thismethod does not return any value.

Definition at line 360 of file Intl.php.

Erebot\Intl::getLocale (   $category)

Returns the target locale of this translator in canonical form for a given catergory.

Parameters
opaque$categoryOne of the constants defined in Erebot::IntlInterface indicating the category we're interested in querying. For the most basic usage, you should pass Erebot::IntlInterface::LC_MESSAGES as the category.
Return values
stringThe canonical form of the target locale for this translator.

Implements Erebot\IntlInterface.

Definition at line 119 of file Intl.php.

Erebot\Intl::gettext (   $message)

Translates the given message using the translations for the current component.

Parameters
string$messageThe original message to translate, in US English.
Return values
stringThe message, translated into the selected locale.

Implements Erebot\IntlInterface.

Definition at line 344 of file Intl.php.

Erebot\Intl::getTranslation (   $component,
  $message 
)
protected

Returns the translation for the given message, as contained in some translation catalog (MO file).

Parameters
string$filePath to the translation catalog to use.
string$messageThe message to translate.
string$modeEither "MO" or "PO", indicating whether the given file refers to a MO or PO catalog.
Return values
stringThe translation matching the given message.
nullThe message could not be found in the translation catalog.
Note
This method implements a caching strategy so that the translation catalog is not read again every time this method is called but only when the catalog actually changed.

Definition at line 241 of file Intl.php.

static Erebot\Intl::nameToCategory (   $name)
static

Returns the value of the category matching the given name.

Parameters
string$nameA category name, such as "LC_MESSAGES".
Return values
opaqueThe corresponding category, returned as one of the constants in Erebot::IntlInterface, eg. Erebot::IntlInterface::LC_MESSAGES.

Implements Erebot\IntlInterface.

Definition at line 73 of file Intl.php.

Erebot\Intl::reallyGetText (   $message,
  $component 
)
protected

Low-level translation method.

Parameters
string$messageThe message to translate.
string$componentThe name of the component this translation belongs to, such as "Erebot" for core messages or "Erebot_Module_ABC" for messages belonging to the module named "Erebot_Module_ABC".
Return values
stringEither the translation for the given message is returned, or the original message if none could be found.

Definition at line 335 of file Intl.php.

Erebot\Intl::setLocale (   $category,
  $candidates 
)

Sets the target locale of this translator for a given catergory.

Parameters
opaque$categoryOne of the constants defined in Erebot::IntlInterface indicating the category we're interested in setting. For the most basic usage, you should pass Erebot::IntlInterface::LC_MESSAGES as the category.
array$candidatesArray of locales that can be used. The candidate locales will be reviewed in order and the first one to match a locale available to the bot will be used as the effective locale.
Return values
stringThe locale effectively in use after this method has been called, in its canonical form.
Note
The bot assumes the "en_US" locale is always available. If none of the given candidates matches a locale available to the bot, "en_US" will automatically be selected as the locale to use.

Implements Erebot\IntlInterface.

Definition at line 140 of file Intl.php.


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