diff --git a/common.php b/common.php index ce34d196..6b551d63 100644 --- a/common.php +++ b/common.php @@ -51,6 +51,11 @@ require_once("$incpath/functions.inc.php"); $_SESSION['lang'] = $language = check_language (); # TODO: storing the language only at login instead of calling check_language() on every page would save some processor cycles ;-) require_once("$incpath/languages/" . $_SESSION['lang'] . ".lang"); +if($CONF['language_hook'] != '' && function_exists($CONF['language_hook'])) { + $hook_func = $CONF['language_hook']; + $PALANG = $hook_func ($PALANG, $_SESSION['lang']); +} + /** * @param string $class * __autoload implementation, for use with spl_autoload_register(). diff --git a/config.inc.php b/config.inc.php index 5d54f6a3..96a673c9 100644 --- a/config.inc.php +++ b/config.inc.php @@ -38,6 +38,35 @@ $CONF['postfix_admin_url'] = ''; // Language files are located in './languages', change as required.. $CONF['default_language'] = 'en'; +// Hook to override or add translations in $PALANG +// Set to the function name you want to use as hook function (see language_hook example function below) +$CONF['language_hook'] = ''; + +/* + language_hook example function + + Called if $CONF['language_hook'] == '' + Allows to add or override $PALANG interface texts. + + Returns: modified $PALANG array +*/ +/* +function language_hook($PALANG, $language) { + switch ($language) { + case "de": + $PALANG['whatever'] = 'foo'; + break; + case "en": + $PALANG['whatever'] = 'bar'; + break; + default: + $PALANG['whatever'] = 'foobar'; + } + + return $PALANG; +} +*/ + // Database Config // mysql = MySQL 3.23 and 4.0, 4.1 or 5 // mysqli = MySQL 4.1+ diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index 03879eee..3a3b8d1d 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -215,7 +215,7 @@ class PostfixAdmin { PATH.'/config.inc.php', PATH.'/languages/language.php', PATH.'/functions.inc.php', - PATH.'/languages/en.lang', + PATH.'/languages/en.lang', # TODO: honor $CONF[default_language] and/or language from $_ENV CORE_INCLUDE_PATH.'/common.php', CORE_INCLUDE_PATH.'/inflector.php', ); @@ -230,6 +230,12 @@ class PostfixAdmin { Config::write($CONF); Lang::getInstance(); + + if($CONF['language_hook'] != '' && function_exists($CONF['language_hook'])) { + $hook_func = $CONF['language_hook']; + $PALANG = $hook_func ($PALANG, 'en'); # $includes is also hardcoded to 'en' - see TODO above + } + Lang::write($PALANG); return true;