Skip to content
PHP Ecosystem
Explore

GettextMoFile

API reference › yii › i18n › GettextMoFile

classyii\i18n\GettextMoFile
ExtendsGettextFile » yii\base\Component » yii\base\BaseObject
Implementsyii\base\Configurable
Since2.0
Sourceframework/i18n/GettextMoFile.php

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.

PropertyTypeDescriptionDefined by
$behaviors read-onlyarray<yii\base\Behavior<static>>List of behaviors attached to this component.yii\base\Component
$useBigEndianboolWhether to use big-endian when reading and writing an integer. Default: false.GettextMoFile
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\Component
__clone()This method is called after the object is created by cloning an existing one.yii\base\Component
__get()Returns the value of a component property.yii\base\Component
__isset()Checks if a property is set, i.e. defined and not null.yii\base\Component
__set()Sets the value of a component property.yii\base\Component
__unset()Sets a component property to be null.yii\base\Component
attachBehavior()Attaches a behavior to this component.yii\base\Component
attachBehaviors()Attaches a list of behaviors to the component.yii\base\Component
behaviors()Returns a list of behaviors that this component should behave as.yii\base\Component
canGetProperty()Returns a value indicating whether a property can be read.yii\base\Component
canSetProperty()Returns a value indicating whether a property can be set.yii\base\Component
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
detachBehavior()Detaches a behavior from the component.yii\base\Component
detachBehaviors()Detaches all behaviors from the component.yii\base\Component
ensureBehaviors()Makes sure that the behaviors declared in behaviors() are attached to this component.yii\base\Component
getBehavior()Returns the named behavior object.yii\base\Component
getBehaviors()Returns all behaviors attached to this component.yii\base\Component
hasEventHandlers()Returns a value indicating whether there is any handler attached to the named event.yii\base\Component
hasMethod()Returns a value indicating whether a method is defined.yii\base\Component
hasProperty()Returns a value indicating whether a property is defined for this component.yii\base\Component
init()Initializes the object.yii\base\BaseObject
load()Loads messages from an MO file.GettextMoFile
off()Detaches an existing event handler from this component.yii\base\Component
on()Attaches an event handler to an event.yii\base\Component
save()Saves messages to an MO file.GettextMoFile
trigger()Triggers an event.yii\base\Component
readBytes() protectedReads one or several bytes.GettextMoFile
readInteger() protectedReads a 4-byte integer.GettextMoFile
readString() protectedReads a string.GettextMoFile
writeBytes() protectedWrite bytes.GettextMoFile
writeInteger() protectedWrites a 4-byte integer.GettextMoFile
writeString() protectedWrites a string.GettextMoFile
public function load(string $filePath, string $context): array

Loads messages from an MO file.

Parameters

ParameterTypeDescription
$filePathstringFile path
$contextstringMessage context

Returns

array: Message translations. Array keys are source messages and array values are translated messages: source message => translated message.

Throws

public function save(string $filePath, array $messages): mixed

Saves messages to an MO file.

Parameters

ParameterTypeDescription
$filePathstringFile path
$messagesarrayMessage 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

protected function readBytes(resource $fileHandle, int $byteCount = 1): string|null

Reads one or several bytes.

Parameters

ParameterTypeDescription
$fileHandleresourceTo read from
$byteCountintTo be read

Returns

string|null: Bytes

protected function readInteger(resource $fileHandle): int

Reads a 4-byte integer.

Parameters

ParameterTypeDescription
$fileHandleresourceTo read from

Returns

int: The result

protected function readString(resource $fileHandle, int $length, int|null $offset = null): string|null

Reads a string.

Parameters

ParameterTypeDescription
$fileHandleresourceFile handle
$lengthintOf the string
$offsetint|nullOf the string in the file. If null, it reads from the current position.

Returns

string|null: The result

protected function writeBytes(resource $fileHandle, string $bytes): int

Write bytes.

Parameters

ParameterTypeDescription
$fileHandleresourceTo write to
$bytesstringTo be written

Returns

int: How many bytes are written

protected function writeInteger(resource $fileHandle, int $integer): int

Writes a 4-byte integer.

Parameters

ParameterTypeDescription
$fileHandleresourceTo write to
$integerintTo be written

Returns

int: How many bytes are written

protected function writeString(resource $fileHandle, string $string): int

Writes a string.

Parameters

ParameterTypeDescription
$fileHandleresourceTo write to
$stringstringTo be written

Returns

int: How many bytes are written