Exemple #1
0
/**
 * Translate a KEY_STRING to its i18n version
 *
 * @return string
 */
function t(){
	$params   = func_get_args();
	$key      = $params[0];

	$string = new \Core\i18n\I18NString($key);
	$string->setParameters($params);

	return $string->getTranslation();
}
Exemple #2
0
/**
 * @alpha
 *
 * @param array  $params  Associative (and/or indexed) array of smarty parameters passed in from the template
 * @param Smarty $smarty  Parent Smarty template object
 *
 * @throws SmartyException
 *
 * @return string
 */
function smarty_function_t($params, $smarty){

	$key      = $params[0];
	$modifier = null;

	if(isset($params['modifier'])){
		$modifier = $params['modifier'];
		unset($params['modifier']);
	}

	$string = new \Core\i18n\I18NString($key);
	$string->setParameters($params);

	$str = $string->getTranslation();

	// Is there a modifier on this text?
	$whitelist = ['strtolower', 'strtoupper', 'ucfirst', 'ucwords'];

	if(in_array($modifier, $whitelist)){
		$str = call_user_func($modifier, $str);
	}

	return $str;
}