Checks installation requirements and reports any errors.
function install_check_translations($install_state) {
$requirements = array();
$readable = FALSE;
$writable = FALSE;
// @todo: Make this configurable.
$files_directory = conf_path() . '/files';
$translations_directory = conf_path() . '/files/translations';
$translations_directory_exists = FALSE;
$online = FALSE;
// First attempt to create or make writable the files directory.
file_prepare_directory($files_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Then, attempt to create or make writable the translations directory.
file_prepare_directory($translations_directory, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
// Get values so the requirements errors can be specific.
if (drupal_verify_install_file($translations_directory, FILE_EXIST | FILE_WRITABLE, 'dir')) {
$readable = is_readable($translations_directory);
$writable = is_writable($translations_directory);
$translations_directory_exists = TRUE;
}
// Build URLs for the translation file and the translation server.
$release = install_get_localization_release();
$langcode = $install_state['parameters']['langcode'];
$variables = array(
'%project' => 'drupal',
'%version' => $release['version'],
'%core' => $release['core'],
'%language' => $langcode,
);
$translation_url = strtr($install_state['server_pattern'], $variables);
$elements = parse_url($translation_url);
$server_url = $elements['scheme'] . '://' . $elements['host'];
// Build the language name for display.
$languages = LanguageManager::getStandardLanguageList();
$language = isset($languages[$langcode]) ? $languages[$langcode][0] : $langcode;
// Check if the desirered translation file is available and if the translation
// server can be reached, or in other words if we have an internet connection.
if ($translation_available = install_check_localization_server($translation_url)) {
$online = TRUE;
}
else {
if (install_check_localization_server($server_url)) {
$online = TRUE;
}
}
// If the translations directory does not exists, throw an error.
if (!$translations_directory_exists) {
$requirements['translations directory exists'] = array(
'title' => st('Translations directory'),
'value' => st('The translations directory does not exist.'),
'severity' => REQUIREMENT_ERROR,
'description' => st('The installer requires that you create a translations directory as part of the installation process. Create the directory %translations_directory . More details about installing Drupal are available in <a href="@install_txt">INSTALL.txt</a>.', array(
'%translations_directory' => $translations_directory,
'@install_txt' => base_path() . 'core/INSTALL.txt',
)),
);
}
else {
$requirements['translations directory exists'] = array(
'title' => st('Translations directory'),
'value' => st('The diretory %translations_directory exists.', array(
'%translations_directory' => $translations_directory,
)),
);
// If the translations directory is not readable, throw an error.
if (!$readable) {
$requirements['translations directory readable'] = array(
'title' => st('Translations directory'),
'value' => st('The translations directory is not readable.'),
'severity' => REQUIREMENT_ERROR,
'description' => st('The installer requires read permissions to %translations_directory at all times. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.', array(
'%translations_directory' => $translations_directory,
'@handbook_url' => 'http://drupal.org/server-permissions',
)),
);
}
// If translations directory is not writable, throw an error.
if (!$writable) {
$requirements['translations directory writable'] = array(
'title' => st('Translations directory'),
'value' => st('The translations directory is not writable.'),
'severity' => REQUIREMENT_ERROR,
'description' => st('The installer requires write permissions to %translations_directory during the installation process. If you are unsure how to grant file permissions, consult the <a href="@handbook_url">online handbook</a>.', array(
'%translations_directory' => $translations_directory,
'@handbook_url' => 'http://drupal.org/server-permissions',
)),
);
}
else {
$requirements['translations directory writable'] = array(
'title' => st('Translations directory'),
'value' => st('The translations directory is writable.'),
);
}
}
// If the translations server can not be contacted, throw an error.
if (!$online) {
$requirements['online'] = array(
'title' => st('Internet'),
'value' => st('The translation server is offline.'),
'severity' => REQUIREMENT_ERROR,
'description' => st('The installer requires to contact the translation server to download a translation file. Check your internet connection and verify that your website can reach the translation server at <a href="!server_url">!server_url</a>.', array(
'!server_url' => $server_url,
)),
);
}
else {
$requirements['online'] = array(
'title' => st('Internet'),
'value' => st('The translation server is online.'),
);
// If translation file is not found at the translation server, throw an
// error.
if (!$translation_available) {
$requirements['translation available'] = array(
'title' => st('Translation'),
'value' => st('The %language translation is not available.', array(
'%language' => $language,
)),
'severity' => REQUIREMENT_ERROR,
'description' => st('The %language translation file is not available at the translation server. <a href="!url">Choose a different language</a> or select English and translate your website later.', array(
'%language' => $language,
'!url' => check_url($_SERVER['SCRIPT_NAME']),
)),
);
}
else {
$requirements['translation available'] = array(
'title' => st('Translation'),
'value' => st('The %language translation is available.', array(
'%language' => $language,
)),
);
}
}
if ($translations_directory_exists && $readable && $writable && $translation_available) {
$translation_downloaded = install_retrieve_file($translation_url, $translations_directory);
if (!$translation_downloaded) {
$requirements['translation downloaded'] = array(
'title' => st('Translation'),
'value' => st('The %language translation could not be downloaded.', array(
'%language' => $language,
)),
'severity' => REQUIREMENT_ERROR,
'description' => st('The %language translation file could not be downloaded. <a href="!url">Choose a different language</a> or select English and translate your website later.', array(
'%language' => $language,
'!url' => check_url($_SERVER['SCRIPT_NAME']),
)),
);
}
}
return $requirements;
}