summaryrefslogtreecommitdiff
path: root/it_text.class
diff options
context:
space:
mode:
authorUrban Müller2008-05-05 15:51:57 +0000
committerUrban Müller2008-05-05 15:51:57 +0000
commit003e365f0fe745cd8aa511eca1532da9e7560211 (patch)
tree6b6f6c4d8f4eba0d7ca4bfea926ba5514caa3605 /it_text.class
parenta2496481d22bdd7647540d083272e3a359b65bee (diff)
downloaditools-003e365f0fe745cd8aa511eca1532da9e7560211.tar.gz
itools-003e365f0fe745cd8aa511eca1532da9e7560211.tar.bz2
itools-003e365f0fe745cd8aa511eca1532da9e7560211.zip
load all texts in path
Diffstat (limited to 'it_text.class')
-rw-r--r--it_text.class33
1 files changed, 22 insertions, 11 deletions
diff --git a/it_text.class b/it_text.class
index 2167f4e..9d3e406 100644
--- a/it_text.class
+++ b/it_text.class
@@ -29,26 +29,37 @@ class it_text
/**
* Constructor
- * Example it_texts.php: <?php return array('_' => array('en'=>"English", 'de'=>"Deutsch"), 'edit'=>array('en'=>"Edit", 'de'=>("Editieren")));
+ * Loads all texts.php in include path for translated labels. Singleton; if instanciated mutiple times, texts are merged
+ * Example texts.php: <?php return array('_' => array('en'=>"English", 'de'=>"Deutsch"), 'edit'=>array('en'=>"Edit", 'de'=>("Editieren")));
* @param $p['cookiename'] optional cookie name (default: 'LANGUAGE')
* @param $p['debug'] optional debug mode: display label of unknown texts, set to 'label' to always display labels instead of actual text
* @param $p['fallbacklanguage'] optional language to use for undefined texts (useful for partially translated projects)
* @param $p['forcelanguage'] optional language to use instead of user's preferred language
- * @param $p['phpfile'] optional texts file, defaults to first it_texts.php in include path
+ * @param $p['phpfile'] optional texts file(s), default: all texts.php in include path
*/
function it_text($p = null)
{
- # Find it_texts.php in path (abs path in case we need to save)
- foreach (explode(":", ini_get('include_path')) as $dir)
- if (file_exists($phpfile = "$dir/it_texts.php") || file_exists($phpfile = "$dir/texts.php"))
- break;
+ $this->p = (array)$p + array('cookiename' => 'LANGUAGE', 'debug' => (EDC('label') ? "label" : ""));
- $this->p = (array)$p + array('cookiename' => 'LANGUAGE', 'phpfile' => $phpfile, 'debug' => (EDC('label') ? "label" : ""));
+ $phpfiles = array();
+ if ($p['phpfile'])
+ $phpfiles = (array)$p['phpfile'];
+ else
+ {
+ # Find texts.php in path (abs path in case we need to save)
+ foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $dir)
+ if (file_exists($phpfile = "$dir/texts.php"))
+ $phpfiles[] = $phpfile;
+ }
- # Read $this->statictext from php file if it's not defined yet
- if (!$this->statictext)
- if (is_array($ret = @include($this->p['phpfile'])))
- $this->statictext = $ret;
+ # Read and merge texts from php files if none defined yet
+ foreach ($phpfiles as $phpfile) {
+ $oldtexts = $this->statictexts;
+ if (is_array($ret = @include($phpfile)))
+ $this->statictext += $ret;
+ else
+ $this->statictext = $oldtexts + $this->statictext; # FIXME: compatibility mode
+ }
# Get array of supported languages and their names
$this->languages_available = (array)$this->statictext['_'];