1 config.inc | public Config::getTranslated($key = '', $args = array(), $options = array()) |
Gets translated data from this configuration object.
Parameters
string $key: A string that maps to a key within the configuration data. For instance in the following configuration array:
array(
'foo' => array(
'bar' => 'baz',
),
);
A key of 'foo.bar' would return the string 'baz'. However, a key of 'foo' would return array('bar' => 'baz'). If no key is specified, then an empty string is returned. If the key is not 'translatable' key then the original string is returned. If the key's value is not a string then an empty string is returned.
array $args: An associative array of replacements to make. Replacements are made in the same way as the t() function.
array $options: An associative array of additional options, with the following elements:
- 'langcode' (defaults to the current language): The language code to translate to a language other than what is used to display the page.
- 'context' (defaults to the empty context): The context the source string belongs to.
Return value
string|NULL: The translated data that was requested.
See also
t()
get()
File
- core/
includes/ config.inc, line 806 - This is the API for configuration storage.
Class
- Config
- Defines the default configuration object.
Code
public function getTranslated($key = '', $args = array(), $options = array()) {
if (empty($key)) {
return NULL;
}
$value = $this->get($key);
if (!is_string($value)) {
return NULL;
}
if (!is_array($this->get('_config_translatables'))) {
return $value;
}
// Ensure that it's a translatable key.
if (!in_array($key, $this->get('_config_translatables'))) {
return $value;
}
// Set a default context so we can differentiate between config strings.
// Rather than by using isset() or empty(), checking by key existence
// allows a NULL context to be used.
if (!array_key_exists('context', $options)) {
$options['context'] = 'config:' . $this->getName() . ':' . $key;
}
return t($value, $args, $options);
}