/**
* translates string with key $msg_id
*
* @param string $msg_id
* @param int $count NOT USED YET, only for ITranslator needs
* @return string translated string
*/
public function translate($msg_id, $count = NULL)
{
if ($msg_id == "") {
return NULL;
}
///**************
if (!isset($this->dictionary[$msg_id])) {
dibi::insert(self::TABLE, array('msg_id' => $msg_id))->execute();
$this->dictionary[$msg_id] = $msg_id;
CacheTools::invalidate('dictionary');
}
/** applying parameters **/
$args = func_get_args();
$argsCount = count($args);
$requiredArgsCount = preg_match_all($this->paramsRegexp, $this->dictionary[$msg_id], $matches);
if ($requiredArgsCount > $argsCount - 1) {
throw new InvalidArgumentException("Insufficient number of arguments in translate function. Provided string '{$msg_id}'");
}
// if ($argsCount > 1) {
// volane z Rules.php, aby sa mi to nesexovalo s '%label' a tym percentom a nemusel ho zdvojovat
if ($argsCount > 1 && !is_null($args[1])) {
// vola sa to aj s parametrami z Rules.php napr. pre MIN_LENGTH a pod., treba zdvojit percento
$msg_id = str_replace(array('%label', '%name', '%value'), array('%%label', '%%name', '%%value'), $this->dictionary[$msg_id]);
// dump($args);
array_shift($args);
// dump($args);
return vsprintf($msg_id, $args);
} else {
return $this->dictionary[$msg_id];
}
/** applying parameters END **/
}