Skip to content

Commit

Permalink
The gettext bind methods only need to be called once per page access
Browse files Browse the repository at this point in the history
This saves up to 40+ bindtextdomain()/bind_textdomain_codeset() calls
per access.
  • Loading branch information
slusarz committed Jan 27, 2014
1 parent b983c4d commit ca6c3c4
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions framework/Core/lib/Horde/Registry.php
Expand Up @@ -124,6 +124,13 @@ class Horde_Registry implements Horde_Shutdown_Task
*/
protected $_args = array();

/**
* Cached textdomain bindings.
*
* @var array
*/
protected $_bindCache = array();

/**
* Cached configuration information.
*
Expand Down Expand Up @@ -2705,12 +2712,17 @@ public function setLanguageEnvironment($lang = null, $app = null)
*/
public function setTextdomain($app, $directory)
{
bindtextdomain($app, $directory);
textdomain($app);
if (isset($this->_bindCache[$app])) {
textdomain($app);
} else {
bindtextdomain($app, $directory);
textdomain($app);

/* The existence of this function depends on the platform. */
if (function_exists('bind_textdomain_codeset')) {
bind_textdomain_codeset($app, 'UTF-8');
/* The existence of this function depends on the platform. */
if (function_exists('bind_textdomain_codeset')) {
bind_textdomain_codeset($app, 'UTF-8');
}
$this->_bindCache[$app] = true;
}
}

Expand Down

0 comments on commit ca6c3c4

Please sign in to comment.