## Class MessageFormat

Description

MessageFormat class.

Format a message, that is, for a particular message find the translated message. The following is an example using a SQLite database to store the translation message. Create a new message format instance and echo "Hello" in simplified Chinese. This assumes that the world "Hello" is translated in the database.

      $source = MessageSource::factory('SQLite', 'sqlite://messages.db');
        $source->setCulture('zh_CN');
        $source->setCache(new MessageCache('./tmp'));

         $formatter = new MessageFormat($source);

        echo $formatter->format('Hello');

- version: v1.0, last update on Fri Dec 24 20:46:16 EST 2004
- author: Xiang Wei Zhuo <weizhuo[at]gmail[dot]com>

Located in /I18N/core/MessageFormat.php (line 54)

Variable Summary
array $catagloues
string $Catalogue
string $charset
array $messages
array $postscript
MessageSource $source
array $untranslated
Method Summary
MessageFormat __construct (IMessageSource $source, [string $charset = 'UTF-8'])
string format (string $string, [array $args = array()], [string $catalogue = null], [string $charset = null])
string formatString (string $string, [array $args = array()], [string $catalogue = null])
string getCharset ()
MessageSource getSource ()
void loadCatalogue (string $catalogue)
void setCharset (string $charset)
void setUntranslatedPS (array $postscript)
Variables
array $catagloues = array() (line 66)

A list of loaded message catalogues.

- access: protected

string $Catalogue (line 90)

Set the default catalogue.

- access: public

string $charset = 'UTF-8' (line 96)

Output encoding charset

- access: protected

array $messages = array() (line 72)

The translation messages.

- access: protected

array $postscript = array('','') (line 84)

The prefix and suffix to append to untranslated messages.

- access: protected

MessageSource $source (line 60)

The message source.

- access: protected

array $untranslated = array() (line 78)

A list of untranslated messages.

- access: protected

Methods
Constructor __construct (line 105)

Constructor.

Create a new instance of MessageFormat using the messages from the supplied message source.

MessageFormat __construct (IMessageSource $source, [string $charset = 'UTF-8'])

- MessageSource $source: the source of translation messages.
- string $charset: charset for the message output.

format (line 161)

Format the string. That is, for a particular string find the corresponding translation. Variable subsitution is performed for the $args parameter. A different catalogue can be specified using the $catalogue parameter.

The output charset is determined by $this->getCharset();

- return: translated string.
- access: public

string format (string $string, [array $args = array()], [string $catalogue = null], [string $charset = null])

- string $string: the string to translate.
- array $args: a list of string to substitute.
- string $catalogue: get the translation from a particular message
- string $charset: charset, the input AND output charset catalogue.

formatString (line 176)

Do string translation.

- return: translated string.
- access: protected

string formatString (string $string, [array $args = array()], [string $catalogue = null])

- string $string: the string to translate.
- array $args: a list of string to substitute.
- string $catalogue: get the translation from a particular message catalogue.

getCharset (line 124)

Gets the charset for message output. Default is UTF-8.

- return: charset, default UTF-8
- access: public

string getCharset ()
getSource (line 231)

Get the message source.

MessageSource getSource ()
loadCatalogue (line 136)

Load the message from a particular catalogue. A listed loaded catalogues is kept to prevent reload of the same catalogue. The load catalogue messages are stored in the $this->message array.

- access: protected

void loadCatalogue (string $catalogue)

- string $catalogue: message catalogue to load.

setCharset (line 115)

Sets the charset for message output.

- access: public

void setCharset (string $charset)

- string $charset: charset, default is UTF-8

setUntranslatedPS (line 242)

Set the prefix and suffix to append to untranslated messages.

e.g. $postscript=array('[T]','[/T]'); will output "[T]Hello[/T]" if the translation for "Hello" can not be determined.

void setUntranslatedPS (array $postscript)

- array $postscript: first element is the prefix, second element the suffix.

Documentation generated on Mon, 01 May 2006 23:02:38 -0400 by phpDocumentor 1.3.0RC4