Skip to content

Instantly share code, notes, and snippets.

@slusarz
Created August 4, 2014 20:23
Show Gist options
  • Save slusarz/8e6c0bc23676a81df392 to your computer and use it in GitHub Desktop.
Save slusarz/8e6c0bc23676a81df392 to your computer and use it in GitHub Desktop.
Translation Autoconfiguration
class Horde_Translation_Autoconfigure extends Horde_Translation
{
/**
*/
static public function loadHandler($handlerClass)
{
if (!isset(self::$_directory)) {
$a = new ReflectionClass(get_called_class());
$dir = dirname($a->getFilename());
$subdir = substr_count(self::$_domain, '_');
$dirs = array(
/* PEAR */
$dir . str_repeat('/..', $subdir + 1) . '/data/' . self::$_domai
n . '/locale',
/* Composer */
$dir . str_repeat('/..', $subdir) . '/data/locale',
/* Source directory */
$dir . str_repeat('/..', $subdir + 1) . '/locale'
);
foreach ($dirs as $val) {
if (file_exists($val)) {
self::$_directory = realpath($val);
break;
}
}
}
parent::loadHandler($handlerClass);
}
}
class Horde_Foo_Translation extends Horde_Translation_Autoconfigure
{
static protected $_domain = "Horde_Foo";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment