PHP Класс 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');
Показать файл Открыть проект

Открытые свойства

Свойство Тип Описание
$Catalogue string Set the default catalogue.

Защищенные свойства (Protected)

Свойство Тип Описание
$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.

Открытые методы

Метод Описание
__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.

Защищенные методы

Метод Описание
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.

Описание методов

__construct() публичный Метод

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() публичный Метод

The output charset is determined by $this->getCharset();
public format ( $string, $args = [], $catalogue = null, $charset = null ) : string
Результат string translated string.

formatString() защищенный Метод

Do string translation.
protected formatString ( $string, $args = [], $catalogue = null ) : string
Результат string translated string.

getCharset() публичный Метод

Gets the charset for message output. Default is UTF-8.
public getCharset ( ) : string
Результат string charset, default UTF-8

getSource() публичный Метод

Get the message source.
public getSource ( ) : MessageSource
Результат MessageSource

loadCatalogue() защищенный Метод

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() публичный Метод

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

setUntranslatedPS() публичный Метод

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

Описание свойств

$Catalogue публичное свойство

Set the default catalogue.
public string $Catalogue
Результат string

$catagloues защищенное свойство

A list of loaded message catalogues.
protected array $catagloues
Результат array

$charset защищенное свойство

Output encoding charset
protected string $charset
Результат string

$messages защищенное свойство

The translation messages.
protected array $messages
Результат array

$postscript защищенное свойство

The prefix and suffix to append to untranslated messages.
protected array $postscript
Результат array

$source защищенное свойство

The message source.
protected MessageSource,Prado\I18N\core $source
Результат MessageSource

$untranslated защищенное свойство

A list of untranslated messages.
protected array $untranslated
Результат array