Skip to content

Phalcon Translate

Updated View as Markdown

Translate\Adapter\AbstractAdapter

AbstractSource on GitHub

@psalm-type TOptions array{ defaultInterpolator?: string }

@template TKey of string @template TValue of string @implements ArrayAccess<TKey, TValue>

Uses ArrayAccess · Phalcon\Translate\Exceptions\ImmutableObject · Phalcon\Translate\InterpolatorFactory

Method Summary

Properties

protectedstring$defaultInterpolator = ""
protectedInterpolatorFactory$interpolatorFactory

Methods

Public · 7

__construct()

public function __construct(
    InterpolatorFactory $interpolator,
    array $options = []
);

AbstractAdapter constructor.

_()

public function _(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation string of the given key (alias of method ‘t’)

offsetExists()

public function offsetExists( mixed $translateKey ): bool;

Check whether a translation key exists

offsetGet()

public function offsetGet( mixed $translateKey ): string|null;

Returns the translation related to the given key

offsetSet()

public function offsetSet(
    mixed $offset,
    mixed $value
): void;

Sets a translation value

offsetUnset()

public function offsetUnset( mixed $offset ): void;

Unsets a translation from the dictionary

t()

public function t(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation string of the given key

Protected · 1

replacePlaceholders()

protected function replacePlaceholders(
    string $translation,
    array $placeholders = []
): string;

Replaces placeholders by the values passed

Translate\Adapter\AdapterInterface

InterfaceSource on GitHub

Phalcon\Translate\Adapter\AdapterInterface

Interface for Phalcon\Translate adapters

  • Phalcon\Translate\Adapter\AdapterInterface

Method Summary

Methods

Public · 3

has()

public function has( string $index ): bool;

Check whether is defined a translation key in the internal array

query()

public function query(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation related to the given key

t()

public function t(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation string of the given key

Translate\Adapter\Csv

ClassSource on GitHub

Uses Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\FileOpenError · Phalcon\Translate\Exceptions\MissingRequiredParameter · Phalcon\Translate\InterpolatorFactory

Method Summary

Properties

protectedarray$translate = []

Methods

Public · 5

__construct()

public function __construct(
    InterpolatorFactory $interpolator,
    array $options
);

Csv constructor.

exists()

public function exists( string $index ): bool;

Check whether is defined a translation key in the internal array

has()

public function has( string $index ): bool;

Check whether is defined a translation key in the internal array

query()

public function query(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation related to the given key

toArray()

public function toArray(): array;

Returns the internal array

Protected · 1

phpFopen()

protected function phpFopen(
    string $filename,
    string $mode
);

@todo to be removed when we get traits

Translate\Adapter\Gettext

ClassSource on GitHub

Phalcon\Translate\Adapter\Gettext

use Phalcon\Translate\Adapter\Gettext;

$adapter = new Gettext(
    [
        "locale"        => "de_DE.UTF-8",
        "defaultDomain" => "translations",
        "directory"     => "/path/to/application/locales",
        "category"      => LC_MESSAGES,
    ]
);

Allows translations using gettext

Uses Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\MissingGettextExtension · Phalcon\Translate\Exceptions\MissingRequiredParameter · Phalcon\Translate\InterpolatorFactory

Method Summary

Properties

protectedint$category
protectedstring$defaultDomain
protectedstring|array$directory
protectedstring | false$locale

Methods

Public · 14

__construct()

public function __construct(
    InterpolatorFactory $interpolator,
    array $options
);

Gettext constructor.

exists()

public function exists( string $index ): bool;

Check whether is defined a translation key in the internal array

getCategory()

public function getCategory(): int;

getDefaultDomain()

public function getDefaultDomain(): string;

getDirectory()

public function getDirectory(): array|string;

getLocale()

public function getLocale(): string|false;

has()

public function has( string $index ): bool;

Check whether is defined a translation key in the internal array

nquery()

public function nquery(
    string $msgid1,
    string $msgid2,
    int $count,
    array $placeholders = [],
    string $domain = null
): string;

The plural version of gettext(). Some languages have more than one form for plural messages dependent on the count.

query()

public function query(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation related to the given key.

$translator->query("你好 %name%!", ["name" => "Phalcon"]);

resetDomain()

public function resetDomain(): string;

Sets the default domain

setDefaultDomain()

public function setDefaultDomain( string $domain ): void;

Sets the domain default to search within when calls are made to gettext()

setDirectory()

public function setDirectory( mixed $directory ): void;

Sets the path for a domain

// Set the directory path
$gettext->setDirectory("/path/to/the/messages");

// Set the domains and directories path
$gettext->setDirectory(
    [
        "messages" => "/path/to/the/messages",
        "another"  => "/path/to/the/another",
    ]
);

setDomain()

public function setDomain( string $domain = null ): string;

Changes the current domain (i.e. the translation file)

setLocale()

public function setLocale(
    int $category,
    array $localeArray = []
): string|bool;

Sets locale information

// Set locale to Dutch
$gettext->setLocale(LC_ALL, ["nl_NL"]);

// Try different possible locale names for German
$gettext->setLocale(LC_ALL, ["de_DE@euro", "de_DE", "de", "ge"]);
Protected · 3

getOptionsDefault()

protected function getOptionsDefault(): array;

Gets default options

phpFunctionExists()

protected function phpFunctionExists( string $name ): bool;

@todo to be removed when we get traits

prepareOptions()

protected function prepareOptions( array $options ): void;

Validator for constructor

Translate\Adapter\NativeArray

ClassSource on GitHub

Defines translation lists using PHP arrays

Uses Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\InvalidDataType · Phalcon\Translate\Exceptions\KeyNotFound · Phalcon\Translate\Exceptions\MissingContent · Phalcon\Translate\InterpolatorFactory

Method Summary

Methods

Public · 6

__construct()

public function __construct(
    InterpolatorFactory $interpolator,
    array $options
);

NativeArray constructor.

exists()

public function exists( string $index ): bool;

Check whether is defined a translation key in the internal array

has()

public function has( string $index ): bool;

Check whether is defined a translation key in the internal array

notFound()

public function notFound( string $index ): string;

Whenever a key is not found this method will be called

query()

public function query(
    string $translateKey,
    array $placeholders = []
): string;

Returns the translation related to the given key

toArray()

public function toArray(): array;

Returns the internal array

Translate\Exception

ClassSource on GitHub

Class for exceptions thrown by Phalcon\Translate

Translate\Exceptions\FileOpenError

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $name );

Translate\Exceptions\ImmutableObject

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Translate\Exceptions\InterpolatorNotRegistered

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Translate\Exceptions\InvalidDataType

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Translate\Exceptions\KeyNotFound

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct( string $key );

Translate\Exceptions\MissingContent

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Translate\Exceptions\MissingGettextExtension

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 1

__construct()

public function __construct();

Translate\Exceptions\MissingRequiredParameter

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Method Summary

Methods

Public · 2

__construct()

public function __construct( string $parameter );

getParameter()

public function getParameter(): string;

Translate\Exceptions\TranslatorNotRegistered

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Translate\Exception

Translate\InterpolatorFactory

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Uses Phalcon\Factory\AbstractFactory · Phalcon\Translate\Interpolator\InterpolatorInterface

Method Summary

Methods

Public · 2

__construct()

public function __construct( array $services = [] );

newInstance()

public function newInstance( string $name ): InterpolatorInterface;

Create a new instance of the adapter

Protected · 2

getExceptionClass()

protected function getExceptionClass(): string;

getServices()

protected function getServices(): array;

Returns the available adapters

Translate\Interpolator\AssociativeArray

ClassSource on GitHub

Class AssociativeArray

Uses Phalcon\Support\Helper\Str\Interpolate

Method Summary

Methods

Public · 1

replacePlaceholders()

public function replacePlaceholders(
    string $translation,
    array $placeholders = []
): string;

Replaces placeholders by the values passed

Translate\Interpolator\IndexedArray

ClassSource on GitHub

This file is part of the Phalcon Framework.

(c) Phalcon Team <[email protected]>

For the full copyright and license information, please view the LICENSE.txt file that was distributed with this source code.

Method Summary

Methods

Public · 1

replacePlaceholders()

public function replacePlaceholders(
    string $translation,
    array $placeholders = []
): string;

Replaces placeholders by the values passed

Translate\Interpolator\InterpolatorInterface

InterfaceSource on GitHub

Phalcon\Translate\InterpolatorInterface

Interface for Phalcon\Translate interpolators

  • Phalcon\Translate\Interpolator\InterpolatorInterface

Method Summary

Methods

Public · 1

replacePlaceholders()

public function replacePlaceholders(
    string $translation,
    array $placeholders = []
): string;

Replaces placeholders by the values passed

Translate\TranslateFactory

ClassSource on GitHub

@property InterpolatorFactory $interpolator

@psalm-type TConfig array{ adapter: string, options?: array{ content: string, delimiter: string, enclosure: string, locale: string, defaultDomain: string, directory: string, category: string, triggerError: bool, } }

Uses Phalcon\Config\ConfigInterface · Phalcon\Factory\AbstractFactory · Phalcon\Translate\Adapter\AdapterInterface

Method Summary

Methods

Public · 3

__construct()

public function __construct(
    InterpolatorFactory $interpolator,
    array $services = []
);

load()

public function load( mixed $config ): AdapterInterface;

Factory to create an instance from a Config object

newInstance()

public function newInstance(
    string $name,
    array $options = []
): AdapterInterface;

Create a new instance of the adapter

Protected · 2

getExceptionClass()

protected function getExceptionClass(): string;

getServices()

protected function getServices(): array;

Returns the available adapters

Type to search…

↑↓ navigate↵ selectEsc close