Translate\Adapter\AbstractAdapter
AbstractSource on GitHub@template TKey of string @template TValue of string @implements ArrayAccess<TKey, TValue>
Phalcon\Translate\Adapter\AbstractAdapter- implementsPhalcon\Translate\Adapter\AdapterInterface,ArrayAccess
Uses ArrayAccess · Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\ImmutableObject · Phalcon\Translate\Exceptions\KeyNotFound · Phalcon\Translate\InterpolatorFactory · Phalcon\Translate\Interpolator\InterpolatorInterface
Method Summary
public__construct(InterpolatorFactory$interpolator,array$options = [])AbstractAdapter constructor.publicstring_(string$translateKey,array$placeholders = [])Returns the translation string of the given key (alias of method 't')publicstringnotFound( string$index )Whenever a key is not found this method will be calledpublicbooloffsetExists( mixed$translateKey )Check whether a translation key existspublicstring|nulloffsetGet( mixed$translateKey )Returns the translation related to the given keypublicvoidoffsetSet(mixed$offset,mixed$value)Sets a translation valuepublicvoidoffsetUnset( mixed$offset )Unsets a translation from the dictionarypublicstringt(string$translateKey,array$placeholders = [])Returns the translation string of the given keyprotectedstringreplacePlaceholders(string$translation,array$placeholders = [])Replaces placeholders by the values passedProperties
protectedstring$defaultInterpolator = ""protectedInterpolatorInterface | null$interpolator = nullprotectedInterpolatorFactory$interpolatorFactoryprotectedbool$triggerError = falseMethods
__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’)
notFound()
public function notFound( string $index ): string;Whenever a key is not found this method will be called
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
replacePlaceholders()
protected function replacePlaceholders(
string $translation,
array $placeholders = []
): string;Replaces placeholders by the values passed
Translate\Adapter\AdapterInterface
InterfaceSource on GitHubPhalcon\Translate\Adapter\AdapterInterface
Interface for Phalcon\Translate adapters
Phalcon\Translate\Adapter\AdapterInterface
Method Summary
publicboolhas( string$index )Check whether is defined a translation key in the internal arraypublicstringquery(string$translateKey,array$placeholders = [])Returns the translation related to the given keypublicstringt(string$translateKey,array$placeholders = [])Returns the translation string of the given keyMethods
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
Missing-key semantics differ per adapter:
| Adapter | Missing key returns | Strict mode (triggerError) |
|---|---|---|
| NativeArray | the key, not interpolated | yes |
| Csv | the key, interpolated | yes |
| Gettext | the msgid (gettext) | yes |
With strict mode enabled (the triggerError option) a missing key
throws KeyNotFound instead of falling back.
t()
public function t(
string $translateKey,
array $placeholders = []
): string;Returns the translation string of the given key
Translate\Adapter\Csv
ClassSource on GitHubPhalcon\Translate\Adapter\AbstractAdapterPhalcon\Translate\Adapter\Csv
Uses Phalcon\Traits\Php\FileTrait · Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\FileOpenError · Phalcon\Translate\Exceptions\MissingRequiredParameter · Phalcon\Translate\InterpolatorFactory
Method Summary
public__construct(InterpolatorFactory$interpolator,array$options)Csv constructor.publicboolexists( string$index )Check whether is defined a translation key in the internal arraypublicboolhas( string$index )Check whether is defined a translation key in the internal arraypublicstringquery(string$translateKey,array$placeholders = [])Returns the translation related to the given keypublicarraytoArray()Returns the internal arrayProperties
protectedarray$translate = []Methods
__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
Translate\Adapter\Gettext
ClassSource on GitHubPhalcon\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
Phalcon\Translate\Adapter\AbstractAdapterPhalcon\Translate\Adapter\Gettext
Uses Phalcon\Traits\Php\InfoTrait · Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\MissingGettextExtension · Phalcon\Translate\Exceptions\MissingRequiredParameter · Phalcon\Translate\InterpolatorFactory
Method Summary
public__construct(InterpolatorFactory$interpolator,array$options)Gettext constructor.publicboolexists( string$index )Check whether is defined a translation key in the internal arraypublicintgetCategory()publicstringgetDefaultDomain()publicarray|stringgetDirectory()publicstring|falsegetLocale()publicboolhas( string$index )Check whether is defined a translation key in the internal arraypublicstringnquery(string$msgid1,string$msgid2,int$count,array$placeholders = [],string$domain = null)The plural version of gettext().publicstringquery(string$translateKey,array$placeholders = [])Returns the translation related to the given key.publicstringresetDomain()Sets the default domainpublicvoidsetDefaultDomain( string$domain )Sets the domain default to search within when calls are made to gettext()publicvoidsetDirectory( mixed$directory )Sets the path for a domainpublicstringsetDomain( string$domain = null )Changes the current domain (i.e. the translation file)publicstring|boolsetLocale(int$category,array$localeArray = [])Sets locale informationprotectedarraygetOptionsDefault()Gets default optionsprotectedvoidprepareOptions( array$options )Validator for constructorProperties
protectedint$categoryprotectedstring$defaultDomainprotectedstring|array$directoryprotectedstring | false$localeMethods
__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
Note: this method has process-global side effects. Besides calling
setlocale(), it exports the LC_ALL, LANG and LANGUAGE
environment variables via putenv(). LC_ALL affects every
locale-sensitive operation in the process - (string) casts of floats,
strtoupper()/strtolower() tables, date formatting and more - not
just translations.
// 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"]);getOptionsDefault()
protected function getOptionsDefault(): array;Gets default options
prepareOptions()
protected function prepareOptions( array $options ): void;Validator for constructor
Translate\Adapter\NativeArray
ClassSource on GitHubDefines translation lists using PHP arrays
Phalcon\Translate\Adapter\AbstractAdapterPhalcon\Translate\Adapter\NativeArray
Uses Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\InvalidDataType · Phalcon\Translate\Exceptions\MissingContent · Phalcon\Translate\InterpolatorFactory
Method Summary
public__construct(InterpolatorFactory$interpolator,array$options)NativeArray constructor.publicboolexists( string$index )Check whether is defined a translation key in the internal arraypublicboolhas( string$index )Check whether is defined a translation key in the internal arraypublicstringquery(string$translateKey,array$placeholders = [])Returns the translation related to the given keypublicarraytoArray()Returns the internal arrayMethods
__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
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 GitHubClass for exceptions thrown by Phalcon\Translate
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\FileOpenErrorPhalcon\Translate\Exceptions\ImmutableObjectPhalcon\Translate\Exceptions\InterpolatorNotRegisteredPhalcon\Translate\Exceptions\InvalidDataTypePhalcon\Translate\Exceptions\KeyNotFoundPhalcon\Translate\Exceptions\MissingContentPhalcon\Translate\Exceptions\MissingGettextExtensionPhalcon\Translate\Exceptions\MissingRequiredParameterPhalcon\Translate\Exceptions\TranslatorNotRegistered
Translate\Exceptions\FileOpenError
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\FileOpenError
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct( string $name );Translate\Exceptions\ImmutableObject
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\ImmutableObject
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct();Translate\Exceptions\InterpolatorNotRegistered
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\InterpolatorNotRegistered
Uses Phalcon\Translate\Exception
Translate\Exceptions\InvalidDataType
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\InvalidDataType
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct();Translate\Exceptions\KeyNotFound
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\KeyNotFound
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct( string $key );Translate\Exceptions\MissingContent
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\MissingContent
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct();Translate\Exceptions\MissingGettextExtension
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\MissingGettextExtension
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct();Translate\Exceptions\MissingRequiredParameter
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\MissingRequiredParameter
Uses Phalcon\Translate\Exception
Method Summary
Methods
__construct()
public function __construct( string $parameter );getParameter()
public function getParameter(): string;Translate\Exceptions\TranslatorNotRegistered
ClassSource on GitHub\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\TranslatorNotRegistered
Uses Phalcon\Translate\Exception
Translate\InterpolatorFactory
ClassSource on GitHubPhalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Translate\InterpolatorFactory
Uses Phalcon\Factory\AbstractFactory · Phalcon\Translate\Interpolator\InterpolatorInterface
Method Summary
public__construct( array$services = [] )publicInterpolatorInterfacenewInstance( string$name )Create a new instance of the adapterprotectedstringgetExceptionClass()protectedarraygetServices()Returns the available adaptersMethods
__construct()
public function __construct( array $services = [] );newInstance()
public function newInstance( string $name ): InterpolatorInterface;Create a new instance of the adapter
getExceptionClass()
protected function getExceptionClass(): string;getServices()
protected function getServices(): array;Returns the available adapters
Translate\Interpolator\AssociativeArray
ClassSource on GitHubClass AssociativeArray
Phalcon\Translate\Interpolator\AssociativeArray- implementsPhalcon\Translate\Interpolator\InterpolatorInterface
Uses Phalcon\Traits\Support\Helper\Str\InterpolateTrait
Method Summary
Methods
replacePlaceholders()
public function replacePlaceholders(
string $translation,
array $placeholders = []
): string;Replaces placeholders by the values passed
Translate\Interpolator\IndexedArray
ClassSource on GitHubPhalcon\Translate\Interpolator\IndexedArray- implementsPhalcon\Translate\Interpolator\InterpolatorInterface
Method Summary
Methods
replacePlaceholders()
public function replacePlaceholders(
string $translation,
array $placeholders = []
): string;Replaces placeholders by the values passed
Translate\Interpolator\InterpolatorInterface
InterfaceSource on GitHubPhalcon\Translate\InterpolatorInterface
Interface for Phalcon\Translate interpolators
Phalcon\Translate\Interpolator\InterpolatorInterface
Method Summary
Methods
replacePlaceholders()
public function replacePlaceholders(
string $translation,
array $placeholders = []
): string;Replaces placeholders by the values passed
Translate\TranslateFactory
ClassSource on GitHub@property InterpolatorFactory $interpolator
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Translate\TranslateFactory
Uses Phalcon\Config\ConfigInterface · Phalcon\Factory\AbstractFactory · Phalcon\Translate\Adapter\AdapterInterface
Method Summary
public__construct(InterpolatorFactory$interpolator,array$services = [])publicAdapterInterfaceload( mixed$config )Factory to create an instance from a Config objectpublicAdapterInterfacenewInstance(string$name,array$options = [])Create a new instance of the adapterprotectedstringgetExceptionClass()protectedarraygetServices()Returns the available adaptersMethods
__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
getExceptionClass()
protected function getExceptionClass(): string;getServices()
protected function getServices(): array;Returns the available adapters