Translate\Adapter\AbstractAdapter
AbstractSource on GitHub@implements ArrayAccess<string, string>
Phalcon\Translate\Adapter\AbstractAdapter- implementsPhalcon\Translate\Adapter\AdapterInterface,\ArrayAccess
Uses ArrayAccess · Phalcon\Contracts\Translate\TranslateTypes · Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\ImmutableObject · Phalcon\Translate\Exceptions\KeyNotFound · Phalcon\Translate\InterpolatorFactory · Phalcon\Translate\Interpolator\InterpolatorInterface
Method Summary
public__construct(InterpolatorFactory $interpolatorFactory,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 called
publicbooloffsetExists(mixed $offset)Check whether a translation key exists
publicstringoffsetGet(mixed $offset)Returns the translation related to the given key
publicvoidoffsetSet(mixed $offset,mixed $value)Sets a translation value
publicvoidoffsetUnset(mixed $offset)Unsets a translation from the dictionary
publicstringt(string $translateKey,array $placeholders = [])Returns the translation string of the given key
protectedstringreplacePlaceholders(string $translation,array $placeholders = [])Replaces placeholders by the values passed
Properties
protectedstring$defaultInterpolator = ""protectedInterpolatorInterface|null$interpolator = nullprotectedInterpolatorFactory$interpolatorFactoryprotectedbool$triggerError = falseMethods
__construct()
public function __construct(
InterpolatorFactory $interpolatorFactory,
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 $offset ): bool;Check whether a translation key exists
offsetGet()
public function offsetGet( mixed $offset ): string;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 array
publicstringquery(string $translateKey,array $placeholders = [])Returns the translation related to the given key
publicstringt(string $translateKey,array $placeholders = [])Returns the translation string of the given key
Methods
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\Contracts\Translate\TranslateTypes · 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 array
publicboolhas(string $index)Check whether is defined a translation key in the internal array
publicstringquery(string $translateKey,array $placeholders = [])Returns the translation related to the given key
publicarraytoArray()Returns the internal array
Properties
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\Contracts\Translate\TranslateTypes · 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 array
publicintgetCategory()publicstringgetDefaultDomain()publicarray|stringgetDirectory()publicfalse|stringgetLocale()publicboolhas(string $index)Check whether is defined a translation key in the internal array
publicstringnquery(string $msgid1,string $msgid2,int $count,array $placeholders = [],string|null $domain = null)The plural version of gettext().
publicstringquery(string $translateKey,array $placeholders = [])Returns the translation related to the given key.
publicstringresetDomain()Sets the default domain
publicvoidsetDefaultDomain(string $domain)Sets the domain default to search within when calls are made to gettext()
publicvoidsetDirectory(mixed $directory)Sets the path for a domain
publicstringsetDomain(string|null $domain = null)Changes the current domain (i.e. the translation file)
publicfalse|stringsetLocale(int $category,array $localeArray = [])Sets locale information
protectedarraygetOptionsDefault()Gets default options
protectedvoidprepareOptions(array $options)Validator for constructor
Properties
protectedint$category = 6protectedstring$defaultDomain = "messages"protectedmixed$directoryprotectedfalse|string$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(): false|string;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|null $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|null $domain = null ): string;Changes the current domain (i.e. the translation file)
setLocale()
public function setLocale(
int $category,
array $localeArray = []
): false|string;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\Contracts\Translate\TranslateTypes · 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 array
publicboolhas(string $index)Check whether is defined a translation key in the internal array
publicstringquery(string $translateKey,array $placeholders = [])Returns the translation related to the given key
publicarraytoArray()Returns the internal array
Methods
__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\Exceptions\InterpolatorNotRegistered · Phalcon\Translate\Interpolator\AssociativeArray · Phalcon\Translate\Interpolator\IndexedArray · Phalcon\Translate\Interpolator\InterpolatorInterface · Throwable
Method Summary
public__construct(array $services = [])publicInterpolatorInterfacenewInstance(string $name)Create a new instance of the adapter
protectedstringgetExceptionClass()protectedarraygetServices()Returns the available adapters
Methods
__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\Contracts\Translate\TranslateTypes · Phalcon\Factory\AbstractFactory · Phalcon\Translate\Adapter\AdapterInterface · Phalcon\Translate\Adapter\Csv · Phalcon\Translate\Adapter\Gettext · Phalcon\Translate\Adapter\NativeArray · Phalcon\Translate\Exceptions\TranslatorNotRegistered · Throwable
Method Summary
public__construct(InterpolatorFactory $interpolator,array $services = [])publicAdapterInterfaceload(mixed $config)Factory to create an instance from a Config object
publicAdapterInterfacenewInstance(string $name,array $options = [])Create a new instance of the adapter
protectedstringgetExceptionClass()protectedarraygetServices()Returns the available adapters
Methods
__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