Avolutions\Util\Translation
extends ConfigFileLoaderThe Translation class loads all translation files at the bootstrapping and can be used to get the translated values anywhere in the framework or application.
Properties
Property | Visibility | Type | Description |
---|---|---|---|
$values | protected | array | An array containing all loaded configuration values |
Methods
Method | Visibility | Description |
---|---|---|
__construct() | public | Creates a new Translation instance and loads all translation values from the translations files. |
get() | public | Returns the value for the given key. The key is separated by slashes (/). |
getTranslation() | public | Returns the translation of the given key and language and replace all placeholders if params are passed. |
loadConfigFile() | protected | Loads the given config file and return the content (array) or an empty array if the file can not be found. |
Property Details
$values
An array containing all loaded configuration values
protected array<string|int, mixed> $values = []
Method Details
__construct()
Creates a new Translation instance and loads all translation values from the translations files.
public
__construct(Application $Application, Config $Config, Session $Session) : mixed
Parameters
Application
$Application
Application instance.
Config
$Config
Config instance.
Session
$Session
Session instance.
get()
Returns the value for the given key. The key is separated by slashes (/).
public
get(string $key) : mixed
Parameters
string
$key
The key (slash separated) of the config value.
Return values
mixed Returns the value for the given key. The key is separated by slashes (/).getTranslation()
Returns the translation of the given key and language and replace all placeholders if params are passed.
public
getTranslation(string $key[, array<string|int, mixed> $params = [] ][, string|null $language = null ]) : string
Parameters
string
$key
The key of the translation string.
array<string|int, mixed>
$params
(optional)
An array with values to replace the placeholders in translation.
string|null
$language
(optional)
The language in which the translation should be loaded.
Return values
string Returns the translation of the given key and language and replace all placeholders if params are passed.loadConfigFile()
Loads the given config file and return the content (array) or an empty array if the file can not be found.
protected
loadConfigFile(string $configFile) : array<string|int, mixed>
Parameters
string
$configFile
Complete name including the path and file extension of the config file.