Skip to content
Snippets Groups Projects
Commit be357fab authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #1219236 by Gábor Hojtsy: locale module includes 1350+ lines of...

- Patch #1219236 by Gábor Hojtsy: locale module includes 1350+ lines of unneeded code on all page loads.
parent aca1d4bf
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -1373,6 +1373,7 @@ function install_profile_modules(&$install_state) {
*/
function install_import_locales(&$install_state) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
include_once drupal_get_path('module', 'locale') . '/locale.bulk.inc';
$install_locale = $install_state['parameters']['locale'];
include_once DRUPAL_ROOT . '/includes/iso.inc';
......
This diff is collapsed.
......@@ -363,6 +363,7 @@ function locale_languages_predefined_form_submit($form, &$form_state) {
// See if we have language files to import for the newly added
// language, collect and import them.
include_once drupal_get_path('module', 'locale') . '/locale.bulk.inc';
if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) {
batch_set($batch);
}
......@@ -743,159 +744,6 @@ function locale_language_providers_session_form($form, &$form_state) {
* @} End of "locale-language-administration"
*/
/**
* User interface for the translation import screen.
*/
function locale_translate_import_form($form) {
// Get all languages, except English
drupal_static_reset('language_list');
$names = locale_language_list('name');
unset($names['en']);
if (!count($names)) {
$languages = _locale_prepare_predefined_list();
$default = key($languages);
}
else {
$languages = array(
t('Already added languages') => $names,
t('Languages not yet added') => _locale_prepare_predefined_list()
);
$default = key($names);
}
$form['import'] = array('#type' => 'fieldset',
'#title' => t('Import translation'),
);
$form['import']['file'] = array('#type' => 'file',
'#title' => t('Language file'),
'#size' => 50,
'#description' => t('A Gettext Portable Object (<em>.po</em>) file.'),
);
$form['import']['langcode'] = array('#type' => 'select',
'#title' => t('Import into'),
'#options' => $languages,
'#default_value' => $default,
'#description' => t('Choose the language you want to add strings into. If you choose a language which is not yet set up, it will be added.'),
);
$form['import']['mode'] = array('#type' => 'radios',
'#title' => t('Mode'),
'#default_value' => LOCALE_IMPORT_KEEP,
'#options' => array(
LOCALE_IMPORT_OVERWRITE => t('Strings in the uploaded file replace existing ones, new ones are added. The plural format is updated.'),
LOCALE_IMPORT_KEEP => t('Existing strings and the plural format are kept, only new strings are added.')
),
);
$form['import']['submit'] = array('#type' => 'submit', '#value' => t('Import'));
return $form;
}
/**
* Process the locale import form submission.
*/
function locale_translate_import_form_submit($form, &$form_state) {
$validators = array('file_validate_extensions' => array('po'));
// Ensure we have the file uploaded
if ($file = file_save_upload('file', $validators)) {
// Add language, if not yet supported
drupal_static_reset('language_list');
$languages = language_list('language');
$langcode = $form_state['values']['langcode'];
if (!isset($languages[$langcode])) {
include_once DRUPAL_ROOT . '/includes/iso.inc';
$predefined = _locale_get_predefined_list();
locale_add_language($langcode);
drupal_set_message(t('The language %language has been created.', array('%language' => t($predefined[$langcode][0]))));
}
// Now import strings into the language
if ($return = _locale_import_po($file, $langcode, $form_state['values']['mode']) == FALSE) {
$variables = array('%filename' => $file->filename);
drupal_set_message(t('The translation import of %filename failed.', $variables), 'error');
watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR);
}
}
else {
drupal_set_message(t('File to import not found.'), 'error');
$form_state['redirect'] = 'admin/config/regional/translate/import';
return;
}
$form_state['redirect'] = 'admin/config/regional/translate';
return;
}
/**
* User interface for the translation export screen.
*/
function locale_translate_export_screen() {
// Get all languages, except English
drupal_static_reset('language_list');
$names = locale_language_list('name');
unset($names['en']);
$output = '';
// Offer translation export if any language is set up.
if (count($names)) {
$elements = drupal_get_form('locale_translate_export_po_form', $names);
$output = drupal_render($elements);
}
$elements = drupal_get_form('locale_translate_export_pot_form');
$output .= drupal_render($elements);
return $output;
}
/**
* Form to export PO files for the languages provided.
*
* @param $names
* An associate array with localized language names
*/
function locale_translate_export_po_form($form, &$form_state, $names) {
$form['export_title'] = array('#type' => 'item',
'#title' => t('Export translation'),
);
$form['langcode'] = array('#type' => 'select',
'#title' => t('Language name'),
'#options' => $names,
'#description' => t('Select the language to export in Gettext Portable Object (<em>.po</em>) format.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
return $form;
}
/**
* Translation template export form.
*/
function locale_translate_export_pot_form() {
// Complete template export of the strings
$form['export_title'] = array('#type' => 'item',
'#title' => t('Export template'),
'#description' => t('Generate a Gettext Portable Object Template (<em>.pot</em>) file with all strings from the Drupal locale database.'),
);
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
// Reuse PO export submission callback.
$form['#submit'][] = 'locale_translate_export_po_form_submit';
return $form;
}
/**
* Process a translation (or template) export form submission.
*/
function locale_translate_export_po_form_submit($form, &$form_state) {
// If template is required, language code is not given.
$language = NULL;
if (isset($form_state['values']['langcode'])) {
$languages = language_list();
$language = $languages[$form_state['values']['langcode']];
}
_locale_export_po($language, _locale_export_po_generate($language, _locale_export_get_strings($language)));
}
/**
* Returns HTML for a locale date format form.
*
......
......@@ -162,7 +162,7 @@ function locale_menu() {
'access arguments' => array('translate interface'),
'weight' => 20,
'type' => MENU_LOCAL_TASK,
'file' => 'locale.admin.inc',
'file' => 'locale.bulk.inc',
);
$items['admin/config/regional/translate/export'] = array(
'title' => 'Export',
......@@ -170,7 +170,7 @@ function locale_menu() {
'access arguments' => array('translate interface'),
'weight' => 30,
'type' => MENU_LOCAL_TASK,
'file' => 'locale.admin.inc',
'file' => 'locale.bulk.inc',
);
$items['admin/config/regional/translate/edit/%'] = array(
'title' => 'Edit string',
......@@ -516,6 +516,7 @@ function locale_language_types_info() {
* Implements hook_language_negotiation_info().
*/
function locale_language_negotiation_info() {
require_once DRUPAL_ROOT . '/includes/locale.inc';
$file = 'includes/locale.inc';
$providers = array();
......@@ -805,7 +806,7 @@ function locale_themes_enabled($themes) {
* translations for.
*/
function locale_system_update($components) {
include_once DRUPAL_ROOT . '/includes/locale.inc';
include_once drupal_get_path('module', 'locale') . '/locale.bulk.inc';
if ($batch = locale_batch_by_component($components)) {
batch_set($batch);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment