Skip to content

NOTE

All classes are prefixed with Phalcon

Translate\Adapter\AbstractAdapter Abstract

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter
  • Uses

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

  • Implements

    • AdapterInterface

Properties

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

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

Methods

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

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 Abstract

Source on GitHub

  • Namespace

    • Phalcon\Translate\Adapter

Phalcon\Translate\Adapter\AdapterInterface

Interface for Phalcon\Translate adapters

Methods

public function exists( 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

Allows to define translation lists using CSV file

Properties

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

Methods

public function __construct( InterpolatorFactory $interpolator, array $options );
Phalcon\Translate\Adapter\Csv constructor

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

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

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

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 );
Phalcon\Translate\Adapter\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(): string|array;
public function getLocale(): string;

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 $index, 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( mixed $domain ): string;
Changes the current domain (i.e. the translation file)

public function setLocale( int $category, string $locale ): 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 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

Allows to define translation lists using PHP arrays

Properties

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

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

Methods

public function __construct( InterpolatorFactory $interpolator, array $options );
Phalcon\Translate\Adapter\NativeArray constructor

public function exists( 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 $index, array $placeholders = [] ): string;
Returns the translation related to the given key

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\Helper\Str\Interpolate
  • Extends

  • Implements

    • InterpolatorInterface

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

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

Methods

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

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

protected function getAdapters(): array;

Class Phalcon\Translate\TranslateFactory

Source on GitHub

| Namespace | Phalcon\Translate | | Uses | Phalcon\Config, Phalcon\Factory\AbstractFactory, Phalcon\Helper\Arr, Phalcon\Translate\Adapter\AdapterInterface | | Extends | AbstractFactory |

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.

Properties

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

Methods

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

public function load( mixed $config ): mixed;
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 getAdapters(): array;