lithium\g11n\Message::translate PHP Method

translate() public static method

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 {:count} bike.'); Message::translate('This painting is {:color}.', array( 'color' => Message::translate('silver'), ));
See also: lithium\util\String::insert()
public static translate ( string $id, array $options = [] ) : string
$id string The id to use when looking up the translation.
$options array 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. - `'context'`: The disambiguating context (optional). - `'default'`: Is used as a fall back if `_translated()` returns without a result. - `'noop'`: If `true` no whatsoever lookup takes place.
return string The translation or the value of the `'default'` option if none could be found.
    public static function translate($id, array $options = array())
    {
        $defaults = array('count' => 1, 'locale' => Environment::get('locale'), 'scope' => null, 'context' => 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'], 'context' => $options['context']));
        }
        if ($result = $result ?: $options['default']) {
            return strpos($result, '{:') !== false ? String::insert($result, $options) : $result;
        }
    }

Usage Example

 public function testShortHandsAsymmetry()
 {
     $filters = Message::shortHands();
     $t = $filters['t'];
     $tn = $filters['tn'];
     $expected = Message::translate('house', array('locale' => 'de'));
     $result = $t('house', array('locale' => 'de'));
     $this->assertNotEqual($expected, $result);
     $expected = Message::translate('house', array('locale' => 'de', 'count' => 3));
     $result = $tn('house', 'houses', array('locale' => 'de'));
     $this->assertNotEqual($expected, $result);
 }
All Usage Examples Of lithium\g11n\Message::translate