/** * Find out a user's institution language. If they belong to one institution that has specified * a language, then this will be that institution's language. If they belong to multiple * institutions that have specified languages, it will be the arbitrarily "first" institution. * If they belong to no institution that has specified a language, it will return null. * * @param int $userid Which user to check (defaults to $USER) * @param string $sourceinst If provided, the source institution for the language will be * returned here by reference * @return string A language, or 'default' */ function get_user_institution_language($userid = null, &$sourceinst = null) { global $USER; if ($userid == null) { $userid = $USER->id; } $instlangs = get_configs_user_institutions('lang', $userid); // Every user belongs to at least one institution foreach ($instlangs as $name => $lang) { $sourceinst = $name; $instlang = $lang; // If the user belongs to multiple institutions, arbitrarily use the language // from the first one that has specified a language. if (!empty($instlang) && $instlang != 'default' && language_installed($instlang)) { break; } } if (!$instlang) { $instlang = 'default'; } return $instlang; }
/** * 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; if ($USER instanceof User) { $lang = $USER->get_account_preference('lang'); if ($lang !== null && $lang != 'default') { if (language_installed($lang)) { return $lang; } $USER->set_account_preference('lang', 'default'); } } if (is_a($SESSION, 'Session')) { $sesslang = $SESSION->get('lang'); if (!empty($sesslang) && $sesslang != 'default') { return $sesslang; } } if (!empty($CFG->lang)) { return $CFG->lang; } return 'en.utf8'; }
/** * 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 $userlang, $lastlang; $loggedin = $USER instanceof User && $USER->is_logged_in(); if (!isset($userlang) && $loggedin) { $userlang = $USER->get_account_preference('lang'); if ($userlang !== null && $userlang != 'default') { if (!language_installed($userlang)) { $USER->set_account_preference('lang', 'default'); $userlang = 'default'; } } } if (!empty($userlang) && $userlang != 'default') { $lang = $userlang; } else { if (!$loggedin && 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'; } if ($lang == $lastlang) { return $lang; } set_locale_for_language($lang); return $lastlang = $lang; }
/** * 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; }