summaryrefslogtreecommitdiff
path: root/lib/phptal/PHPTAL/Php/Attribute/I18N/Source.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/phptal/PHPTAL/Php/Attribute/I18N/Source.php')
-rw-r--r--lib/phptal/PHPTAL/Php/Attribute/I18N/Source.php48
1 files changed, 48 insertions, 0 deletions
diff --git a/lib/phptal/PHPTAL/Php/Attribute/I18N/Source.php b/lib/phptal/PHPTAL/Php/Attribute/I18N/Source.php
new file mode 100644
index 0000000..9575fae
--- /dev/null
+++ b/lib/phptal/PHPTAL/Php/Attribute/I18N/Source.php
@@ -0,0 +1,48 @@
+<?php
+/**
+ * PHPTAL templating engine
+ *
+ * PHP Version 5
+ *
+ * @category HTML
+ * @package PHPTAL
+ * @author Laurent Bedubourg <lbedubourg@motion-twin.com>
+ * @author Kornel LesiƄski <kornel@aardvarkmedia.co.uk>
+ * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
+ * @version SVN: $Id$
+ * @link http://phptal.org/
+ */
+
+
+/**
+ * i18n:source
+ *
+ * The i18n:source attribute specifies the language of the text to be
+ * translated. The default is "nothing", which means we don't provide
+ * this information to the translation services.
+ *
+ *
+ * @package PHPTAL
+ * @subpackage Php.attribute.i18n
+ */
+class PHPTAL_Php_Attribute_I18N_Source extends PHPTAL_Php_Attribute
+{
+ public function before(PHPTAL_Php_CodeWriter $codewriter)
+ {
+ // ensure that a sources stack exists or create it
+ $codewriter->doIf('!isset($_i18n_sources)');
+ $codewriter->pushCode('$_i18n_sources = array()');
+ $codewriter->end();
+
+ // push current source and use new one
+ $codewriter->pushCode('$_i18n_sources[] = ' . $codewriter->getTranslatorReference(). '->setSource('.$codewriter->str($this->expression).')');
+ }
+
+ public function after(PHPTAL_Php_CodeWriter $codewriter)
+ {
+ // restore source
+ $code = $codewriter->getTranslatorReference().'->setSource(array_pop($_i18n_sources))';
+ $codewriter->pushCode($code);
+ }
+}
+