1. Marking messages as translatable. $t() and $tn() (implemented in aliases()) are recognized as message marking and picked up by the extraction parser. 2. Extracting marked messages. Messages can be extracted through the g11n command which in turn utilizes the Catalog class with the built-in Code adapter or other custom adapters which are concerned with extracting translatable content. 3. Creating a message template from extracted messages. Templates are created by the g11n command using the Catalog class with an adapter for a format you prefer. 4. Translating messages. The actual translation of messages by translators happens outside using external applications. 5. Storing translated messages. Translations are most often stored by the external applications itself. 6. Retrieving the translation for a message. See description for Message::translate().
See also: lithium\g11n\Catalog
See also: lithium\console\command\G11n
See also: lithium\g11n\catalog\adapter\Code
Inheritance: extends lithium\core\StaticObject
示例#1
0
 /**
  * Renders view element
  * @return object
  */
 protected function renderView()
 {
     if (!isset($this->_view)) {
         $this->_view = new View(array('paths' => array('element' => '{:library}/views/elements/{:template}.{:type}.php'), 'outputFilters' => Message::aliases()));
     }
     return $this->_view;
 }
示例#2
0
 /**
  * Perform initialization.
  *
  * @return void
  */
 protected function _init()
 {
     Object::_init();
     extract(Message::aliases());
     $type = isset($this->_config['type']) ? $this->_config['type'] : null;
     if ($type === 'text') {
         $h = function ($data) {
             return $data;
         };
     } else {
         $encoding = 'UTF-8';
         if ($this->_message) {
             $encoding =& $this->_message->charset;
         }
         $h = function ($data) use(&$encoding) {
             return htmlspecialchars((string) $data, ENT_QUOTES, $encoding);
         };
     }
     $this->outputFilters += compact('h', 't') + $this->_config['outputFilters'];
     foreach (array('loader', 'renderer') as $key) {
         if (is_object($this->_config[$key])) {
             $this->{'_' . $key} = $this->_config[$key];
             continue;
         }
         $class = $this->_config[$key];
         $config = array('view' => $this) + $this->_config;
         $path = 'adapter.template.mail';
         $instance = Libraries::instance($path, $class, $config);
         $this->{'_' . $key} = $instance;
     }
 }
示例#3
0
文件: Message.php 项目: EHER/chegamos
 /**
  * Returns an array containing named closures which are aliases for `translate()`.
  * They can be embedded as content filters in the template layer using a filter for
  * `Media::_handle()` or be used in other places where needed.
  *
  * Usage:
  * {{{
  * 	$t('bike');
  * 	$tn('bike', 'bikes', array('count' => 3));
  * }}}
  *
  * Using in a method:
  * {{{
  * 	public function index() {
  * 		extract(Message::aliases());
  * 		$notice = $t('look');
  * 	}
  * }}}
  *
  * @see lithium\net\http\Media::_handle()
  * @return array Named aliases (`'t'` and `'tn'`) for translation functions.
  */
 public static function aliases()
 {
     $t = function ($message, array $options = array()) {
         return Message::translate($message, $options + array('default' => $message));
     };
     $tn = function ($message1, $message2, $count, array $options = array()) {
         return Message::translate($message1, $options + compact('count') + array('default' => $count == 1 ? $message1 : $message2));
     };
     return compact('t', 'tn');
 }
示例#4
0
文件: g11n.php 项目: EHER/chegamos
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
// Inflector::rules('plural', array('irregular' => array('bar' => 'foo')));
//
// Inflector::rules('transliteration', array('/É|Ê/' => 'E'));
//
// Inflector::rules('uninflected', 'bord');
// Inflector::rules('uninflected', array('bord', 'baird'));
/**
 * Integration with `View`. Embeds message translation aliases into the `View`
 * class (or other content handler, if specified) when content is rendered. This
 * enables translation functions, i.e. `<?=$t("Translated content"); ?>`.
 */
Media::applyFilter('_handle', function ($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
    $params['handler']['outputFilters'] += Message::aliases();
    return $chain->next($self, $params, $chain);
});
/**
 * Integration with `Validator`. You can load locale dependent rules into the `Validator`
 * by specifying them manually or retrieving them with the `Catalog` class.
 */
foreach (array('phone', 'postalCode', 'ssn') as $name) {
    Validator::add($name, Catalog::read(true, "validation.{$name}", 'en_US'));
}
/**
 * Intercepts dispatching processes in order to set the effective locale by using
 * the locale of the request or if that is not available retrieving a locale preferred
 * by the client.
 */
ActionDispatcher::applyFilter('_callable', function ($self, $params, $chain) {
示例#5
0
 * Inflector configuration examples.  If your application has custom singular or plural rules, or
 * extra non-ASCII characters to transliterate, you can configure that by uncommenting the lines
 * below.
 */
// Inflector::rules('singular', array('rules' => array('/rata/' => '\1ratus')));
// Inflector::rules('singular', array('irregular' => array('foo' => 'bar')));
//
// Inflector::rules('plural', array('rules' => array('/rata/' => '\1ratum')));
// Inflector::rules('plural', array('irregular' => array('bar' => 'foo')));
//
// Inflector::rules('transliteration', array('/É|Ê/' => 'E'));
//
// Inflector::rules('uninflected', 'bord');
// Inflector::rules('uninflected', array('bord', 'baird'));
/**
 * Integration with `View`. Embeds message translation short-hands into the `View`
 * class (or other content handler, if specified) when content is rendered. This
 * enables short-hand translation functions, i.e. `<?=$t("Translated content"); ?>`.
 */
Media::applyFilter('_handle', function ($self, $params, $chain) {
    $params['handler'] += array('outputFilters' => array());
    $params['handler']['outputFilters'] += Message::shortHands();
    return $chain->next($self, $params, $chain);
});
/**
 * Integration with `Validator`. You can load locale dependent rules into the `Validator`
 * by specifying them manually or retrieving them with the `Catalog` class.
 */
Validator::add('phone', Catalog::read('validation.phone', 'en_US'));
Validator::add('postalCode', Catalog::read('validation.postalCode', 'en_US'));
Validator::add('ssn', Catalog::read('validation.ssn', 'en_US'));
 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);
 }
示例#7
0
<?php

use lithium\g11n\Message;
extract(Message::aliases());
?>
<h3><?php 
echo $t('Welcome');
?>
 <?php 
echo $compact['data']['email'];
?>
,</h3>
<h4><?php 
echo $t('This email communication is CONFIDENTIAL. All the information given in the document is financial sensitive.');
?>
</h4>


<p><?php 
echo $t('You have today created your own XGC wallet. This is the second confidential email you are receiving regarding your new account.');
?>
</p>

<p><?php 
echo $t('Enclosed is a PDF document which contains a password recovery, public and private keys of XGC in PDF document.');
?>
</p>

<h4><?php 
echo $t('Print the PDF document and keep it in a safe place.');
?>
示例#8
0
 public function testCaching()
 {
     $data = array('catalog' => 'Katalog');
     Catalog::write('runtime', 'message', 'de', $data, array('scope' => 'foo'));
     $this->assertFalse(Message::cache());
     $result = Message::translate('catalog', array('locale' => 'de', 'scope' => 'foo'));
     $this->assertEqual('Katalog', $result);
     $cache = Message::cache();
     $this->assertEqual('Katalog', $cache['foo']['de']['catalog']);
     Message::cache(false);
     $this->assertFalse(Message::cache());
     Message::cache(array('foo' => array('de' => array('catalog' => '<Katalog>'))));
     $result = Message::translate('catalog', array('locale' => 'de', 'scope' => 'foo'));
     $this->assertEqual('<Katalog>', $result);
     $options = array('locale' => 'de', 'scope' => 'foo', 'count' => 2);
     $this->assertEqual('<Katalog>', Message::translate('catalog', $options));
     Message::cache(false);
     Message::cache(array('foo' => array('de' => array('catalog' => array('<Katalog>')))));
     $this->assertNull(Message::translate('catalog', $options));
 }