PHP Class Prado\I18N\core\MessageFormat

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');
Exibir arquivo Open project: pradosoft/prado

Public Properties

Property Type Description
$Catalogue string Set the default catalogue.

Protected Properties

Property Type Description
$catagloues array A list of loaded message catalogues.
$charset string Output encoding charset
$messages array The translation messages.
$postscript array The prefix and suffix to append to untranslated messages.
$source MessageSource The message source.
$untranslated array A list of untranslated messages.

Public Methods

Method Description
__construct ( Prado\I18N\core\IMessageSource $source, $charset = 'UTF-8' ) Constructor.
format ( $string, $args = [], $catalogue = null, $charset = null ) : string 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.
getCharset ( ) : string Gets the charset for message output. Default is UTF-8.
getSource ( ) : MessageSource Get the message source.
setCharset ( $charset ) Sets the charset for message output.
setUntranslatedPS ( $postscript ) Set the prefix and suffix to append to untranslated messages.

Protected Methods

Method Description
formatString ( $string, $args = [], $catalogue = null ) : string Do string translation.
loadCatalogue ( $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.

Method Details

__construct() public method

Create a new instance of MessageFormat using the messages from the supplied message source.
public __construct ( Prado\I18N\core\IMessageSource $source, $charset = 'UTF-8' )
$source Prado\I18N\core\IMessageSource

format() public method

The output charset is determined by $this->getCharset();
public format ( $string, $args = [], $catalogue = null, $charset = null ) : string
return string translated string.

formatString() protected method

Do string translation.
protected formatString ( $string, $args = [], $catalogue = null ) : string
return string translated string.

getCharset() public method

Gets the charset for message output. Default is UTF-8.
public getCharset ( ) : string
return string charset, default UTF-8

getSource() public method

Get the message source.
public getSource ( ) : MessageSource
return MessageSource

loadCatalogue() protected method

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.
protected loadCatalogue ( $catalogue )

setCharset() public method

Sets the charset for message output.
public setCharset ( $charset )

setUntranslatedPS() public method

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

Property Details

$Catalogue public_oe property

Set the default catalogue.
public string $Catalogue
return string

$catagloues protected_oe property

A list of loaded message catalogues.
protected array $catagloues
return array

$charset protected_oe property

Output encoding charset
protected string $charset
return string

$messages protected_oe property

The translation messages.
protected array $messages
return array

$postscript protected_oe property

The prefix and suffix to append to untranslated messages.
protected array $postscript
return array

$source protected_oe property

The message source.
protected MessageSource,Prado\I18N\core $source
return MessageSource

$untranslated protected_oe property

A list of untranslated messages.
protected array $untranslated
return array