PHP Class lithium\g11n\catalog\adapter\Gettext

The adapter works with the directory structure below. The example shows the structure for the directory as given by the 'path' configuration setting. It closely ressembles the standard gettext directory structure with a few slight adjustments to the way templates are being named. {{{ resources/g11n/po ├── | ├── LC_MESSAGES | | ├── default.po | | ├── default.mo | | ├── .po | | └── .mo | ├── LC_VALIDATION | | └── ... | └── ... ├── | └── ... ├── message_default.pot ├── message_.pot ├── validation_default.pot ├── validation_.pot └── ... }}}
See also: lithium\g11n\Locale
Inheritance: extends lithium\g11n\catalog\Adapter
显示文件 Open project: unionofrad/lithium Class Usage Examples

Public Methods

Method Description
__construct ( array $config = [] ) : void Constructor.
read ( string $category, string $locale, string $scope ) : array Reads data.
write ( string $category, string $locale, string $scope, array $data ) : boolean Writes data.

Protected Methods

Method Description
_compileMo ( resource $stream, array $data ) : void Compiles data into machine object (MO) format.
_compilePo ( resource $stream, array $data ) : boolean Compiles data into portable object (PO) format.
_compilePot ( resource $stream, array $data ) : boolean Compiles data into portable object template (POT) format.
_files ( string $category, string $locale, string $scope ) : array Returns absolute paths to files according to configuration.
_init ( ) : void Initializer. Checks if the configured path exists.
_merge ( array $data, array $item ) : array Merges an item into given data and unescapes fields.
_parseMo ( resource $stream ) : array Parses machine object (MO) format, independent of the machine's endian it was created on. Both 32bit and 64bit systems are supported.
_parsePo ( resource $stream ) : array Parses portable object (PO) format.
_parsePot ( resource $stream ) : array Parses portable object template (POT) format.
_prepareForWrite ( array $item ) : array Prepares an item before it is being written and escapes fields.
_readLong ( resource $stream, boolean $isBigEndian ) : integer Reads an unsigned long from stream respecting endianess.

Method Details

__construct() public method

Constructor.
public __construct ( array $config = [] ) : void
$config array Available configuration options are: - `'path'`: The path to the directory holding the data.
return void

_compileMo() protected method

Compiles data into machine object (MO) format.
protected _compileMo ( resource $stream, array $data ) : void
$stream resource
$data array
return void

_compilePo() protected method

To improve portability accross libraries the header is generated according to the format of the output of xgettext. This means using the same names for placeholders as well as including an empty entry. The empty entry at the beginning aids in parsing the file as it _attracts_ the preceding comments and following metadata when parsed which could otherwise be mistaken as a continued translation. The only difference in the header format is the initial header which just features one line of text.
protected _compilePo ( resource $stream, array $data ) : boolean
$stream resource
$data array
return boolean

_compilePot() protected method

Compiles data into portable object template (POT) format.
protected _compilePot ( resource $stream, array $data ) : boolean
$stream resource
$data array
return boolean Success.

_files() protected method

Returns absolute paths to files according to configuration.
protected _files ( string $category, string $locale, string $scope ) : array
$category string
$locale string
$scope string
return array

_init() protected method

Initializer. Checks if the configured path exists.
protected _init ( ) : void
return void

_merge() protected method

Please note that items with an id containing exclusively whitespace characters or are empty are **not** being merged. Whitespace characters are space, tab, vertical tab, line feed, carriage return and form feed.
See also: lithium\g11n\catalog\Adapter::_merge()
protected _merge ( array $data, array $item ) : array
$data array Data to merge item into.
$item array Item to merge into $data.
return array The merged data.

_parseMo() protected method

Parses machine object (MO) format, independent of the machine's endian it was created on. Both 32bit and 64bit systems are supported.
protected _parseMo ( resource $stream ) : array
$stream resource
return array

_parsePo() protected method

This parser sacrifices some features of the reference implementation the differences to that implementation are as follows. - No support for comments spanning multiple lines. - Translator and extracted comments are treated as being the same type. - Message IDs are allowed to have other encodings as just US-ASCII. Items with an empty id are ignored. For more information see _merge().
protected _parsePo ( resource $stream ) : array
$stream resource
return array

_parsePot() protected method

Parses portable object template (POT) format.
protected _parsePot ( resource $stream ) : array
$stream resource
return array

_prepareForWrite() protected method

All characters from \000 to \037 (this includes new line and tab characters) as well as the backslash (\) and the double quote (") are escaped. Literal Windows CRLFs (\r\n) are converted to LFs (\n) to improve cross platform compatibility. Escaped single quotes (') are unescaped as they should not need to be. Double escaped characters are maintained and not escaped once again.
See also: lithium\g11n\catalog\Adapter::_prepareForWrite()
protected _prepareForWrite ( array $item ) : array
$item array
return array

_readLong() protected method

Reads an unsigned long from stream respecting endianess.
protected _readLong ( resource $stream, boolean $isBigEndian ) : integer
$stream resource
$isBigEndian boolean
return integer

read() public method

Reads data.
public read ( string $category, string $locale, string $scope ) : array
$category string A category.
$locale string A locale identifier.
$scope string The scope for the current operation.
return array

write() public method

Writes data.
public write ( string $category, string $locale, string $scope, array $data ) : boolean
$category string A category.
$locale string A locale identifier.
$scope string The scope for the current operation.
$data array The data to write.
return boolean