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
Afficher le fichier Open project: unionofrad/lithium Class Usage Examples

Méthodes publiques

Méthode 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.

Méthodes protégées

Méthode 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 méthode

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

_compileMo() protected méthode

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

_compilePo() protected méthode

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
Résultat boolean

_compilePot() protected méthode

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

_files() protected méthode

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

_init() protected méthode

Initializer. Checks if the configured path exists.
protected _init ( ) : void
Résultat void

_merge() protected méthode

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.
Résultat array The merged data.

_parseMo() protected méthode

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
Résultat array

_parsePo() protected méthode

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
Résultat array

_parsePot() protected méthode

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

_prepareForWrite() protected méthode

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
Résultat array

_readLong() protected méthode

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

read() public méthode

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.
Résultat array

write() public méthode

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.
Résultat boolean