1 install.core.inc | install_select_language(&$install_state) |
Installation task; select which language to use.
Parameters
array $install_state: An array of information about the current installation state. The chosen langcode will be added here, if it was not already selected previously, as will a list of all available languages.
Return value
string|NULL: For interactive installations, a form or other page output allowing the language to be selected or providing information about language selection, if a language has not been chosen. For non-interactive installs, nothing is returned. An exception is thrown if a language cannot be chosen automatically.
Throws
Exception
File
- core/
includes/ install.core.inc, line 1326 - API functions for installing Backdrop.
Code
function install_select_language(&$install_state) {
// Find all available translations.
$files = install_find_translations();
$install_state['translations'] += $files;
include_once BACKDROP_ROOT . '/core/includes/standard.inc';
$standard_languages = install_get_available_translations($files);
if (!empty($_POST['langcode'])) {
$langcode = $_POST['langcode'];
if ($langcode == 'en' || isset($standard_languages[$langcode])) {
$install_state['parameters']['langcode'] = $langcode;
return;
}
}
if (empty($install_state['parameters']['langcode'])) {
// If only the built-in (English) language is available, and we are
// performing an interactive installation, inform the user that the
// installer can be translated. Otherwise we assume the user knows what he
// is doing.
if (count($standard_languages) == 1) {
if ($install_state['interactive']) {
$directory = settings_get('locale_translate_file_directory', conf_path() . '/files/translations');
backdrop_set_title(st('Choose language'));
if (!empty($install_state['parameters']['translate'])) {
$output = '<p>Follow these steps to translate Backdrop into your language:</p>';
$output .= '<ol>';
if (!install_check_localization_server(INSTALL_AVAILABLE_TRANSLATIONS_URI)) {
$output .= '<li>Ensure that you are connected to the internet, since Backdrop is able to automatically download new translations. Alternatively,</li>';
}
$output .= '<li>Download a translation from the <a href="https://localize.backdropcms.org/translate/languages" target="_blank">translation server</a>.</li>';
$output .= '<li>Place it into the following directory:<pre>' . $directory . '</pre></li>';
$output .= '</ol>';
$output .= '<p>For more information on installing Backdrop in different languages, visit the <a href="https://backdropcms.org/installing-in-other-languages" target="_blank">Backdrop user guide page</a>.</p>';
$output .= '<p>How should the installation continue?</p>';
$output .= '<ul>';
$output .= '<li><a href="' . check_url(backdrop_current_script_url(array('translate' => NULL))) . '">Reload the language selection page after adding translations</a></li>';
$output .= '<li><a href="' . check_url(backdrop_current_script_url(array(
'langcode' => 'en',
'translate' => NULL,
))) . '">Continue installation in English</a></li>';
$output .= '</ul>';
}
else {
include_once BACKDROP_ROOT . '/core/includes/form.inc';
$elements = backdrop_get_form('install_select_language_form', $files, $standard_languages);
$output = backdrop_render($elements);
}
return $output;
}
// One language, but not an interactive installation. Assume the user
// knows what he is doing.
$single_language = reset($standard_languages);
$install_state['parameters']['langcode'] = key($single_language);
return NULL;
}
else {
// We still don't have a langcode, 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']) {
backdrop_set_title(st('Choose language'));
include_once BACKDROP_ROOT . '/core/includes/form.inc';
$elements = backdrop_get_form('install_select_language_form', $files, $standard_languages);
return backdrop_render($elements);
}
else {
throw new Exception(st('Sorry, you must select a language to continue the installation.'));
}
}
}
// Non-interactive installs where no language was specified. No action to do.
else {
return NULL;
}
}