Commit: 7e75cc379d97bc4469e5f015d7582e9e04cc6ad8
Author: David Persson | Date: 2010-07-29 01:04:02 +0200
diff --git a/libraries/lithium/g11n/catalog/adapter/Code.php b/libraries/lithium/g11n/catalog/adapter/Code.php
index 9e18bfb..aadf1dc 100644
--- a/libraries/lithium/g11n/catalog/adapter/Code.php
+++ b/libraries/lithium/g11n/catalog/adapter/Code.php
@@ -11,6 +11,7 @@ namespace lithium\g11n\catalog\adapter;
use \Exception;
use \RecursiveIteratorIterator;
use \RecursiveDirectoryIterator;
+use \lithium\template\view\Compiler;
/**
* The `Code` class is an adapter which treats files containing code as just another source
@@ -109,6 +110,7 @@ class Code extends \lithium\g11n\catalog\Adapter {
*/
protected function _parsePhp($file) {
$contents = file_get_contents($file);
+ $contents = Compiler::compile($contents);
$defaults = array(
'ids' => array(),
diff --git a/libraries/lithium/tests/cases/g11n/catalog/adapter/CodeTest.php b/libraries/lithium/tests/cases/g11n/catalog/adapter/CodeTest.php
index d65df7e..67e94cb 100644
--- a/libraries/lithium/tests/cases/g11n/catalog/adapter/CodeTest.php
+++ b/libraries/lithium/tests/cases/g11n/catalog/adapter/CodeTest.php
@@ -11,46 +11,60 @@ namespace lithium\tests\cases\g11n\catalog\adapter;
use \Exception;
use \lithium\g11n\catalog\adapter\Code;
-if (false) {
- $t('simple 1');
+class CodeTest extends \lithium\test\Unit {
- $t('options 1', null, array('locale' => 'en'));
+ public $adapter;
- $t('replace 1 {:a}', array('a' => 'b'));
+ protected $_path;
- $t($test['invalid']);
- $t(32203);
- $t('invalid 1', $test['invalid']);
- $t('invalid 2', 32203);
- $t('invalid 3', 'invalid 3b');
+ public function setUp() {
+ $this->_path = $path = LITHIUM_APP_PATH . '/resources/tmp/tests';
+ $this->skipIf(!is_writable($this->_path), "{$this->_path} is not writable.");
- $t('escaping\n1');
- $t("escaping\n2");
- $t("escaping\r\n3");
- $t('escaping
- 4');
+ $this->adapter = new Code(compact('path'));
- $tn('singular simple 1', 'plural simple 1', 3);
- $tn('singular simple 2', 'plural simple 2');
+ $file = "{$this->_path}/a.php";
+ $data = <<<'EOD'
+<?php
+$t('simple 1');
- $t('mixed 1');
- $tn('mixed 1', 'plural mixed 1', 3);
+$t('options 1', null, array('locale' => 'en'));
- $t('mixed 2');
- $tn('mixed 2', 'plural mixed 2', 3);
- $t('mixed 2');
- $t('plural mixed 2');
-}
+$t('replace 1 {:a}', array('a' => 'b'));
-class CodeTest extends \lithium\test\Unit {
+$t($test['invalid']);
+$t(32203);
+$t('invalid 1', $test['invalid']);
+$t('invalid 2', 32203);
+$t('invalid 3', 'invalid 3b');
- public $adapter;
+$t('escaping\n1');
+$t("escaping\n2");
+$t("escaping\r\n3");
+$t('escaping
+ 4');
- protected $_path;
+$tn('singular simple 1', 'plural simple 1', 3);
+$tn('singular simple 2', 'plural simple 2');
- public function setUp() {
- $this->_path = $path = __DIR__;
- $this->adapter = new Code(compact('path'));
+$t('mixed 1');
+$tn('mixed 1', 'plural mixed 1', 3);
+
+$t('mixed 2');
+$tn('mixed 2', 'plural mixed 2', 3);
+$t('mixed 2');
+$t('plural mixed 2');
+?>
+EOD;
+ file_put_contents($file, $data);
+
+ $file = "{$this->_path}/a.html.php";
+ $data = <<<'EOD'
+<?=$t('simple 1 short'); ?>
+
+<?=$tn('singular simple 1 short', 'plural simple 1 short', 3); ?>
+EOD;
+ file_put_contents($file, $data);
}
public function tearDown() {
@@ -85,6 +99,14 @@ class CodeTest extends \lithium\test\Unit {
$this->assertEqual($expected, $result);
}
+ public function testReadMessageTemplateTSimpleShort() {
+ $results = $this->adapter->read('messageTemplate', 'root', null);
+
+ $expected = array('singular' => 'simple 1 short');
+ $result = $results['simple 1 short']['ids'];
+ $this->assertEqual($expected, $result);
+ }
+
public function testReadMessageTemplateTOptions() {
$results = $this->adapter->read('messageTemplate', 'root', null);
@@ -164,6 +186,18 @@ class CodeTest extends \lithium\test\Unit {
$this->assertEqual($expected, $result);
}
+ public function testReadMessageTemplateTnSimpleShort() {
+ $results = $this->adapter->read('messageTemplate', 'root', null);
+
+ $expected = 'singular simple 1 short';
+ $result = $results['singular simple 1 short']['ids']['singular'];
+ $this->assertEqual($expected, $result);
+
+ $expected = 'plural simple 1 short';
+ $result = $results['singular simple 1 short']['ids']['plural'];
+ $this->assertEqual($expected, $result);
+ }
+
public function testReadMessageTemplateTnT() {
$results = $this->adapter->read('messageTemplate', 'root', null);