Extends
lithium\core\StaticObject
Translates a message according to the current or provided locale
and into it's correct plural form.
Usage:
{{{
Message::translate('Mind the gap.');
Message::translate('house', array('count' => 23));
}}}
`String::insert()`-style placeholders may be used within the message
and replacements provided directly within the `options` argument.
Example:
{{{
Message::translate('I can see 1 bike.');
Message::translate('This painting is {:color}.', array(
'color' => Message::translate('silver'),
));
}}}
Parameters
- string $id The id to use when looking up the translation.
- array $options Valid options are: - `'count'`: Used to determine the correct plural form. You can either pass a signed or unsigned integer, the behavior when passing other types is yet undefined. The count is made absolute before being passed to the pluralization function. This has the effect that that with i.e. an English pluralization function passing `-1` results in a singular translation. - `'locale'`: The target locale, defaults to current locale. - `'scope'`: The scope of the message. - `'default'`: Is used as a fall back if `_translated()` returns without a result. - `'noop'`: If `true` no whatsoever lookup takes place.
Returns
string The translation or the value of the `'default'` option if none could be found.Source
public static function translate($id, array $options = array()) {
$defaults = array(
'count' => 1,
'locale' => Environment::get('locale'),
'scope' => null,
'default' => null,
'noop' => false
);
$options += $defaults;
if ($options['noop']) {
$result = null;
} else {
$result = static::_translated($id, abs($options['count']), $options['locale'], array(
'scope' => $options['scope']
));
}
if ($result || $options['default']) {
return String::insert($result ?: $options['default'], $options);
}
}