summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Schneider2008-08-15 16:10:35 +0000
committerChristian Schneider2008-08-15 16:10:35 +0000
commit0e055cd6319374f9b7df5cc4b762aded7c5b52d2 (patch)
tree9a8f902c9fa3d319e8684db6d3a0bdb356c5e947
parent9c2659c1c4a93a1cdf3fe058075dd70084dab22b (diff)
downloaditools-0e055cd6319374f9b7df5cc4b762aded7c5b52d2.tar.gz
itools-0e055cd6319374f9b7df5cc4b762aded7c5b52d2.tar.bz2
itools-0e055cd6319374f9b7df5cc4b762aded7c5b52d2.zip
T() now accepts values like ET() but uses Q() to quote them
-rw-r--r--auto_prepend.php11
-rwxr-xr-xtests/autoprepend.t40
2 files changed, 48 insertions, 3 deletions
diff --git a/auto_prepend.php b/auto_prepend.php
index d026017..6bcd03c 100644
--- a/auto_prepend.php
+++ b/auto_prepend.php
@@ -92,13 +92,18 @@ function EDX()
/**
* Return a text in the selected language
* @param $label Label of text to return
- * @param $language Optional language to return text in
+ * @param $language Optional value array or language string
+ * @param $values Optional value array or language string
* @return Localized text string
*/
-function T($label, $language = null, $dummy = null)
+function T($label, $language = null, $values = null)
{
it_text::init();
- return $GLOBALS['it_text']->text($label, $language, $dummy);
+
+ if (is_array($language)) # Need to swap params?
+ list($language, $values) = array($values, $language);
+
+ return is_array($values) ? $GLOBALS['it_text']->etext($label, array_map(array("it_html", "Q"), $values), $language) : $GLOBALS['it_text']->text($label, $language);
}
/**
diff --git a/tests/autoprepend.t b/tests/autoprepend.t
new file mode 100755
index 0000000..e91996f
--- /dev/null
+++ b/tests/autoprepend.t
@@ -0,0 +1,40 @@
+#!/www/server/bin/php -qC
+<?php
+
+require "searchlib/search_test.class";
+
+it_text::init();
+$GLOBALS['it_text']->statictext = array(
+ '_' => array("de" => "Deutsch", "en" => "English"),
+ 'foo' => array("de" => "bar {v1}", "en" => "qux {v1}"),
+);
+
+is(
+ T('foo'),
+ "bar {v1}",
+ "simple T()",
+);
+
+is(
+ T('foo', 'en'),
+ "qux {v1}",
+ "simple T() with language",
+);
+
+is(
+ T('foo', 'v1' => "gna<bber"),
+ "bar gna&lt;bber",
+ "T() with quoted values",
+);
+
+is(
+ T('foo', 'v1' => "gna<bber", 'en'),
+ "qux gna&lt;bber",
+ "T() with with quoted values and language",
+);
+
+is(
+ T('foo', 'en', 'v1' => "gna<bber"),
+ "qux gna&lt;bber",
+ "T() with with language and quoted values",
+);