System.I18N.core
[ class tree: System.I18N.core ] [ index: System.I18N.core ] [ all elements ]

Class: MessageFormat

Source Location: /I18N/core/MessageFormat.php

Class Overview


MessageFormat class.

Class Details

[line 54]
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.

  1. $source = MessageSource::factory('SQLite', 'sqlite://messages.db');
  2. $source->setCulture('zh_CN');
  3. $source->setCache(new MessageCache('./tmp'));
  4.  
  5. $formatter = new MessageFormat($source);
  6.  
  7. 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>


[ Top ]

Variables

Methods



Class Variables

$catagloues = array()

[line 66]

A list of loaded message catalogues.



access:  protected

Type:   array


[ Top ]

$Catalogue =

[line 90]

Set the default catalogue.



access:  public

Type:   string


[ Top ]

$charset =  'UTF-8'

[line 96]

Output encoding charset



access:  protected

Type:   string


[ Top ]

$messages = array()

[line 72]

The translation messages.



access:  protected

Type:   array


[ Top ]

$postscript = array('','')

[line 84]

The prefix and suffix to append to untranslated messages.



access:  protected

Type:   array


[ Top ]

$source =

[line 60]

The message source.



access:  protected

Type:   MessageSource


[ Top ]

$untranslated = array()

[line 78]

A list of untranslated messages.



access:  protected

Type:   array


[ Top ]



Class Methods


constructor __construct [line 105]

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

Constructor.

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




Parameters:

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

[ Top ]

method format [line 161]

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

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


Parameters:

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.

[ Top ]

method formatString [line 176]

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

Do string translation.



return:  translated string.
access:  protected


Parameters:

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

[ Top ]

method getCharset [line 124]

string getCharset( )

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



return:  charset, default UTF-8
access:  public


[ Top ]

method getSource [line 231]

MessageSource getSource( )

Get the message source.



[ Top ]

method loadCatalogue [line 136]

void loadCatalogue( string $catalogue)

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


Parameters:

string   $catalogue   message catalogue to load.

[ Top ]

method setCharset [line 115]

void setCharset( string $charset)

Sets the charset for message output.



access:  public


Parameters:

string   $charset   charset, default is UTF-8

[ Top ]

method setUntranslatedPS [line 242]

void setUntranslatedPS( array $postscript)

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.




Parameters:

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

[ Top ]


© 2004-2005 PRADO Software Group. All Rights Reserved.