function get_raw_string($identifier, $section = 'mahara') { // For a raw string we don't want to format any arguments using // sprintf, so the replace function passed to get_string_location // should just return the first argument and ignore the second. return get_string_location($identifier, $section, array(), create_function('$string, $args', 'return $string;')); }
/** * Helper function to sprintf language strings * with a variable number of arguments * * @param mixed $string raw string to use, or an array of strings, one for each plural form * @param array $args arguments to sprintf * @param string $lang The language */ function format_langstring($string, $args, $lang = 'en.utf8') { if (is_array($string) && isset($args[0]) && is_numeric($args[0])) { // If there are multiple strings here, there must be one for each plural // form in the language. The first argument is passed into the plural // function, which returns an index into the array of strings. $pluralfunction = get_string_location('pluralfunction', 'langconfig', array(), 'raw_langstring', $lang); $index = function_exists($pluralfunction) ? $pluralfunction($args[0]) : 0; $string = isset($string[$index]) ? $string[$index] : current($string); } return call_user_func_array('sprintf', array_merge(array($string), $args)); }
/** * This function returns the current * language to use, either for a given user * or sitewide, or the default * * @return string */ function current_language() { global $USER, $CFG, $SESSION; static $lang; if (!empty($lang)) { return $lang; } if ($USER instanceof User) { $userlang = $USER->get_account_preference('lang'); if ($userlang !== null && $userlang != 'default') { if (language_installed($userlang)) { $lang = $userlang; } else { $USER->set_account_preference('lang', 'default'); } } } if (empty($lang) && is_a($SESSION, 'Session')) { $sesslang = $SESSION->get('lang'); if (!empty($sesslang) && $sesslang != 'default') { $lang = $sesslang; } } if (empty($lang)) { $lang = !empty($CFG->lang) ? $CFG->lang : 'en.utf8'; } // Set locale. We are probably being called from get_string_location. // $lang had better be non-empty, or it will call us again. if ($args = split(',', get_string_location('locales', 'langconfig', array(), 'raw_langstring', $lang))) { array_unshift($args, LC_ALL); call_user_func_array('setlocale', $args); } return $lang; }