GettextMoFile
API reference › yii › i18n › GettextMoFile
GettextMoFile represents an MO Gettext message file.
This class is written by adapting Michael’s Gettext_MO class in PEAR. Please refer to the following license terms.
Copyright (c) 2004-2005, Michael Wallner <mike@iworks.at>. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$behaviors read-only | array<yii\<static>> | List of behaviors attached to this component. | yii\ |
$useBigEndian | bool | Whether to use big-endian when reading and writing an integer. Default: false. | GettextMoFile |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__clone() | This method is called after the object is created by cloning an existing one. | yii\ |
__get() | Returns the value of a component property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets the value of a component property. | yii\ |
__unset() | Sets a component property to be null. | yii\ |
attachBehavior() | Attaches a behavior to this component. | yii\ |
attachBehaviors() | Attaches a list of behaviors to the component. | yii\ |
behaviors() | Returns a list of behaviors that this component should behave as. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
detachBehavior() | Detaches a behavior from the component. | yii\ |
detachBehaviors() | Detaches all behaviors from the component. | yii\ |
ensureBehaviors() | Makes sure that the behaviors declared in behaviors() are attached to this component. | yii\ |
getBehavior() | Returns the named behavior object. | yii\ |
getBehaviors() | Returns all behaviors attached to this component. | yii\ |
hasEventHandlers() | Returns a value indicating whether there is any handler attached to the named event. | yii\ |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined for this component. | yii\ |
init() | Initializes the object. | yii\ |
load() | Loads messages from an MO file. | GettextMoFile |
off() | Detaches an existing event handler from this component. | yii\ |
on() | Attaches an event handler to an event. | yii\ |
save() | Saves messages to an MO file. | GettextMoFile |
trigger() | Triggers an event. | yii\ |
readBytes() protected | Reads one or several bytes. | GettextMoFile |
readInteger() protected | Reads a 4-byte integer. | GettextMoFile |
readString() protected | Reads a string. | GettextMoFile |
writeBytes() protected | Write bytes. | GettextMoFile |
writeInteger() protected | Writes a 4-byte integer. | GettextMoFile |
writeString() protected | Writes a string. | GettextMoFile |
Method details
Section titled “Method details”load()
Section titled “load() ”public function load(string $filePath, string $context): arrayLoads messages from an MO file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$filePath | string | File path |
$context | string | Message context |
Returns
array: Message translations. Array keys are source messages and array values are translated messages: source message => translated message.
Throws
yii\base\Exception: if unable to read the MO file
save()
Section titled “save() ”public function save(string $filePath, array $messages): mixedSaves messages to an MO file.
Parameters
| Parameter | Type | Description |
|---|---|---|
$filePath | string | File path |
$messages | array | Message translations. Array keys are source messages and array values are translated messages: source message => translated message. Note if the message has a context, the message ID must be prefixed with the context with chr(4) as the separator. |
Returns
mixed
Throws
yii\base\Exception: if unable to save the MO file
readBytes()
Section titled “readBytes() ”protected function readBytes(resource $fileHandle, int $byteCount = 1): string|nullReads one or several bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileHandle | resource | To read from |
$byteCount | int | To be read |
Returns
string|null: Bytes
readInteger()
Section titled “readInteger() ”protected function readInteger(resource $fileHandle): intReads a 4-byte integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileHandle | resource | To read from |
Returns
int: The result
readString()
Section titled “readString() ”protected function readString(resource $fileHandle, int $length, int|null $offset = null): string|nullReads a string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileHandle | resource | File handle |
$length | int | Of the string |
$offset | int| | Of the string in the file. If null, it reads from the current position. |
Returns
string|null: The result
writeBytes()
Section titled “writeBytes() ”protected function writeBytes(resource $fileHandle, string $bytes): intWrite bytes.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileHandle | resource | To write to |
$bytes | string | To be written |
Returns
int: How many bytes are written
writeInteger()
Section titled “writeInteger() ”protected function writeInteger(resource $fileHandle, int $integer): intWrites a 4-byte integer.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileHandle | resource | To write to |
$integer | int | To be written |
Returns
int: How many bytes are written
writeString()
Section titled “writeString() ”protected function writeString(resource $fileHandle, string $string): intWrites a string.
Parameters
| Parameter | Type | Description |
|---|---|---|
$fileHandle | resource | To write to |
$string | string | To be written |
Returns
int: How many bytes are written