install_select_locale(&$install_state)Installation task; select which locale to use for the current profile.
$install_state An array of information about the current installation state. The chosen locale will be added here, if it was not already selected previously, as will a list of all available locales.
For interactive installations, a form or other page output allowing the locale to be selected or providing information about locale selection, if a locale has not been chosen. Otherwise, an exception is thrown if a locale cannot be chosen automatically.
includes/install.core.inc, line 1162
<?php
function install_select_locale(&$install_state) {
// Find all available locales.
$profilename = $install_state['parameters']['profile'];
$locales = install_find_locales($profilename);
$install_state['locales'] += $locales;
if (!empty($_POST['locale'])) {
foreach ($locales as $locale) {
if ($_POST['locale'] == $locale->name) {
$install_state['parameters']['locale'] = $locale->name;
return;
}
}
}
if (empty($install_state['parameters']['locale'])) {
// If only the built-in (English) language is available, and we are using
// the default profile and performing an interactive installation, inform
// the user that the installer can be localized. Otherwise we assume the
// user knows what he is doing.
if (count($locales) == 1) {
if ($profilename == 'standard' && $install_state['interactive']) {
drupal_set_title(st('Choose language'));
if (!empty($install_state['parameters']['localize'])) {
$output = '<p>' . st('With the addition of an appropriate translation package, this installer is capable of proceeding in another language of your choice. To install and use Drupal in a language other than English:') . '</p>';
$output .= '<ul><li>' . st('Determine if <a href="@translations" target="_blank">a translation of this Drupal version</a> is available in your language of choice. A translation is provided via a translation package; each translation package enables the display of a specific version of Drupal in a specific language. Not all languages are available for every version of Drupal.', array('@translations' => 'http://drupal.org/project/translations')) . '</li>';
$output .= '<li>' . st('If an alternative translation package of your choice is available, download and extract its contents to your Drupal root directory.') . '</li>';
$output .= '<li>' . st('Return to choose language using the second link below and select your desired language from the displayed list. Reloading the page allows the list to automatically adjust to the presence of new translation packages.') . '</li>';
$output .= '</ul><p>' . st('Alternatively, to install and use Drupal in English, or to defer the selection of an alternative language until after installation, select the first link below.') . '</p>';
$output .= '<p>' . st('How should the installation continue?') . '</p>';
$output .= '<ul><li><a href="install.php?profile=' . $profilename . '&locale=en">' . st('Continue installation in English') . '</a></li><li><a href="install.php?profile=' . $profilename . '">' . st('Return to choose a language') . '</a></li></ul>';
}
else {
include_once DRUPAL_ROOT . '/includes/form.inc';
$output = drupal_render(drupal_get_form('install_select_locale_form', $locales, $profilename));
}
return $output;
}
// One language, but not the default profile or not an interactive
// installation. Assume the user knows what he is doing.
$locale = current($locales);
$install_state['parameters']['locale'] = $locale->name;
return;
}
else {
// Allow profile to pre-select the language, skipping the selection.
$function = $profilename . '_profile_details';
if (function_exists($function)) {
$details = $function();
if (isset($details['language'])) {
foreach ($locales as $locale) {
if ($details['language'] == $locale->name) {
$install_state['parameters']['locale'] = $locale->name;
return;
}
}
}
}
// We still don't have a locale, so display a form for selecting one.
// Only do this in the case of interactive installations, since this is
// not a real form with submit handlers (the database isn't even set up
// yet), rather just a convenience method for setting parameters in the
// URL.
if ($install_state['interactive']) {
drupal_set_title(st('Choose language'));
include_once DRUPAL_ROOT . '/includes/form.inc';
return drupal_render(drupal_get_form('install_select_locale_form', $locales, $profilename));
}
else {
throw new Exception(st('Sorry, you must select a language to continue the installation.'));
}
}
}
}
?>