Skip to content

Phalcon translate

NOTE

All classes are prefixed with Phalcon

Translate\Adapter\AbstractAdapter Abstract

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter
  • Uses

    • Phalcon\Support\Helper\Arr\Get
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • Extends

  • Implements

    • AdapterInterface

Class AbstractAdapter

@package Phalcon\Translate\Adapter

@property string $defaultInterpolator @property InterpolatorFactory $interpolatorFactory

Properties

/**
 * @var string
 */
protected $defaultInterpolator = ;

/**
    * @var InterpolatorFactory
    */
protected $interpolatorFactory;

Methods

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')

public function offsetExists( mixed $translateKey ): bool;
Check whether a translation key exists

public function offsetGet( mixed $translateKey ): mixed;
Returns the translation related to the given key

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

public function offsetUnset( mixed $offset ): void;
Unsets a translation from the dictionary

public function t( string $translateKey, array $placeholders = [] ): string;
Returns the translation string of the given key

protected function replacePlaceholders( string $translation, array $placeholders = [] ): string;
Replaces placeholders by the values passed

Translate\Adapter\AdapterInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter
  • Uses

  • Extends

  • Implements

Phalcon\Translate\Adapter\AdapterInterface

Interface for Phalcon\Translate adapters

Methods

public function has( string $index ): bool;
Check whether is defined a translation key in the internal array

public function query( string $translateKey, array $placeholders = [] ): string;
Returns the translation related to the given key

public function t( string $translateKey, array $placeholders = [] ): string;
Returns the translation string of the given key

Translate\Adapter\Csv

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter
  • Uses

    • ArrayAccess
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • Extends

    AbstractAdapter

  • Implements

    • ArrayAccess

Properties

/**
 * @var array
 */
protected $translate;

Methods

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

public function exists( string $index ): bool;
Check whether is defined a translation key in the internal array

public function has( string $index ): bool;
Check whether is defined a translation key in the internal array

public function query( string $translateKey, array $placeholders = [] ): string;
Returns the translation related to the given key

public function toArray(): array;
Returns the internal array

protected function phpFopen( string $filename, string $mode );
@todo to be removed when we get traits

Translate\Adapter\Gettext

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter
  • Uses

    • ArrayAccess
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • Extends

    AbstractAdapter

  • Implements

    • ArrayAccess

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 translate using gettext

@property int $category @property string $defaultDomain @property string|array $directory @property string|false $locale

Properties

/**
 * @var int
 */
protected $category;

/**
 * @var string
 */
protected $defaultDomain;

/**
 * @var string|array
 */
protected $directory;

/**
 * @var string
 */
protected $locale;

Methods

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

public function exists( string $index ): bool;
Check whether is defined a translation key in the internal array

public function getCategory(): int;
public function getDefaultDomain(): string;
public function getDirectory(): array | string;
public function getLocale(): string;

public function has( string $index ): bool;
Check whether is defined a translation key in the internal array

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.

public function query( string $translateKey, array $placeholders = [] ): string;
Returns the translation related to the given key.

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

public function resetDomain(): string;
Sets the default domain

public function setDefaultDomain( string $domain ): void;
Sets the domain default to search within when calls are made to gettext()

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",
    ]
);

public function setDomain( string $domain = null ): string;
Changes the current domain (i.e. the translation file)

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 function getOptionsDefault(): array;
Gets default options

protected function phpFunctionExists( string $name ): bool;
@todo to be removed when we get traits

protected function prepareOptions( array $options ): void;
Validator for constructor

Translate\Adapter\NativeArray

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter
  • Uses

    • ArrayAccess
    • Phalcon\Translate\Exception
    • Phalcon\Translate\InterpolatorFactory
  • Extends

    AbstractAdapter

  • Implements

    • ArrayAccess

Class NativeArray

Defines translation lists using PHP arrays

@package Phalcon\Translate\Adapter

@property array $translate @property bool $triggerError

Properties

/**
 * @var array
 */
private $translate;

/**
 * @var bool
 */
private $triggerError = false;

Methods

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

public function exists( string $index ): bool;
Check whether is defined a translation key in the internal array

public function has( string $index ): bool;
Check whether is defined a translation key in the internal array

public function notFound( string $index ): string;
Whenever a key is not found this method will be called

public function query( string $translateKey, array $placeholders = [] ): string;
Returns the translation related to the given key

public function toArray(): array;
Returns the internal array

Translate\Exception

Source on GitHub

  • Namespace

    • Phalcon\Translate
  • Uses

  • Extends

    \Exception

  • Implements

Phalcon\Translate\Exception

Class for exceptions thrown by Phalcon\Translate

Translate\Interpolator\AssociativeArray

Source on GitHub

  • Namespace

    • Phalcon\Translate\Interpolator
  • Uses

    • Phalcon\Support\Helper\Str\Interpolate
  • Extends

  • Implements

    • InterpolatorInterface

Class AssociativeArray

@package Phalcon\Translate\Interpolator

Methods

public function replacePlaceholders( string $translation, array $placeholders = [] ): string;
Replaces placeholders by the values passed

Translate\Interpolator\IndexedArray

Source on GitHub

  • Namespace

    • Phalcon\Translate\Interpolator
  • Uses

  • Extends

  • Implements

    • InterpolatorInterface

Class IndexedArray

@package Phalcon\Translate\Interpolator

Methods

public function replacePlaceholders( string $translation, array $placeholders = [] ): string;
Replaces placeholders by the values passed

Translate\Interpolator\InterpolatorInterface Interface

Source on GitHub

  • Namespace

    • Phalcon\Translate\Interpolator
  • Uses

  • Extends

  • Implements

Phalcon\Translate\InterpolatorInterface

Interface for Phalcon\Translate interpolators

Methods

public function replacePlaceholders( string $translation, array $placeholders = [] ): string;
Replaces placeholders by the values passed

Translate\InterpolatorFactory

Source on GitHub

  • Namespace

    • Phalcon\Translate
  • Uses

    • Phalcon\Factory\AbstractFactory
    • Phalcon\Translate\Interpolator\InterpolatorInterface
  • Extends

    AbstractFactory

  • Implements

This file is part of the Phalcon Framework.

(c) Phalcon Team team@phalcon.io

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

Methods

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

public function newInstance( string $name ): InterpolatorInterface;
Create a new instance of the adapter

protected function getExceptionClass(): string;

protected function getServices(): array;
Returns the available adapters

Translate\TranslateFactory

Source on GitHub

  • Namespace

    • Phalcon\Translate
  • Uses

    • Phalcon\Config\ConfigInterface
    • Phalcon\Factory\AbstractFactory
    • Phalcon\Translate\Adapter\AdapterInterface
  • Extends

    AbstractFactory

  • Implements

Class TranslateFactory

@package Phalcon\Translate

@property InterpolatorFactory $interpolator

Properties

/**
 * @var InterpolatorFactory
 */
private $interpolator;

Methods

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

public function load( mixed $config ): AdapterInterface;
Factory to create an instance from a Config object

public function newInstance( string $name, array $options = [] ): AdapterInterface;
Create a new instance of the adapter

protected function getExceptionClass(): string;

protected function getServices(): array;
Returns the available adapters