Phalcon translate
NOTE
All classes are prefixed with Phalcon
Translate\Adapter\AbstractAdapter¶
Abstract Source on GitHub
@template TKey of string
@template TValue of string
@implements ArrayAccess
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.
public
string
_(string $translateKey,array $placeholders = [])
Returns the translation string of the given key (alias of method 't')
public
string
notFound( string $index )
Whenever a key is not found this method will be called
public
bool
offsetExists( mixed $translateKey )
Check whether a translation key exists
public
string|null
offsetGet( mixed $translateKey )
Returns the translation related to the given key
public
void
offsetSet(mixed $offset,mixed $value)
Sets a translation value
public
void
offsetUnset( mixed $offset )
Unsets a translation from the dictionary
public
string
t(string $translateKey,array $placeholders = [])
Returns the translation string of the given key
protected
string
replacePlaceholders(string $translation,array $placeholders = [])
Replaces placeholders by the values passed
Properties¶
protected
string
$defaultInterpolator = ""
protected
InterpolatorInterface | null
$interpolator = null
protected
InterpolatorFactory
$interpolatorFactory
protected
bool
$triggerError = false
Methods¶
__construct()¶
AbstractAdapter constructor.
_()¶
Returns the translation string of the given key (alias of method 't')
notFound()¶
Whenever a key is not found this method will be called
offsetExists()¶
Check whether a translation key exists
offsetGet()¶
Returns the translation related to the given key
offsetSet()¶
Sets a translation value
offsetUnset()¶
Unsets a translation from the dictionary
t()¶
Returns the translation string of the given key
replacePlaceholders()¶
Replaces placeholders by the values passed
Translate\Adapter\AdapterInterface¶
Interface Source on GitHub
Phalcon\Translate\Adapter\AdapterInterface
Interface for Phalcon\Translate adapters
Phalcon\Translate\Adapter\AdapterInterface
Method Summary¶
public
bool
has( string $index )
Check whether is defined a translation key in the internal array
public
string
query(string $translateKey,array $placeholders = [])
Returns the translation related to the given key
public
string
t(string $translateKey,array $placeholders = [])
Returns the translation string of the given key
Methods¶
has()¶
Check whether is defined a translation key in the internal array
query()¶
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()¶
Returns the translation string of the given key
Translate\Adapter\Csv¶
Class Source on GitHub
Phalcon\Translate\Adapter\AbstractAdapterPhalcon\Translate\Adapter\Csv
Uses Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\FileOpenError · Phalcon\Translate\Exceptions\MissingRequiredParameter · Phalcon\Translate\InterpolatorFactory
Method Summary¶
public
__construct(InterpolatorFactory $interpolator,array $options)
Csv constructor.
public
bool
exists( string $index )
Check whether is defined a translation key in the internal array
public
bool
has( string $index )
Check whether is defined a translation key in the internal array
public
string
query(string $translateKey,array $placeholders = [])
Returns the translation related to the given key
public
array
toArray()
Returns the internal array
protected
phpFopen(string $filename,string $mode)
@todo to be removed when we get traits
Properties¶
protected
array
$translate = []
Methods¶
__construct()¶
Csv constructor.
exists()¶
Check whether is defined a translation key in the internal array
has()¶
Check whether is defined a translation key in the internal array
query()¶
Returns the translation related to the given key
toArray()¶
Returns the internal array
phpFopen()¶
@todo to be removed when we get traits
Translate\Adapter\Gettext¶
Class Source 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
Phalcon\Translate\Adapter\AbstractAdapterPhalcon\Translate\Adapter\Gettext
Uses Phalcon\Translate\Exception · Phalcon\Translate\Exceptions\MissingGettextExtension · Phalcon\Translate\Exceptions\MissingRequiredParameter · Phalcon\Translate\InterpolatorFactory
Method Summary¶
public
__construct(InterpolatorFactory $interpolator,array $options)
Gettext constructor.
public
bool
exists( string $index )
Check whether is defined a translation key in the internal array
public
int
getCategory()
public
string
getDefaultDomain()
public
array|string
getDirectory()
public
string|false
getLocale()
public
bool
has( string $index )
Check whether is defined a translation key in the internal array
public
string
nquery(string $msgid1,string $msgid2,int $count,array $placeholders = [],string $domain = null)
The plural version of gettext().
public
string
query(string $translateKey,array $placeholders = [])
Returns the translation related to the given key.
public
string
resetDomain()
Sets the default domain
public
void
setDefaultDomain( string $domain )
Sets the domain default to search within when calls are made to gettext()
public
void
setDirectory( mixed $directory )
Sets the path for a domain
public
string
setDomain( string $domain = null )
Changes the current domain (i.e. the translation file)
public
string|bool
setLocale(int $category,array $localeArray = [])
Sets locale information
protected
array
getOptionsDefault()
Gets default options
protected
bool
phpFunctionExists( string $name )
@todo to be removed when we get traits
protected
void
prepareOptions( array $options )
Validator for constructor
Properties¶
protected
int
$category
protected
string
$defaultDomain
protected
string|array
$directory
protected
string | false
$locale
Methods¶
__construct()¶
Gettext constructor.
exists()¶
Check whether is defined a translation key in the internal array
getCategory()¶
getDefaultDomain()¶
getDirectory()¶
getLocale()¶
has()¶
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()¶
Returns the translation related to the given key.
resetDomain()¶
Sets the default domain
setDefaultDomain()¶
Sets the domain default to search within when calls are made to gettext()
setDirectory()¶
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()¶
Changes the current domain (i.e. the translation file)
setLocale()¶
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()¶
Gets default options
phpFunctionExists()¶
@todo to be removed when we get traits
prepareOptions()¶
Validator for constructor
Translate\Adapter\NativeArray¶
Class Source on GitHub
Defines 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.
public
bool
exists( string $index )
Check whether is defined a translation key in the internal array
public
bool
has( string $index )
Check whether is defined a translation key in the internal array
public
string
query(string $translateKey,array $placeholders = [])
Returns the translation related to the given key
public
array
toArray()
Returns the internal array
Methods¶
__construct()¶
NativeArray constructor.
exists()¶
Check whether is defined a translation key in the internal array
has()¶
Check whether is defined a translation key in the internal array
query()¶
Returns the translation related to the given key
toArray()¶
Returns the internal array
Translate\Exception¶
Class Source on GitHub
Class 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¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\FileOpenError
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
Translate\Exceptions\ImmutableObject¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\ImmutableObject
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
Translate\Exceptions\InterpolatorNotRegistered¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\InterpolatorNotRegistered
Uses Phalcon\Translate\Exception
Translate\Exceptions\InvalidDataType¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\InvalidDataType
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
Translate\Exceptions\KeyNotFound¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\KeyNotFound
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
Translate\Exceptions\MissingContent¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\MissingContent
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
Translate\Exceptions\MissingGettextExtension¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\MissingGettextExtension
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
Translate\Exceptions\MissingRequiredParameter¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\MissingRequiredParameter
Uses Phalcon\Translate\Exception
Method Summary¶
Methods¶
__construct()¶
getParameter()¶
Translate\Exceptions\TranslatorNotRegistered¶
Class Source on GitHub
\ExceptionPhalcon\Translate\ExceptionPhalcon\Translate\Exceptions\TranslatorNotRegistered
Uses Phalcon\Translate\Exception
Translate\InterpolatorFactory¶
Class Source on GitHub
Phalcon\Factory\AbstractConfigFactoryPhalcon\Factory\AbstractFactoryPhalcon\Translate\InterpolatorFactory
Uses Phalcon\Factory\AbstractFactory · Phalcon\Translate\Interpolator\InterpolatorInterface
Method Summary¶
public
__construct( array $services = [] )
public
InterpolatorInterface
newInstance( string $name )
Create a new instance of the adapter
protected
string
getExceptionClass()
protected
array
getServices()
Returns the available adapters
Methods¶
__construct()¶
newInstance()¶
Create a new instance of the adapter
getExceptionClass()¶
getServices()¶
Returns the available adapters
Translate\Interpolator\AssociativeArray¶
Class Source on GitHub
Class AssociativeArray
Phalcon\Translate\Interpolator\AssociativeArray- implementsPhalcon\Translate\Interpolator\InterpolatorInterface
Uses Phalcon\Support\Helper\Str\Interpolate
Method Summary¶
Properties¶
protected
Interpolate | null
$interpolate = null
Methods¶
replacePlaceholders()¶
Replaces placeholders by the values passed
Translate\Interpolator\IndexedArray¶
Class Source on GitHub
Phalcon\Translate\Interpolator\IndexedArray- implementsPhalcon\Translate\Interpolator\InterpolatorInterface
Method Summary¶
Methods¶
replacePlaceholders()¶
Replaces placeholders by the values passed
Translate\Interpolator\InterpolatorInterface¶
Interface Source on GitHub
Phalcon\Translate\InterpolatorInterface
Interface for Phalcon\Translate interpolators
Phalcon\Translate\Interpolator\InterpolatorInterface
Method Summary¶
Methods¶
replacePlaceholders()¶
Replaces placeholders by the values passed
Translate\TranslateFactory¶
Class Source 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 = [])
public
AdapterInterface
load( mixed $config )
Factory to create an instance from a Config object
public
AdapterInterface
newInstance(string $name,array $options = [])
Create a new instance of the adapter
protected
string
getExceptionClass()
protected
array
getServices()
Returns the available adapters
Methods¶
__construct()¶
load()¶
Factory to create an instance from a Config object
newInstance()¶
Create a new instance of the adapter
getExceptionClass()¶
getServices()¶
Returns the available adapters