X-Git-Url: http://git.roojs.org/?p=Pman.Core;a=blobdiff_plain;f=DataObjects%2FI18n.php;h=739c80b318a4b8901a1d2e12fbfa67c708bd7cf2;hp=3f52fb5a58c962a6ef643df2742cbfffe9b7fd79;hb=6f4c2d6f80256876f51cc71ae3f207a16c476866;hpb=0280a4e403d14ba7108d037e441da70094f73719 diff --git a/DataObjects/I18n.php b/DataObjects/I18n.php index 3f52fb5a..739c80b3 100644 --- a/DataObjects/I18n.php +++ b/DataObjects/I18n.php @@ -127,9 +127,24 @@ class Pman_Core_DataObjects_I18n extends DB_DataObject $this->buildDB(); // ensure we have the full database... $this->selectAdd(" + id as id, i18n_translate(ltype, lkey, 'en') as lval_en "); } + + if (!empty($q['_as_code_and_title'])) { + $tn = $this->tableName(); + + $this->selectAdd(); + $this->selectAdd(" + {$tn}.lval as title, + {$tn}.lkey as code + "); + $this->is_active = 1; + if (!empty($q['_title'])) { + $this->whereAdd("{$tn}.lval like '{$this->escape($_REQUEST['_title'])}%'"); + } + } if (!empty($q['!code'])) { $this->whereAddIn('!lkey', explode(',', $q['!code']), 'string'); @@ -140,6 +155,10 @@ class Pman_Core_DataObjects_I18n extends DB_DataObject $this->whereAdd("upper(lval) LIKE '%{$v}%'"); } + if (!empty($q['query']['name_starts'])) { + $this->whereAdd("lval LIKE '". $this->escape($q['query']['name_starts']). "%'"); + } + if (!empty($q['_filtered']) && !empty($this->ltype)) { $cfg = $this->cfg(); $filter = $cfg[$this->ltype]; @@ -205,6 +224,13 @@ class Pman_Core_DataObjects_I18n extends DB_DataObject function translate($inlang,$ltype,$kval) { + + static $cache = array(); + $cache_key = implode(' ', array($inlang,$ltype,$kval)); + if (isset($cache[$cache_key ])) { + return $cache[$cache_key]; + } + $x = DB_DataObject::factory('i18n'); $x->ltype = $ltype; $x->lkey = $kval; @@ -213,12 +239,15 @@ class Pman_Core_DataObjects_I18n extends DB_DataObject $x->limit(1); if ($x->find(true) && !empty($x->lval)) { + $cache[$cache_key] = $x->lval; return $x->lval; } $fallback->inlang = 'en'; if ($fallback->find(true) && !empty($fallback->lval)) { - return $fallback->lval; + $cache[$cache_key] = $fallback->lval; + return $fallback->lval; } + $cache[$cache_key] = $kval; return $kval; } @@ -227,7 +256,7 @@ class Pman_Core_DataObjects_I18n extends DB_DataObject function toTransList($ltype, $inlang) { - + $this->is_active = 1; $this->ltype = $ltype; $this->inlang= $inlang; $this->selectAdd();