Added "js" parameter to intl function for a safe usage in JS string,
This commit is contained in:
@@ -47,20 +47,26 @@ class Translation extends AbstractSmartyPlugin
|
|||||||
*/
|
*/
|
||||||
public function translate($params, &$smarty)
|
public function translate($params, &$smarty)
|
||||||
{
|
{
|
||||||
// All parameters other than 'l' and 'd' are supposed to be variables. Build an array of var => value pairs
|
// All parameters other than 'l' and 'd' and 'js' are supposed to be variables. Build an array of var => value pairs
|
||||||
// and pass it to the translator
|
// and pass it to the translator
|
||||||
$vars = array();
|
$vars = array();
|
||||||
|
|
||||||
foreach ($params as $name => $value) {
|
foreach ($params as $name => $value) {
|
||||||
if ($name != 'l' && $name != 'd') $vars["%$name"] = $value;
|
if ($name != 'l' && $name != 'd' && $name != 'js') $vars["%$name"] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->translator->trans(
|
$str = $this->translator->trans(
|
||||||
$this->getParam($params, 'l'),
|
$this->getParam($params, 'l'),
|
||||||
$vars,
|
$vars,
|
||||||
$this->getParam($params, 'd', $this->defaultTranslationDomain)
|
$this->getParam($params, 'd', $this->defaultTranslationDomain)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
if ($this->getParam($params, 'js', 0)) {
|
||||||
|
$str = preg_replace("/(['\"])/", "\\\\$1", $str);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $str;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Define the various smarty plugins handled by this class
|
* Define the various smarty plugins handled by this class
|
||||||
|
|||||||
Reference in New Issue
Block a user