From a5f3cb9b960b390151a212ac983aad0af321d66c Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Tue, 23 Aug 2011 21:23:16 +0000 Subject: [PATCH] config.inc.php: - new config option $CONF['language_hook'] Hook function to override or add translations to $PALANG. Example hook function included (commented out). common.php: - honor $CONF['language_hook'] scripts/postfixadmin-cli.php: - honor $CONF['language_hook'] - add TODO - language shouldn't be hardcoded to english This implements my feature request at http://sourceforge.net/tracker/?func=detail&aid=3292408&group_id=191583&atid=937967 git-svn-id: https://svn.code.sf.net/p/postfixadmin/code/trunk@1176 a1433add-5e2c-0410-b055-b7f2511e0802 --- common.php | 5 +++++ config.inc.php | 29 +++++++++++++++++++++++++++++ scripts/postfixadmin-cli.php | 8 +++++++- 3 files changed, 41 insertions(+), 1 deletion(-) 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;