diff options
Diffstat (limited to 'includes/bootstrap.inc')
-rw-r--r-- | includes/bootstrap.inc | 105 |
1 files changed, 101 insertions, 4 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc index 13e584452..26fa25ec2 100644 --- a/includes/bootstrap.inc +++ b/includes/bootstrap.inc @@ -85,15 +85,20 @@ define('DRUPAL_BOOTSTRAP_SESSION', 4); define('DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE', 5); /** - * Seventh bootstrap phase: set $_GET['q'] to Drupal path of request. + * Seventh bootstrap phase: find out language of the page. */ -define('DRUPAL_BOOTSTRAP_PATH', 6); +define('DRUPAL_BOOTSTRAP_LANGUAGE', 6); + +/** + * Eighth bootstrap phase: set $_GET['q'] to Drupal path of request. + */ +define('DRUPAL_BOOTSTRAP_PATH', 7); /** * Final bootstrap phase: Drupal is fully loaded; validate and fix * input data. */ -define('DRUPAL_BOOTSTRAP_FULL', 7); +define('DRUPAL_BOOTSTRAP_FULL', 8); /** * Role ID for anonymous users; should match what's in the "role" table. @@ -106,6 +111,30 @@ define('DRUPAL_ANONYMOUS_RID', 1); define('DRUPAL_AUTHENTICATED_RID', 2); /** + * No language negotiation. The default language is used. + */ +define('LANGUAGE_NEGOTIATION_NONE', 0); + +/** + * Path based negotiation with fallback to default language + * if no defined path prefix identified. + */ +define('LANGUAGE_NEGOTIATION_PATH_DEFAULT', 1); + +/** + * Path based negotiation with fallback to user preferences + * and browser language detection if no defined path prefix + * identified. + */ +define('LANGUAGE_NEGOTIATION_PATH', 2); + +/** + * Domain based negotiation with fallback to default language + * if no language identified by domain. + */ +define('LANGUAGE_NEGOTIATION_DOMAIN', 3); + +/** * Start the timer with the specified name. If you start and stop * the same timer multiple times, the measured intervals will be * accumulated. @@ -409,6 +438,7 @@ function variable_del($name) { unset($conf[$name]); } + /** * Retrieve the current page from the cache. * @@ -762,11 +792,12 @@ function drupal_anonymous_user($session = '') { * DRUPAL_BOOTSTRAP_SESSION: initialize session handling. * DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE: load bootstrap.inc and module.inc, start * the variable system and try to serve a page from the cache. + * DRUPAL_BOOTSTRAP_LANGUAGE: identify the language used on the page. * DRUPAL_BOOTSTRAP_PATH: set $_GET['q'] to Drupal path of request. * DRUPAL_BOOTSTRAP_FULL: Drupal is fully loaded, validate and fix input data. */ function drupal_bootstrap($phase) { - static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL); + static $phases = array(DRUPAL_BOOTSTRAP_CONFIGURATION, DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE, DRUPAL_BOOTSTRAP_DATABASE, DRUPAL_BOOTSTRAP_ACCESS, DRUPAL_BOOTSTRAP_SESSION, DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, DRUPAL_BOOTSTRAP_LANGUAGE, DRUPAL_BOOTSTRAP_PATH, DRUPAL_BOOTSTRAP_FULL); while (!is_null($current_phase = array_shift($phases))) { _drupal_bootstrap($current_phase); @@ -824,6 +855,10 @@ function _drupal_bootstrap($phase) { drupal_page_header(); break; + case DRUPAL_BOOTSTRAP_LANGUAGE: + drupal_init_language(); + break; + case DRUPAL_BOOTSTRAP_PATH: require_once './includes/path.inc'; // Initialize $_GET['q'] prior to loading modules and invoking hook_init(). @@ -898,3 +933,65 @@ function get_t() { } return $t; } + +/** + * Choose a language for the current page, based on site and user preferences. + */ +function drupal_init_language() { + global $language, $user; + + // Ensure the language is correctly returned, even without multilanguage support. + // Useful for eg. XML/HTML 'lang' attributes. + if (variable_get('language_count', 1) == 1) { + $language = language_default(); + } + else { + include_once './includes/language.inc'; + $language = language_initialize(); + } +} + +/** + * Get a list of languages set up indexed by the specified key + * + * @param $field The field to index the list with. + * @param $reset Boolean to request a reset of the list. + */ +function language_list($field = 'language', $reset = FALSE) { + static $languages = NULL; + + // Reset language list + if ($reset) { + $languages = NULL; + } + + // Init language list + if (!isset($languages)) { + $result = db_query('SELECT * FROM {languages} ORDER BY weight ASC, name ASC'); + while ($row = db_fetch_object($result)) { + $languages['language'][$row->language] = $row; + } + } + + // Return the array indexed by the right field + if (!isset($languages[$field])) { + $languages[$field] = array(); + foreach($languages['language'] as $lang) { + // Some values should be collected into an array + if (in_array($field, array('enabled', 'weight'))) { + $languages[$field][$lang->$field][$lang->language] = $lang; + } + else { + $languages[$field][$lang->$field] = $lang; + } + } + } + return $languages[$field]; +} + +/** + * Default language used on the site + */ +function language_default() { + return variable_get('language_default', (object) array('language' => 'en', 'name' => 'English', 'direction' => 0, 'native' => 'English')); +} |