From c11575dbe73e1312f2e1fea3ea74aa393b1a672f Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Wed, 14 Apr 2010 12:51:53 +0000 Subject: [PATCH] MDL-22015 improved get_string method - it can now fetch strings from any language, not just the current one --- lib/moodlelib.php | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 7a8da84e71b..485d9a200fc 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5691,15 +5691,16 @@ function get_string_manager() { */ interface string_manager { /** - * Mega Function - Get String returns a requested string + * Get String returns a requested string * * @param string $identifier The identifier of the string to search for * @param string $component The module the string is associated with - * @param string $a An object, string or number that can be used + * @param string|object|array $a An object, string or number that can be used * within translation strings + * @param string $lang moodle translation language, NULL means use current * @return string The String ! */ - public function get_string($identifier, $component = '', $a = NULL); + public function get_string($identifier, $component = '', $a = NULL, $lang = NULL); /** * Does the string actually exist? @@ -5920,11 +5921,12 @@ class core_string_manager implements string_manager { * * @param string $identifier The identifier of the string to search for * @param string $component The module the string is associated with - * @param string $a An object, string or number that can be used + * @param string|object|array $a An object, string or number that can be used * within translation strings + * @param string $lang moodle translation language, NULL means use current * @return string The String ! */ - public function get_string($identifier, $component = '', $a = NULL) { + public function get_string($identifier, $component = '', $a = NULL, $lang = NULL) { // there are very many uses of these time formating strings without the 'langconfig' component, // it would not be reasonable to expect that all of them would be converted during 2.0 migration static $langconfigstrs = array( @@ -5950,7 +5952,9 @@ class core_string_manager implements string_manager { } } - $lang = current_language(); + if ($lang === NULL) { + $lang = current_language(); + } $string = $this->load_component_strings($component, $lang); @@ -6167,16 +6171,20 @@ class install_string_manager implements string_manager { * * @param string $identifier The identifier of the string to search for * @param string $component The module the string is associated with - * @param string $a An object, string or number that can be used + * @param string|object|array $a An object, string or number that can be used * within translation strings + * @param string $lang moodle translation language, NULL means use current * @return string The String ! */ - public function get_string($identifier, $component = '', $a = NULL) { + public function get_string($identifier, $component = '', $a = NULL, $lang = NULL) { if (!$component) { $component = 'moodle'; } - $lang = current_language(); + if ($lang === NULL) { + $lang = current_language(); + } + //get parent lang $parent = ''; if ($lang !== 'en' and $identifier !== 'parentlanguage' and $component !== 'langconfig') { @@ -6338,7 +6346,7 @@ class install_string_manager implements string_manager { * usually expressed as the filename in the language pack without the * .php on the end but can also be written as mod/forum or grade/export/xls. * If none is specified then moodle.php is used. - * @param mixed $a An object, string or number that can be used + * @param string|object|array $a An object, string or number that can be used * within translation strings * @return string The localized string. */