From 7916e86880ca1b1e20e9c112486cc2dfaa787d6d Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Sun, 21 Aug 2011 11:38:01 +0000 Subject: [PATCH] method to translate options incl. optionial title --- .../class.etemplate_widget_menupopup.inc.php | 41 +++++++++++-------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/etemplate/inc/class.etemplate_widget_menupopup.inc.php b/etemplate/inc/class.etemplate_widget_menupopup.inc.php index 06b3dc6846..96470a4aec 100644 --- a/etemplate/inc/class.etemplate_widget_menupopup.inc.php +++ b/etemplate/inc/class.etemplate_widget_menupopup.inc.php @@ -161,10 +161,7 @@ class etemplate_widget_menupopup extends etemplate_widget } if (!$no_lang) { - foreach($options as $value => &$label) - { - $label = lang($label); - } + $options = self::translateOptions($options); } //error_log(__METHOD__."('$name') returning ".array2string($options)); return $options; @@ -567,23 +564,35 @@ class etemplate_widget_menupopup extends etemplate_widget if (!$no_lang) { - foreach($options as $value => &$label) - { - if (!is_array($label)) - { - $label = lang($label); - } - else - { - $label['label'] = lang($label['label']); - if (isset($label['title'])) $label['title'] = lang($label['title']); - } - } + $options = self::translateOptions($options); } //error_log(__METHOD__."('$widget_type', '$legacy_options', ...) returning ".array2string($options)); return $options; } + /** + * Translate options incl. optional title (label is an array with values for keys 'label' and optionally 'title' + * + * @param array $options + * @return $options + */ + public static function translateOptions(array $options) + { + foreach($options as $value => &$label) + { + if (!is_array($label)) + { + $label = lang($label); + } + else + { + $label['label'] = lang($label['label']); + if (isset($label['title'])) $label['title'] = lang($label['title']); + } + } + return $options; + } + /** * internal function to format account-data */