Skip to content

Instantly share code, notes, and snippets.

@mahono
Created September 15, 2010 09:24
Show Gist options
  • Save mahono/580469 to your computer and use it in GitHub Desktop.
Save mahono/580469 to your computer and use it in GitHub Desktop.
make __() faster
class myI18N extends sfI18N
{
public function __($string, $args = array(), $catalogue = 'messages')
{
$string = (string) $string;
if ($this->cache)
{
// the arguments stuff should probably be removed as this will cause
// a lot of cache entries
$argsStr = '';
foreach ($args as $arg => $value)
{
$argsStr .= $arg.(string)$value;
}
$key = 'i18n_trans:'.md5($this->getCulture().$catalogue.$string.$argsStr);
if ($translation = $this->cache->get($key))
{
return $translation;
}
}
$translation = parent::__($string, $args, $catalogue);
if (!empty($key))
{
$this->cache->set($key, $translation);
}
return $translation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment