Permalink
Browse files

Adding `'noop'` option to `Message::translate()`. Adding test.

  • Loading branch information...
1 parent 5c81170 commit fc31c7f5ee4aed688abf29cdfc6185f0fe6acc61 @davidpersson davidpersson committed with gwoo Feb 9, 2010
Showing with 18 additions and 2 deletions.
  1. +8 −2 libraries/lithium/g11n/Message.php
  2. +10 −0 libraries/lithium/tests/cases/g11n/MessageTest.php
@@ -74,6 +74,7 @@ class Message extends \lithium\core\StaticObject {
* - `'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.
* @return string|void The translation or the value of the `'default'` option if none could be found.
* @see lithium\util\String::insert()
*/
@@ -83,11 +84,16 @@ public static function translate($id, $options = array()) {
// 'locale' => Environment::get('g11n.locale'),
'locale' => 'root',
'scope' => null,
- 'default' => null
+ 'default' => null,
+ 'noop' => false
);
extract($options + $defaults);
- $result = static::_translated($id, $count, $locale, compact('scope'));
+ if ($noop) {
+ $result = null;
+ } else {
+ $result = static::_translated($id, $count, $locale, compact('scope'));
+ }
if ($result || $default) {
return String::insert($result ?: $default, $options);
@@ -155,6 +155,16 @@ public function testTranslateLocales() {
$this->assertEqual($expected, $result);
}
+ public function testTranslateNoop() {
+ $data = array(
+ 'catalog' => 'Katalog',
+ );
+ Catalog::write('message', 'de', $data, array('name' => 'runtime'));
+
+ $result = Message::translate('catalog', array('locale' => 'de', 'noop' => true));
+ $this->assertNull($result);
+ }
+
public function testShortHandsBasic() {
$data = array(
'house' => array('Haus', 'Häuser')

0 comments on commit fc31c7f

Please sign in to comment.