summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-01-08 13:32:43 +0000
committerDries Buytaert <dries@buytaert.net>2010-01-08 13:32:43 +0000
commitcc55d2941707999d7f29b6739882444dda5849a6 (patch)
tree957740ae0ff96f24a7e2ef0bcf8ed1193571300c
parent3046a5452d757decb3325ee9471753459c245702 (diff)
downloadbrdo-cc55d2941707999d7f29b6739882444dda5849a6.tar.gz
brdo-cc55d2941707999d7f29b6739882444dda5849a6.tar.bz2
- Patch #187398 by andypost, Crell, lilou, Gábor Hojtsy, sun: re-split locale module.
-rw-r--r--includes/locale.inc1261
-rw-r--r--modules/locale/locale.admin.inc1435
-rw-r--r--modules/locale/locale.info1
-rw-r--r--modules/locale/locale.module212
4 files changed, 1455 insertions, 1454 deletions
diff --git a/includes/locale.inc b/includes/locale.inc
index 9b1e95b9a..e9197f46e 100644
--- a/includes/locale.inc
+++ b/includes/locale.inc
@@ -36,722 +36,11 @@ define('LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX', 0);
define('LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN', 1);
/**
- * @defgroup locale-language-overview Language overview functionality
- * @{
- */
-
-/**
- * User interface for the language overview screen.
- */
-function locale_languages_overview_form() {
- drupal_static_reset('language');
- $languages = language_list('language');
-
- $options = array();
- $form['weight'] = array('#tree' => TRUE);
- foreach ($languages as $langcode => $language) {
-
- $options[$langcode] = '';
- if ($language->enabled) {
- $enabled[] = $langcode;
- }
- $form['weight'][$langcode] = array(
- '#type' => 'weight',
- '#default_value' => $language->weight,
- '#attributes' => array('class' => array('language-order-weight')),
- );
- $form['name'][$langcode] = array('#markup' => check_plain($language->name));
- $form['native'][$langcode] = array('#markup' => check_plain($language->native));
- $form['direction'][$langcode] = array('#markup' => ($language->direction == LANGUAGE_RTL ? t('Right to left') : t('Left to right')));
- }
- $form['enabled'] = array('#type' => 'checkboxes',
- '#options' => $options,
- '#default_value' => $enabled,
- );
- $form['site_default'] = array('#type' => 'radios',
- '#options' => $options,
- '#default_value' => language_default('language'),
- );
- $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
- $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
- $form['#theme'] = 'locale_languages_overview_form';
-
- return $form;
-}
-
-/**
- * Theme the language overview form.
- *
- * @param $variables
- * An associative array containing:
- * - form: @todo: document
- *
- * @return
- * A themed HTML string representing the form.
- *
- * @ingroup themeable
- */
-function theme_locale_languages_overview_form($variables) {
- $form = $variables['form'];
- $default = language_default();
- foreach ($form['name'] as $key => $element) {
- // Do not take form control structures.
- if (is_array($element) && element_child($key)) {
- // Disable checkbox for the default language, because it cannot be disabled.
- if ($key == $default->language) {
- $form['enabled'][$key]['#attributes']['disabled'] = 'disabled';
- }
- $rows[] = array(
- 'data' => array(
- '<strong>' . drupal_render($form['name'][$key]) . '</strong>',
- drupal_render($form['native'][$key]),
- check_plain($key),
- drupal_render($form['direction'][$key]),
- array('data' => drupal_render($form['enabled'][$key]), 'align' => 'center'),
- drupal_render($form['site_default'][$key]),
- drupal_render($form['weight'][$key]),
- l(t('edit'), 'admin/config/regional/language/edit/' . $key) . (($key != 'en' && $key != $default->language) ? ' ' . l(t('delete'), 'admin/config/regional/language/delete/' . $key) : '')
- ),
- 'class' => array('draggable'),
- );
- }
- }
- $header = array(array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Code')), array('data' => t('Direction')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations')));
- $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'language-order')));
- $output .= drupal_render_children($form);
-
- drupal_add_tabledrag('language-order', 'order', 'sibling', 'language-order-weight');
-
- return $output;
-}
-
-/**
- * Process language overview form submissions, updating existing languages.
- */
-function locale_languages_overview_form_submit($form, &$form_state) {
- $languages = language_list();
- $default = language_default();
- $enabled_count = 0;
- foreach ($languages as $langcode => $language) {
- if ($form_state['values']['site_default'] == $langcode || $default->language == $langcode) {
- // Automatically enable the default language and the language
- // which was default previously (because we will not get the
- // value from that disabled checkox).
- $form_state['values']['enabled'][$langcode] = 1;
- }
- if ($form_state['values']['enabled'][$langcode]) {
- $enabled_count++;
- $language->enabled = 1;
- }
- else {
- $language->enabled = 0;
- }
- $language->weight = $form_state['values']['weight'][$langcode];
- db_update('languages')
- ->fields(array(
- 'enabled' => $language->enabled,
- 'weight' => $language->weight,
- ))
- ->condition('language', $langcode)
- ->execute();
- $languages[$langcode] = $language;
- }
- drupal_set_message(t('Configuration saved.'));
- variable_set('language_default', $languages[$form_state['values']['site_default']]);
- variable_set('language_count', $enabled_count);
-
- // Changing the language settings impacts the interface.
- cache_clear_all('*', 'cache_page', TRUE);
- module_invoke_all('multilingual_settings_changed');
-
- $form_state['redirect'] = 'admin/config/regional/language';
- return;
-}
-/**
- * @} End of "locale-language-overview"
- */
-
-/**
- * @defgroup locale-language-add-edit Language addition and editing functionality
- * @{
- */
-
-/**
- * User interface for the language addition screen.
- */
-function locale_languages_add_screen() {
- $build['predefined'] = drupal_get_form('locale_languages_predefined_form');
- $build['custom'] = drupal_get_form('locale_languages_custom_form');
- return $build;
-}
-
-/**
- * Predefined language setup form.
- */
-function locale_languages_predefined_form($form) {
- $predefined = _locale_prepare_predefined_list();
- $form['language list'] = array('#type' => 'fieldset',
- '#title' => t('Predefined language'),
- '#collapsible' => TRUE,
- );
- $form['language list']['langcode'] = array('#type' => 'select',
- '#title' => t('Language name'),
- '#default_value' => key($predefined),
- '#options' => $predefined,
- '#description' => t('Select the desired language and click the <em>Add language</em> button. (Use the <em>Custom language</em> options if your desired language does not appear in this list.)'),
- );
- $form['language list']['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
- $form['language list']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Add language'));
- return $form;
-}
-
-/**
- * Custom language addition form.
- */
-function locale_languages_custom_form($form) {
- $form['custom language'] = array('#type' => 'fieldset',
- '#title' => t('Custom language'),
- '#collapsible' => TRUE,
- '#collapsed' => TRUE,
- );
- _locale_languages_common_controls($form['custom language']);
- $form['custom language']['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
- $form['custom language']['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Add custom language')
- );
- // Reuse the validation and submit functions of the predefined language setup form.
- $form['#submit'][] = 'locale_languages_predefined_form_submit';
- $form['#validate'][] = 'locale_languages_predefined_form_validate';
- return $form;
-}
-
-/**
- * Editing screen for a particular language.
- *
- * @param $langcode
- * Language code of the language to edit.
- */
-function locale_languages_edit_form($form, &$form_state, $langcode) {
- if ($language = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchObject()) {
- _locale_languages_common_controls($form, $language);
- $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save language')
- );
- $form['#submit'][] = 'locale_languages_edit_form_submit';
- $form['#validate'][] = 'locale_languages_edit_form_validate';
- return $form;
- }
- else {
- drupal_not_found();
- drupal_exit();
- }
-}
-
-/**
- * Common elements of the language addition and editing form.
- *
- * @param $form
- * A parent form item (or empty array) to add items below.
- * @param $language
- * Language object to edit.
- */
-function _locale_languages_common_controls(&$form, $language = NULL) {
- if (!is_object($language)) {
- $language = new stdClass();
- }
- if (isset($language->language)) {
- $form['langcode_view'] = array(
- '#type' => 'item',
- '#title' => t('Language code'),
- '#markup' => $language->language
- );
- $form['langcode'] = array(
- '#type' => 'value',
- '#value' => $language->language
- );
- }
- else {
- $form['langcode'] = array('#type' => 'textfield',
- '#title' => t('Language code'),
- '#size' => 12,
- '#maxlength' => 60,
- '#required' => TRUE,
- '#default_value' => @$language->language,
- '#disabled' => (isset($language->language)),
- '#description' => t('<a href="@rfc4646">RFC 4646</a> compliant language identifier. Language codes typically use a country code, and optionally, a script or regional variant name. <em>Examples: "en", "en-US" and "zh-Hant".</em>', array('@rfc4646' => 'http://www.ietf.org/rfc/rfc4646.txt')),
- );
- }
- $form['name'] = array('#type' => 'textfield',
- '#title' => t('Language name in English'),
- '#maxlength' => 64,
- '#default_value' => @$language->name,
- '#required' => TRUE,
- '#description' => t('Name of the language in English. Will be available for translation in all languages.'),
- );
- $form['native'] = array('#type' => 'textfield',
- '#title' => t('Native language name'),
- '#maxlength' => 64,
- '#default_value' => @$language->native,
- '#required' => TRUE,
- '#description' => t('Name of the language in the language being added.'),
- );
- $form['prefix'] = array('#type' => 'textfield',
- '#title' => t('Path prefix'),
- '#maxlength' => 64,
- '#default_value' => @$language->prefix,
- '#description' => t('Language code or other custom string for pattern matching within the path. With language negotiation set to <em>Path prefix only</em> or <em>Path prefix with language fallback</em>, this site is presented in this language when the Path prefix value matches an element in the path. For the default language, this value may be left blank. <strong>Modifying this value will break existing URLs and should be used with caution in a production environment.</strong> <em>Example: Specifying "deutsch" as the path prefix for German results in URLs in the form "www.example.com/deutsch/node".</em>')
- );
- $form['domain'] = array('#type' => 'textfield',
- '#title' => t('Language domain'),
- '#maxlength' => 128,
- '#default_value' => @$language->domain,
- '#description' => t('Language-specific URL, with protocol. With language negotiation set to <em>Domain name only</em>, the site is presented in this language when the URL accessing the site references this domain. For the default language, this value may be left blank. <strong>This value must include a protocol as part of the string.</strong> <em>Example: Specifying "http://example.de" or "http://de.example.com" as language domains for German results in URLs in the forms "http://example.de/node" and "http://de.example.com/node", respectively.</em>'),
- );
- $form['direction'] = array('#type' => 'radios',
- '#title' => t('Direction'),
- '#required' => TRUE,
- '#description' => t('Direction that text in this language is presented.'),
- '#default_value' => @$language->direction,
- '#options' => array(LANGUAGE_LTR => t('Left to right'), LANGUAGE_RTL => t('Right to left'))
- );
- return $form;
-}
-
-/**
- * Validate the language addition form.
- */
-function locale_languages_predefined_form_validate($form, &$form_state) {
- $langcode = $form_state['values']['langcode'];
-
- if (($duplicate = db_query("SELECT COUNT(*) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) != 0) {
- form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_state['values']['name'], '%code' => $langcode)));
- }
-
- if (!isset($form_state['values']['name'])) {
- // Predefined language selection.
- include_once DRUPAL_ROOT . '/includes/iso.inc';
- $predefined = _locale_get_predefined_list();
- if (!isset($predefined[$langcode])) {
- form_set_error('langcode', t('Invalid language code.'));
- }
- }
- else {
- // Reuse the editing form validation routine if we add a custom language.
- locale_languages_edit_form_validate($form, $form_state);
- }
-}
-
-/**
- * Process the language addition form submission.
- */
-function locale_languages_predefined_form_submit($form, &$form_state) {
- $langcode = $form_state['values']['langcode'];
- if (isset($form_state['values']['name'])) {
- // Custom language form.
- locale_add_language($langcode, $form_state['values']['name'], $form_state['values']['native'], $form_state['values']['direction'], $form_state['values']['domain'], $form_state['values']['prefix']);
- drupal_set_message(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($form_state['values']['name']), '@locale-help' => url('admin/help/locale'))));
- }
- else {
- // Predefined language selection.
- 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 and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($predefined[$langcode][0]), '@locale-help' => url('admin/help/locale'))));
- }
-
- // See if we have language files to import for the newly added
- // language, collect and import them.
- if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) {
- batch_set($batch);
- }
-
- module_invoke_all('multilingual_settings_changed');
-
- $form_state['redirect'] = 'admin/config/regional/language';
- return;
-}
-
-/**
- * Validate the language editing form. Reused for custom language addition too.
- */
-function locale_languages_edit_form_validate($form, &$form_state) {
- if (!empty($form_state['values']['domain']) && !empty($form_state['values']['prefix'])) {
- form_set_error('prefix', t('Domain and path prefix values should not be set at the same time.'));
- }
- if (!empty($form_state['values']['domain']) && $duplicate = db_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) {
- form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_state['values']['domain'], '%language' => $duplicate->language)));
- }
- if (empty($form_state['values']['prefix']) && language_default('language') != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) {
- form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.'));
- }
- if (!empty($form_state['values']['prefix']) && $duplicate = db_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) {
- form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_state['values']['prefix'], '%language' => $duplicate->language)));
- }
-}
-
-/**
- * Process the language editing form submission.
- */
-function locale_languages_edit_form_submit($form, &$form_state) {
- db_update('languages')
- ->fields(array(
- 'name' => $form_state['values']['name'],
- 'native' => $form_state['values']['native'],
- 'domain' => $form_state['values']['domain'],
- 'prefix' => $form_state['values']['prefix'],
- 'direction' => $form_state['values']['direction'],
- ))
- ->condition('language', $form_state['values']['langcode'])
- ->execute();
- $default = language_default();
- if ($default->language == $form_state['values']['langcode']) {
- $properties = array('name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight');
- foreach ($properties as $keyname) {
- if (isset($form_state['values'][$keyname])) {
- $default->$keyname = $form_state['values'][$keyname];
- }
- }
- variable_set('language_default', $default);
- }
- $form_state['redirect'] = 'admin/config/regional/language';
- return;
-}
-/**
- * @} End of "locale-language-add-edit"
- */
-
-/**
- * @defgroup locale-language-delete Language deletion functionality
- * @{
- */
-
-/**
- * User interface for the language deletion confirmation screen.
- */
-function locale_languages_delete_form($form, &$form_state, $langcode) {
-
- // Do not allow deletion of English locale.
- if ($langcode == 'en') {
- drupal_set_message(t('The English language cannot be deleted.'));
- drupal_goto('admin/config/regional/language');
- }
-
- if (language_default('language') == $langcode) {
- drupal_set_message(t('The default language cannot be deleted.'));
- drupal_goto('admin/config/regional/language');
- }
-
- // For other languages, warn user that data loss is ahead.
- $languages = language_list();
-
- if (!isset($languages[$langcode])) {
- drupal_not_found();
- drupal_exit();
- }
- else {
- $form['langcode'] = array('#type' => 'value', '#value' => $langcode);
- return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages[$langcode]->name))), 'admin/config/regional/language', t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.'), t('Delete'), t('Cancel'));
- }
-}
-
-/**
- * Process language deletion submissions.
- */
-function locale_languages_delete_form_submit($form, &$form_state) {
- $languages = language_list();
- if (isset($languages[$form_state['values']['langcode']])) {
- // Remove translations first.
- db_delete('locales_target')
- ->condition('language', $form_state['values']['langcode'])
- ->execute();
- cache_clear_all('locale:' . $form_state['values']['langcode'], 'cache');
- // With no translations, this removes existing JavaScript translations file.
- _locale_rebuild_js($form_state['values']['langcode']);
- // Remove the language.
- db_delete('languages')
- ->condition('language', $form_state['values']['langcode'])
- ->execute();
- db_update('node')
- ->fields(array('language' => ''))
- ->condition('language', $form_state['values']['langcode'])
- ->execute();
- module_invoke_all('multilingual_settings_changed');
- $variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
- drupal_set_message(t('The language %locale has been removed.', $variables));
- watchdog('locale', 'The language %locale has been removed.', $variables);
- }
-
- // Changing the language settings impacts the interface:
- cache_clear_all('*', 'cache_page', TRUE);
-
- $form_state['redirect'] = 'admin/config/regional/language';
- return;
-}
-/**
- * @} End of "locale-language-add-edit"
- */
-
-/**
* @defgroup locale-languages-negotiation Language negotiation options
* @{
*/
/**
- * Setting for language negotiation options
- */
-function locale_languages_configure_form() {
- include_once DRUPAL_ROOT . '/includes/language.inc';
-
- $form = array(
- '#submit' => array('locale_languages_configure_form_submit'),
- '#theme' => 'locale_languages_configure_form',
- '#language_types' => language_types_configurable(),
- '#language_types_info' => language_types_info(),
- '#language_providers' => language_negotiation_info(),
- );
-
- foreach ($form['#language_types'] as $type) {
- _locale_languages_configure_form_language_table($form, $type);
- }
-
- $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save settings'),
- );
-
- return $form;
-}
-
-/**
- * Helper function to build a language provider table.
- */
-function _locale_languages_configure_form_language_table(&$form, $type) {
- $info = $form['#language_types_info'][$type];
-
- $table_form = array(
- '#title' => t('@type language', array('@type' => $info['name'])),
- '#tree' => TRUE,
- '#description' => $info['description'],
- '#language_providers' => array(),
- '#show_operations' => FALSE,
- 'weight' => array('#tree' => TRUE),
- 'enabled' => array('#tree' => TRUE),
- );
-
- $language_providers = $form['#language_providers'];
- $enabled_providers = variable_get("locale_language_providers_enabled_$type", array());
- $providers_weight = variable_get("locale_language_providers_weight_$type", array());
-
- // Add missing data to the providers lists.
- foreach ($language_providers as $id => $provider) {
- if (!isset($providers_weight[$id])) {
- $providers_weight[$id] = language_provider_weight($provider);
- }
- if (!isset($enabled_providers[$id])) {
- $enabled_providers[$id] = FALSE;
- }
- }
-
- // Order providers list by weight.
- asort($providers_weight);
-
- foreach ($providers_weight as $id => $weight) {
- $enabled = $enabled_providers[$id];
- $provider = $language_providers[$id];
-
- // List the provider only if the current type is defined in its 'types' key.
- // If it is not defined default to all the configurabe language types.
- $types = array_flip(isset($provider['types']) ? $provider['types'] : $form['#language_types']);
-
- if (isset($types[$type])) {
- $table_form['#language_providers'][$id] = $provider;
-
- $table_form['weight'][$id] = array(
- '#type' => 'weight',
- '#default_value' => $weight,
- '#attributes' => array('class' => array("language-provider-weight-$type")),
- );
-
- $table_form['title'][$id] = array('#markup' => check_plain($provider['name']));
-
- $table_form['enabled'][$id] = array('#type' => 'checkbox', '#default_value' => $enabled);
- if ($id === LANGUAGE_NEGOTIATION_DEFAULT) {
- $table_form['enabled'][$id]['#default_value'] = TRUE;
- $table_form['enabled'][$id]['#attributes'] = array('disabled' => 'disabled');
- }
-
- $table_form['description'][$id] = array('#markup' => filter_xss_admin($provider['description']));
-
- $config_op = array();
- if (isset($provider['config'])) {
- $config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $provider['config']);
- // If there is at least one operation enabled show the operation column.
- $table_form['#show_operations'] = TRUE;
- }
- $table_form['operation'][$id] = $config_op;
- }
- }
-
- $form[$type] = $table_form;
-}
-
-/**
- * Theme the language configure form.
- *
- * @ingroup themeable
- */
-function theme_locale_languages_configure_form($variables) {
- $form = $variables['form'];
- $output = '';
-
- foreach ($form['#language_types'] as $type) {
- $rows = array();
- $info = $form['#language_types_info'][$type];
- $title = '<label>' . $form[$type]['#title'] . '</label>';
- $description = '<div class="description">' . $form[$type]['#description'] . '</div>';
-
- foreach ($form[$type]['title'] as $id => $element) {
- // Do not take form control structures.
- if (is_array($element) && element_child($id)) {
- $row = array(
- 'data' => array(
- '<strong>' . drupal_render($form[$type]['title'][$id]) . '</strong>',
- drupal_render($form[$type]['description'][$id]),
- drupal_render($form[$type]['enabled'][$id]),
- drupal_render($form[$type]['weight'][$id]),
- ),
- 'class' => array('draggable'),
- );
- if ($form[$type]['#show_operations']) {
- $row['data'][] = drupal_render($form[$type]['operation'][$id]);
- }
- $rows[] = $row;
- }
- }
-
- $header = array(
- array('data' => t('Detection method')),
- array('data' => t('Description')),
- array('data' => t('Enabled')),
- array('data' => t('Weight')),
- );
-
- // If there is at least one operation enabled show the operation column.
- if ($form[$type]['#show_operations']) {
- $header[] = array('data' => t('Operations'));
- }
-
- $variables = array(
- 'header' => $header,
- 'rows' => $rows,
- 'attributes' => array('id' => "language-negotiation-providers-$type"),
- );
- $table = theme('table', $variables);
- $table .= drupal_render_children($form[$type]);
-
- drupal_add_tabledrag("language-negotiation-providers-$type", 'order', 'sibling', "language-provider-weight-$type");
-
- $output .= '<div class="form-item">' . $title . $description . $table . '</div>';
- }
-
- $output .= drupal_render_children($form);
- return $output;
-}
-
-/**
- * Submit handler for language negotiation settings.
- */
-function locale_languages_configure_form_submit($form, &$form_state) {
- $language_types = array();
- $configurable_types = $form['#language_types'];
-
- foreach ($configurable_types as $type) {
- $negotiation = array();
- $enabled_providers = $form_state['values'][$type]['enabled'];
- $enabled_providers[LANGUAGE_NEGOTIATION_DEFAULT] = TRUE;
- $providers_weight = $form_state['values'][$type]['weight'];
- $language_types[$type] = TRUE;
-
- foreach ($providers_weight as $id => $weight) {
- if ($enabled_providers[$id]) {
- $provider = $form[$type]['#language_providers'][$id];
- $provider['weight'] = $weight;
- $negotiation[$id] = $provider;
- }
- }
-
- language_negotiation_set($type, $negotiation);
- variable_set("locale_language_providers_enabled_$type", $enabled_providers);
- variable_set("locale_language_providers_weight_$type", $providers_weight);
- }
-
- // Save non-configurable language types negotiation.
- $language_types_info = language_types_info();
- $defined_providers = $form['#language_providers'];
- foreach ($language_types_info as $type => $info) {
- if (isset($info['fixed'])) {
- $language_types[$type] = FALSE;
- $negotiation = array();
- foreach ($info['fixed'] as $id) {
- if (isset($defined_providers[$id])) {
- $negotiation[$id] = $defined_providers[$id];
- }
- }
- language_negotiation_set($type, $negotiation);
- }
- }
-
- // Save language types.
- variable_set('language_types', $language_types);
-
- $form_state['redirect'] = 'admin/config/regional/language';
- drupal_set_message(t('Language negotiation configuration saved.'));
-}
-
-/**
- * The URL language provider configuration form.
- */
-function locale_language_providers_url_form() {
- $form = array();
-
- $form['locale_language_negotiation_url_part'] = array(
- '#title' => t('The part of the URL that will determine the language.'),
- '#type' => 'radios',
- '#options' => array(
- LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX => t('Path prefix'),
- LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN => t('Domain'),
- ),
- '#default_value' => variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX),
- );
-
- $form['#redirect'] = 'admin/config/regional/language/configure';
-
- return system_settings_form($form);
-}
-
-/**
- * The URL language provider configuration form.
- */
-function locale_language_providers_session_form() {
- $form = array();
-
- $form['locale_language_negotiation_session_param'] = array(
- '#title' => t('Request/session parameter'),
- '#type' => 'textfield',
- '#default_value' => variable_get('locale_language_negotiation_session_param', 'language'),
- '#description' => t('Name of the request/session parameter used to determine the desired language.'),
- );
-
- $form['#redirect'] = 'admin/config/regional/language/configure';
-
- return system_settings_form($form);
-}
-
-/**
* Identify the language from the current content language.
*
* @return
@@ -1009,442 +298,6 @@ function locale_language_url_rewrite_session(&$path, &$options) {
*/
/**
- * @defgroup locale-translate-overview Translation overview screen.
- * @{
- */
-
-/**
- * Overview screen for translations.
- */
-function locale_translate_overview_screen() {
- drupal_static_reset('language_list');
- $languages = language_list('language');
- $groups = module_invoke_all('locale', 'groups');
-
- // Build headers with all groups in order.
- $headers = array_merge(array(t('Language')), array_values($groups));
-
- // Collect summaries of all source strings in all groups.
- $sums = db_query("SELECT COUNT(*) AS strings, textgroup FROM {locales_source} GROUP BY textgroup");
- $groupsums = array();
- foreach ($sums as $group) {
- $groupsums[$group->textgroup] = $group->strings;
- }
-
- // Set up overview table with default values, ensuring common order for values.
- $rows = array();
- foreach ($languages as $langcode => $language) {
- $rows[$langcode] = array('name' => ($langcode == 'en' ? t('English (built-in)') : t($language->name)));
- foreach ($groups as $group => $name) {
- $rows[$langcode][$group] = ($langcode == 'en' ? t('n/a') : '0/' . (isset($groupsums[$group]) ? $groupsums[$group] : 0) . ' (0%)');
- }
- }
-
- // Languages with at least one record in the locale table.
- $translations = db_query("SELECT COUNT(*) AS translation, t.language, s.textgroup FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY textgroup, language");
- foreach ($translations as $data) {
- $ratio = (!empty($groupsums[$data->textgroup]) && $data->translation > 0) ? round(($data->translation/$groupsums[$data->textgroup]) * 100.0, 2) : 0;
- $rows[$data->language][$data->textgroup] = $data->translation . '/' . $groupsums[$data->textgroup] . " ($ratio%)";
- }
-
- return theme('table', array('header' => $headers, 'rows' => $rows));
-}
-/**
- * @} End of "locale-translate-overview"
- */
-
-/**
- * @defgroup locale-translate-seek Translation search screen.
- * @{
- */
-
-/**
- * String search screen.
- */
-function locale_translate_seek_screen() {
- // Add CSS.
- drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css', array('preprocess' => FALSE));
-
- $output = drupal_render(drupal_get_form('locale_translation_filter_form'));
- $output .= _locale_translate_seek();
- return $output;
-}
-/**
- * @} End of "locale-translate-seek"
- */
-
-/**
- * List locale translation filters that can be applied.
- */
-function locale_translation_filters() {
- $filters = array();
-
- // Get all languages, except English
- drupal_static_reset('language_list');
- $languages = locale_language_list('name');
- unset($languages['en']);
-
- $filters['string'] = array(
- 'title' => t('String contains'),
- 'description' => t('Leave blank to show all strings. The search is case sensitive.'),
- );
-
- $filters['language'] = array(
- 'title' => t('Language'),
- 'options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages),
- );
-
- $filters['translation'] = array(
- 'title' => t('Search in'),
- 'options' => array('all' => t('Both translated and untranslated strings'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')),
- );
-
- $groups = module_invoke_all('locale', 'groups');
- $filters['group'] = array(
- 'title' => t('Limit search to'),
- 'options' => array_merge(array('all' => t('All text groups')), $groups),
- );
-
- return $filters;
-}
-
-/**
- * Return form for locale translation filters.
- *
- * @ingroup forms
- */
-function locale_translation_filter_form() {
- $filters = locale_translation_filters();
-
- $form['filters'] = array(
- '#type' => 'fieldset',
- '#title' => t('Filter translatable strings'),
- '#collapsible' => TRUE,
- '#collapsed' => FALSE,
- );
- foreach ($filters as $key => $filter) {
- // Special case for 'string' filter.
- if ($key == 'string') {
- $form['filters']['status']['string'] = array(
- '#type' => 'textfield',
- '#title' => $filter['title'],
- '#description' => $filter['description'],
- );
- }
- else {
- $form['filters']['status'][$key] = array(
- '#title' => $filter['title'],
- '#type' => 'select',
- '#multiple' => FALSE,
- '#size' => 0,
- '#options' => $filter['options'],
- );
- }
- if (!empty($_SESSION['locale_translation_filter'][$key])) {
- $form['filters']['status'][$key]['#default_value'] = $_SESSION['locale_translation_filter'][$key];
- }
- }
-
- $form['filters']['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions', 'container-inline')));
- $form['filters']['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Filter'),
- );
- if (!empty($_SESSION['locale_translation_filter'])) {
- $form['filters']['actions']['reset'] = array(
- '#type' => 'submit',
- '#value' => t('Reset')
- );
- }
-
- return $form;
-}
-
-/**
- * Validate result from locale translation filter form.
- */
-function locale_translation_filter_form_validate($form, &$form_state) {
- if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['language']) && empty($form_state['values']['group'])) {
- form_set_error('type', t('You must select something to filter by.'));
- }
-}
-
-/**
- * Process result from locale translation filter form.
- */
-function locale_translation_filter_form_submit($form, &$form_state) {
- $op = $form_state['values']['op'];
- $filters = locale_translation_filters();
- switch ($op) {
- case t('Filter'):
- foreach ($filters as $name => $filter) {
- if (isset($form_state['values'][$name])) {
- $_SESSION['locale_translation_filter'][$name] = $form_state['values'][$name];
- }
- }
- break;
- case t('Reset'):
- $_SESSION['locale_translation_filter'] = array();
- break;
- }
-
- $form_state['redirect'] = 'admin/config/regional/translate/translate';
-}
-
-/**
- * @defgroup locale-translate-import Translation import screen.
- * @{
- */
-
-/**
- * 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']['group'] = array('#type' => 'radios',
- '#title' => t('Text group'),
- '#default_value' => 'default',
- '#options' => module_invoke_all('locale', 'groups'),
- '#description' => t('Imported translations will be added to this text group.'),
- );
- $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'),
- LOCALE_IMPORT_KEEP => t('Existing strings 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) {
- // Ensure we have the file uploaded
- if ($file = file_save_upload('file')) {
-
- // 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'], $form_state['values']['group']) == 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;
-}
-/**
- * @} End of "locale-translate-import"
- */
-
-/**
- * @defgroup locale-translate-export Translation export screen.
- * @{
- */
-
-/**
- * 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)) {
- $output = drupal_render(drupal_get_form('locale_translate_export_po_form', $names));
- }
- $output .= drupal_render(drupal_get_form('locale_translate_export_pot_form'));
- 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'] = array('#type' => 'fieldset',
- '#title' => t('Export translation'),
- '#collapsible' => TRUE,
- );
- $form['export']['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['export']['group'] = array('#type' => 'radios',
- '#title' => t('Text group'),
- '#default_value' => 'default',
- '#options' => module_invoke_all('locale', 'groups'),
- );
- $form['export']['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'] = array('#type' => 'fieldset',
- '#title' => t('Export template'),
- '#collapsible' => TRUE,
- '#description' => t('Generate a Gettext Portable Object Template (<em>.pot</em>) file with all strings from the Drupal locale database.'),
- );
- $form['export']['group'] = array('#type' => 'radios',
- '#title' => t('Text group'),
- '#default_value' => 'default',
- '#options' => module_invoke_all('locale', 'groups'),
- );
- $form['export']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
- // Reuse PO export submission callback.
- $form['#submit'][] = 'locale_translate_export_po_form_submit';
- $form['#validate'][] = 'locale_translate_export_po_form_validate';
- 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, $form_state['values']['group'])));
-}
-/**
- * @} End of "locale-translate-export"
- */
-
-/**
- * @defgroup locale-translate-edit Translation text editing
- * @{
- */
-
-/**
- * User interface for string editing.
- */
-function locale_translate_edit_form($form, &$form_state, $lid) {
- // Fetch source string, if possible.
- $source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject();
- if (!$source) {
- drupal_set_message(t('String not found.'), 'error');
- drupal_goto('admin/config/regional/translate/translate');
- }
-
- // Add original text to the top and some values for form altering.
- $form['original'] = array(
- '#type' => 'item',
- '#title' => t('Original text'),
- '#markup' => check_plain(wordwrap($source->source, 0)),
- );
- if (!empty($source->context)) {
- $form['context'] = array(
- '#type' => 'item',
- '#title' => t('Context'),
- '#markup' => check_plain($source->context),
- );
- }
- $form['lid'] = array(
- '#type' => 'value',
- '#value' => $lid
- );
- $form['textgroup'] = array(
- '#type' => 'value',
- '#value' => $source->textgroup,
- );
- $form['location'] = array(
- '#type' => 'value',
- '#value' => $source->location
- );
-
- // Include default form controls with empty values for all languages.
- // This ensures that the languages are always in the same order in forms.
- $languages = language_list();
- $default = language_default();
- // We don't need the default language value, that value is in $source.
- $omit = $source->textgroup == 'default' ? 'en' : $default->language;
- unset($languages[($omit)]);
- $form['translations'] = array('#tree' => TRUE);
- // Approximate the number of rows to use in the default textarea.
- $rows = min(ceil(str_word_count($source->source) / 12), 10);
- foreach ($languages as $langcode => $language) {
- $form['translations'][$langcode] = array(
- '#type' => 'textarea',
- '#title' => t($language->name),
- '#rows' => $rows,
- '#default_value' => '',
- );
- }
-
- // Fetch translations and fill in default values in the form.
- $result = db_query("SELECT DISTINCT translation, language FROM {locales_target} WHERE lid = :lid AND language <> :omit", array(':lid' => $lid, ':omit' => $omit));
- foreach ($result as $translation) {
- $form['translations'][$translation->language]['#default_value'] = $translation->translation;
- }
-
- $form['submit'] = array('#type' => 'submit', '#value' => t('Save translations'));
- return $form;
-}
-
-/**
* Check that a string is safe to be added or imported as a translation.
*
* This test can be used to detect possibly bad translation strings. It should
@@ -1463,120 +316,6 @@ function locale_string_is_safe($string) {
}
/**
- * Validate string editing form submissions.
- */
-function locale_translate_edit_form_validate($form, &$form_state) {
- // Locale string check is needed for default textgroup only.
- $safe_check_needed = $form_state['values']['textgroup'] == 'default';
- foreach ($form_state['values']['translations'] as $key => $value) {
- if ($safe_check_needed && !locale_string_is_safe($value)) {
- form_set_error('translations', t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
- watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING);
- }
- }
-}
-
-/**
- * Process string editing form submissions.
- *
- * Saves all translations of one string submitted from a form.
- */
-function locale_translate_edit_form_submit($form, &$form_state) {
- $lid = $form_state['values']['lid'];
- foreach ($form_state['values']['translations'] as $key => $value) {
- $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchField();
- if (!empty($value)) {
- // Only update or insert if we have a value to use.
- if (!empty($translation)) {
- db_update('locales_target')
- ->fields(array(
- 'translation' => $value,
- ))
- ->condition('lid', $lid)
- ->condition('language', $key)
- ->execute();
- }
- else {
- db_insert('locales_target')
- ->fields(array(
- 'lid' => $lid,
- 'translation' => $value,
- 'language' => $key,
- ))
- ->execute();
- }
- }
- elseif (!empty($translation)) {
- // Empty translation entered: remove existing entry from database.
- db_delete('locales_target')
- ->condition('lid', $lid)
- ->condition('language', $key)
- ->execute();
- }
-
- // Force JavaScript translation file recreation for this language.
- _locale_invalidate_js($key);
- }
-
- drupal_set_message(t('The string has been saved.'));
-
- // Clear locale cache.
- _locale_invalidate_js();
- cache_clear_all('locale:', 'cache', TRUE);
-
- $form_state['redirect'] = 'admin/config/regional/translate/translate';
- return;
-}
-/**
- * @} End of "locale-translate-edit"
- */
-
-/**
- * @defgroup locale-translate-delete Translation delete interface.
- * @{
- */
-
-/**
- * String deletion confirmation page.
- */
-function locale_translate_delete_page($lid) {
- if ($source = db_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) {
- return drupal_get_form('locale_translate_delete_form', $source);
- }
- else {
- return drupal_not_found();
- }
-}
-
-/**
- * User interface for the string deletion confirmation screen.
- */
-function locale_translate_delete_form($form, &$form_state, $source) {
- $form['lid'] = array('#type' => 'value', '#value' => $source->lid);
- return confirm_form($form, t('Are you sure you want to delete the string "%source"?', array('%source' => $source->source)), 'admin/config/regional/translate/translate', t('Deleting the string will remove all translations of this string in all languages. This action cannot be undone.'), t('Delete'), t('Cancel'));
-}
-
-/**
- * Process string deletion submissions.
- */
-function locale_translate_delete_form_submit($form, &$form_state) {
- db_delete('locales_source')
- ->condition('lid', $form_state['values']['lid'])
- ->execute();
- db_delete('locales_target')
- ->condition('lid', $form_state['values']['lid'])
- ->execute();
- // Force JavaScript translation file recreation for all languages.
- _locale_invalidate_js();
- cache_clear_all('locale:', 'cache', TRUE);
- drupal_set_message(t('The string has been removed.'));
- $form_state['redirect'] = 'admin/config/regional/translate/translate';
-}
-/**
- * @} End of "locale-translate-delete"
- */
-
-/**
* @defgroup locale-api-add Language addition API.
* @{
*/
diff --git a/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc
new file mode 100644
index 000000000..9bb1803bc
--- /dev/null
+++ b/modules/locale/locale.admin.inc
@@ -0,0 +1,1435 @@
+<?php
+// $Id$
+
+/**
+ * @file
+ * Administration functions for locale.module.
+ */
+
+/**
+ * @defgroup locale-language-overview Language overview functionality
+ * @{
+ */
+
+/**
+ * User interface for the language overview screen.
+ */
+function locale_languages_overview_form() {
+ drupal_static_reset('language');
+ $languages = language_list('language');
+
+ $options = array();
+ $form['weight'] = array('#tree' => TRUE);
+ foreach ($languages as $langcode => $language) {
+
+ $options[$langcode] = '';
+ if ($language->enabled) {
+ $enabled[] = $langcode;
+ }
+ $form['weight'][$langcode] = array(
+ '#type' => 'weight',
+ '#default_value' => $language->weight,
+ '#attributes' => array('class' => array('language-order-weight')),
+ );
+ $form['name'][$langcode] = array('#markup' => check_plain($language->name));
+ $form['native'][$langcode] = array('#markup' => check_plain($language->native));
+ $form['direction'][$langcode] = array('#markup' => ($language->direction == LANGUAGE_RTL ? t('Right to left') : t('Left to right')));
+ }
+ $form['enabled'] = array('#type' => 'checkboxes',
+ '#options' => $options,
+ '#default_value' => $enabled,
+ );
+ $form['site_default'] = array('#type' => 'radios',
+ '#options' => $options,
+ '#default_value' => language_default('language'),
+ );
+ $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
+ $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration'));
+ $form['#theme'] = 'locale_languages_overview_form';
+
+ return $form;
+}
+
+/**
+ * Theme the language overview form.
+ *
+ * @param $variables
+ * An associative array containing:
+ * - form: @todo: document
+ *
+ * @return
+ * A themed HTML string representing the form.
+ *
+ * @ingroup themeable
+ */
+function theme_locale_languages_overview_form($variables) {
+ $form = $variables['form'];
+ $default = language_default();
+ foreach ($form['name'] as $key => $element) {
+ // Do not take form control structures.
+ if (is_array($element) && element_child($key)) {
+ // Disable checkbox for the default language, because it cannot be disabled.
+ if ($key == $default->language) {
+ $form['enabled'][$key]['#attributes']['disabled'] = 'disabled';
+ }
+ $rows[] = array(
+ 'data' => array(
+ '<strong>' . drupal_render($form['name'][$key]) . '</strong>',
+ drupal_render($form['native'][$key]),
+ check_plain($key),
+ drupal_render($form['direction'][$key]),
+ array('data' => drupal_render($form['enabled'][$key]), 'align' => 'center'),
+ drupal_render($form['site_default'][$key]),
+ drupal_render($form['weight'][$key]),
+ l(t('edit'), 'admin/config/regional/language/edit/' . $key) . (($key != 'en' && $key != $default->language) ? ' ' . l(t('delete'), 'admin/config/regional/language/delete/' . $key) : '')
+ ),
+ 'class' => array('draggable'),
+ );
+ }
+ }
+ $header = array(array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Code')), array('data' => t('Direction')), array('data' => t('Enabled')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations')));
+ $output = theme('table', array('header' => $header, 'rows' => $rows, 'attributes' => array('id' => 'language-order')));
+ $output .= drupal_render_children($form);
+
+ drupal_add_tabledrag('language-order', 'order', 'sibling', 'language-order-weight');
+
+ return $output;
+}
+
+/**
+ * Process language overview form submissions, updating existing languages.
+ */
+function locale_languages_overview_form_submit($form, &$form_state) {
+ $languages = language_list();
+ $default = language_default();
+ $enabled_count = 0;
+ foreach ($languages as $langcode => $language) {
+ if ($form_state['values']['site_default'] == $langcode || $default->language == $langcode) {
+ // Automatically enable the default language and the language
+ // which was default previously (because we will not get the
+ // value from that disabled checkox).
+ $form_state['values']['enabled'][$langcode] = 1;
+ }
+ if ($form_state['values']['enabled'][$langcode]) {
+ $enabled_count++;
+ $language->enabled = 1;
+ }
+ else {
+ $language->enabled = 0;
+ }
+ $language->weight = $form_state['values']['weight'][$langcode];
+ db_update('languages')
+ ->fields(array(
+ 'enabled' => $language->enabled,
+ 'weight' => $language->weight,
+ ))
+ ->condition('language', $langcode)
+ ->execute();
+ $languages[$langcode] = $language;
+ }
+ drupal_set_message(t('Configuration saved.'));
+ variable_set('language_default', $languages[$form_state['values']['site_default']]);
+ variable_set('language_count', $enabled_count);
+
+ // Changing the language settings impacts the interface.
+ cache_clear_all('*', 'cache_page', TRUE);
+ module_invoke_all('multilingual_settings_changed');
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+/**
+ * @} End of "locale-language-overview"
+ */
+
+/**
+ * @defgroup locale-language-add-edit Language addition and editing functionality
+ * @{
+ */
+
+/**
+ * User interface for the language addition screen.
+ */
+function locale_languages_add_screen() {
+ $build['predefined'] = drupal_get_form('locale_languages_predefined_form');
+ $build['custom'] = drupal_get_form('locale_languages_custom_form');
+ return $build;
+}
+
+/**
+ * Predefined language setup form.
+ */
+function locale_languages_predefined_form($form) {
+ $predefined = _locale_prepare_predefined_list();
+ $form['language list'] = array('#type' => 'fieldset',
+ '#title' => t('Predefined language'),
+ '#collapsible' => TRUE,
+ );
+ $form['language list']['langcode'] = array('#type' => 'select',
+ '#title' => t('Language name'),
+ '#default_value' => key($predefined),
+ '#options' => $predefined,
+ '#description' => t('Select the desired language and click the <em>Add language</em> button. (Use the <em>Custom language</em> options if your desired language does not appear in this list.)'),
+ );
+ $form['language list']['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
+ $form['language list']['actions']['submit'] = array('#type' => 'submit', '#value' => t('Add language'));
+ return $form;
+}
+
+/**
+ * Custom language addition form.
+ */
+function locale_languages_custom_form($form) {
+ $form['custom language'] = array('#type' => 'fieldset',
+ '#title' => t('Custom language'),
+ '#collapsible' => TRUE,
+ '#collapsed' => TRUE,
+ );
+ _locale_languages_common_controls($form['custom language']);
+ $form['custom language']['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
+ $form['custom language']['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Add custom language')
+ );
+ // Reuse the validation and submit functions of the predefined language setup form.
+ $form['#submit'][] = 'locale_languages_predefined_form_submit';
+ $form['#validate'][] = 'locale_languages_predefined_form_validate';
+ return $form;
+}
+
+/**
+ * Editing screen for a particular language.
+ *
+ * @param $langcode
+ * Language code of the language to edit.
+ */
+function locale_languages_edit_form($form, &$form_state, $langcode) {
+ if ($language = db_query("SELECT * FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchObject()) {
+ _locale_languages_common_controls($form, $language);
+ $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save language')
+ );
+ $form['#submit'][] = 'locale_languages_edit_form_submit';
+ $form['#validate'][] = 'locale_languages_edit_form_validate';
+ return $form;
+ }
+ else {
+ drupal_not_found();
+ drupal_exit();
+ }
+}
+
+/**
+ * Common elements of the language addition and editing form.
+ *
+ * @param $form
+ * A parent form item (or empty array) to add items below.
+ * @param $language
+ * Language object to edit.
+ */
+function _locale_languages_common_controls(&$form, $language = NULL) {
+ if (!is_object($language)) {
+ $language = new stdClass();
+ }
+ if (isset($language->language)) {
+ $form['langcode_view'] = array(
+ '#type' => 'item',
+ '#title' => t('Language code'),
+ '#markup' => $language->language
+ );
+ $form['langcode'] = array(
+ '#type' => 'value',
+ '#value' => $language->language
+ );
+ }
+ else {
+ $form['langcode'] = array('#type' => 'textfield',
+ '#title' => t('Language code'),
+ '#size' => 12,
+ '#maxlength' => 60,
+ '#required' => TRUE,
+ '#default_value' => @$language->language,
+ '#disabled' => (isset($language->language)),
+ '#description' => t('<a href="@rfc4646">RFC 4646</a> compliant language identifier. Language codes typically use a country code, and optionally, a script or regional variant name. <em>Examples: "en", "en-US" and "zh-Hant".</em>', array('@rfc4646' => 'http://www.ietf.org/rfc/rfc4646.txt')),
+ );
+ }
+ $form['name'] = array('#type' => 'textfield',
+ '#title' => t('Language name in English'),
+ '#maxlength' => 64,
+ '#default_value' => @$language->name,
+ '#required' => TRUE,
+ '#description' => t('Name of the language in English. Will be available for translation in all languages.'),
+ );
+ $form['native'] = array('#type' => 'textfield',
+ '#title' => t('Native language name'),
+ '#maxlength' => 64,
+ '#default_value' => @$language->native,
+ '#required' => TRUE,
+ '#description' => t('Name of the language in the language being added.'),
+ );
+ $form['prefix'] = array('#type' => 'textfield',
+ '#title' => t('Path prefix'),
+ '#maxlength' => 64,
+ '#default_value' => @$language->prefix,
+ '#description' => t('Language code or other custom string for pattern matching within the path. With language negotiation set to <em>Path prefix only</em> or <em>Path prefix with language fallback</em>, this site is presented in this language when the Path prefix value matches an element in the path. For the default language, this value may be left blank. <strong>Modifying this value will break existing URLs and should be used with caution in a production environment.</strong> <em>Example: Specifying "deutsch" as the path prefix for German results in URLs in the form "www.example.com/deutsch/node".</em>')
+ );
+ $form['domain'] = array('#type' => 'textfield',
+ '#title' => t('Language domain'),
+ '#maxlength' => 128,
+ '#default_value' => @$language->domain,
+ '#description' => t('Language-specific URL, with protocol. With language negotiation set to <em>Domain name only</em>, the site is presented in this language when the URL accessing the site references this domain. For the default language, this value may be left blank. <strong>This value must include a protocol as part of the string.</strong> <em>Example: Specifying "http://example.de" or "http://de.example.com" as language domains for German results in URLs in the forms "http://example.de/node" and "http://de.example.com/node", respectively.</em>'),
+ );
+ $form['direction'] = array('#type' => 'radios',
+ '#title' => t('Direction'),
+ '#required' => TRUE,
+ '#description' => t('Direction that text in this language is presented.'),
+ '#default_value' => @$language->direction,
+ '#options' => array(LANGUAGE_LTR => t('Left to right'), LANGUAGE_RTL => t('Right to left'))
+ );
+ return $form;
+}
+
+/**
+ * Validate the language addition form.
+ */
+function locale_languages_predefined_form_validate($form, &$form_state) {
+ $langcode = $form_state['values']['langcode'];
+
+ if (($duplicate = db_query("SELECT COUNT(*) FROM {languages} WHERE language = :language", array(':language' => $langcode))->fetchField()) != 0) {
+ form_set_error('langcode', t('The language %language (%code) already exists.', array('%language' => $form_state['values']['name'], '%code' => $langcode)));
+ }
+
+ if (!isset($form_state['values']['name'])) {
+ // Predefined language selection.
+ include_once DRUPAL_ROOT . '/includes/iso.inc';
+ $predefined = _locale_get_predefined_list();
+ if (!isset($predefined[$langcode])) {
+ form_set_error('langcode', t('Invalid language code.'));
+ }
+ }
+ else {
+ // Reuse the editing form validation routine if we add a custom language.
+ locale_languages_edit_form_validate($form, $form_state);
+ }
+}
+
+/**
+ * Process the language addition form submission.
+ */
+function locale_languages_predefined_form_submit($form, &$form_state) {
+ $langcode = $form_state['values']['langcode'];
+ if (isset($form_state['values']['name'])) {
+ // Custom language form.
+ locale_add_language($langcode, $form_state['values']['name'], $form_state['values']['native'], $form_state['values']['direction'], $form_state['values']['domain'], $form_state['values']['prefix']);
+ drupal_set_message(t('The language %language has been created and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($form_state['values']['name']), '@locale-help' => url('admin/help/locale'))));
+ }
+ else {
+ // Predefined language selection.
+ 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 and can now be used. More information is available on the <a href="@locale-help">help screen</a>.', array('%language' => t($predefined[$langcode][0]), '@locale-help' => url('admin/help/locale'))));
+ }
+
+ // See if we have language files to import for the newly added
+ // language, collect and import them.
+ if ($batch = locale_batch_by_language($langcode, '_locale_batch_language_finished')) {
+ batch_set($batch);
+ }
+
+ module_invoke_all('multilingual_settings_changed');
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+
+/**
+ * Validate the language editing form. Reused for custom language addition too.
+ */
+function locale_languages_edit_form_validate($form, &$form_state) {
+ if (!empty($form_state['values']['domain']) && !empty($form_state['values']['prefix'])) {
+ form_set_error('prefix', t('Domain and path prefix values should not be set at the same time.'));
+ }
+ if (!empty($form_state['values']['domain']) && $duplicate = db_query("SELECT language FROM {languages} WHERE domain = :domain AND language <> :language", array(':domain' => $form_state['values']['domain'], ':language' => $form_state['values']['langcode']))->fetchField()) {
+ form_set_error('domain', t('The domain (%domain) is already tied to a language (%language).', array('%domain' => $form_state['values']['domain'], '%language' => $duplicate->language)));
+ }
+ if (empty($form_state['values']['prefix']) && language_default('language') != $form_state['values']['langcode'] && empty($form_state['values']['domain'])) {
+ form_set_error('prefix', t('Only the default language can have both the domain and prefix empty.'));
+ }
+ if (!empty($form_state['values']['prefix']) && $duplicate = db_query("SELECT language FROM {languages} WHERE prefix = :prefix AND language <> :language", array(':prefix' => $form_state['values']['prefix'], ':language' => $form_state['values']['langcode']))->fetchField()) {
+ form_set_error('prefix', t('The prefix (%prefix) is already tied to a language (%language).', array('%prefix' => $form_state['values']['prefix'], '%language' => $duplicate->language)));
+ }
+}
+
+/**
+ * Process the language editing form submission.
+ */
+function locale_languages_edit_form_submit($form, &$form_state) {
+ db_update('languages')
+ ->fields(array(
+ 'name' => $form_state['values']['name'],
+ 'native' => $form_state['values']['native'],
+ 'domain' => $form_state['values']['domain'],
+ 'prefix' => $form_state['values']['prefix'],
+ 'direction' => $form_state['values']['direction'],
+ ))
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ $default = language_default();
+ if ($default->language == $form_state['values']['langcode']) {
+ $properties = array('name', 'native', 'direction', 'enabled', 'plurals', 'formula', 'domain', 'prefix', 'weight');
+ foreach ($properties as $keyname) {
+ if (isset($form_state['values'][$keyname])) {
+ $default->$keyname = $form_state['values'][$keyname];
+ }
+ }
+ variable_set('language_default', $default);
+ }
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+/**
+ * @} End of "locale-language-add-edit"
+ */
+
+/**
+ * @defgroup locale-language-delete Language deletion functionality
+ * @{
+ */
+
+/**
+ * User interface for the language deletion confirmation screen.
+ */
+function locale_languages_delete_form($form, &$form_state, $langcode) {
+
+ // Do not allow deletion of English locale.
+ if ($langcode == 'en') {
+ drupal_set_message(t('The English language cannot be deleted.'));
+ drupal_goto('admin/config/regional/language');
+ }
+
+ if (language_default('language') == $langcode) {
+ drupal_set_message(t('The default language cannot be deleted.'));
+ drupal_goto('admin/config/regional/language');
+ }
+
+ // For other languages, warn user that data loss is ahead.
+ $languages = language_list();
+
+ if (!isset($languages[$langcode])) {
+ drupal_not_found();
+ drupal_exit();
+ }
+ else {
+ $form['langcode'] = array('#type' => 'value', '#value' => $langcode);
+ return confirm_form($form, t('Are you sure you want to delete the language %name?', array('%name' => t($languages[$langcode]->name))), 'admin/config/regional/language', t('Deleting a language will remove all interface translations associated with it, and posts in this language will be set to be language neutral. This action cannot be undone.'), t('Delete'), t('Cancel'));
+ }
+}
+
+/**
+ * Process language deletion submissions.
+ */
+function locale_languages_delete_form_submit($form, &$form_state) {
+ $languages = language_list();
+ if (isset($languages[$form_state['values']['langcode']])) {
+ // Remove translations first.
+ db_delete('locales_target')
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ cache_clear_all('locale:' . $form_state['values']['langcode'], 'cache');
+ // With no translations, this removes existing JavaScript translations file.
+ _locale_rebuild_js($form_state['values']['langcode']);
+ // Remove the language.
+ db_delete('languages')
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ db_update('node')
+ ->fields(array('language' => ''))
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ module_invoke_all('multilingual_settings_changed');
+ $variables = array('%locale' => $languages[$form_state['values']['langcode']]->name);
+ drupal_set_message(t('The language %locale has been removed.', $variables));
+ watchdog('locale', 'The language %locale has been removed.', $variables);
+ }
+
+ // Changing the language settings impacts the interface:
+ cache_clear_all('*', 'cache_page', TRUE);
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+ return;
+}
+/**
+ * @} End of "locale-language-add-edit"
+ */
+
+/**
+ * @defgroup locale-languages-negotiation Language negotiation options
+ * @{
+ */
+
+/**
+ * Setting for language negotiation options
+ */
+function locale_languages_configure_form() {
+ include_once DRUPAL_ROOT . '/includes/language.inc';
+
+ $form = array(
+ '#submit' => array('locale_languages_configure_form_submit'),
+ '#theme' => 'locale_languages_configure_form',
+ '#language_types' => language_types_configurable(),
+ '#language_types_info' => language_types_info(),
+ '#language_providers' => language_negotiation_info(),
+ );
+
+ foreach ($form['#language_types'] as $type) {
+ _locale_languages_configure_form_language_table($form, $type);
+ }
+
+ $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save settings'),
+ );
+
+ return $form;
+}
+
+/**
+ * Helper function to build a language provider table.
+ */
+function _locale_languages_configure_form_language_table(&$form, $type) {
+ $info = $form['#language_types_info'][$type];
+
+ $table_form = array(
+ '#title' => t('@type language', array('@type' => $info['name'])),
+ '#tree' => TRUE,
+ '#description' => $info['description'],
+ '#language_providers' => array(),
+ '#show_operations' => FALSE,
+ 'weight' => array('#tree' => TRUE),
+ 'enabled' => array('#tree' => TRUE),
+ );
+
+ $language_providers = $form['#language_providers'];
+ $enabled_providers = variable_get("locale_language_providers_enabled_$type", array());
+ $providers_weight = variable_get("locale_language_providers_weight_$type", array());
+
+ // Add missing data to the providers lists.
+ foreach ($language_providers as $id => $provider) {
+ if (!isset($providers_weight[$id])) {
+ $providers_weight[$id] = language_provider_weight($provider);
+ }
+ if (!isset($enabled_providers[$id])) {
+ $enabled_providers[$id] = FALSE;
+ }
+ }
+
+ // Order providers list by weight.
+ asort($providers_weight);
+
+ foreach ($providers_weight as $id => $weight) {
+ $enabled = $enabled_providers[$id];
+ $provider = $language_providers[$id];
+
+ // List the provider only if the current type is defined in its 'types' key.
+ // If it is not defined default to all the configurabe language types.
+ $types = array_flip(isset($provider['types']) ? $provider['types'] : $form['#language_types']);
+
+ if (isset($types[$type])) {
+ $table_form['#language_providers'][$id] = $provider;
+
+ $table_form['weight'][$id] = array(
+ '#type' => 'weight',
+ '#default_value' => $weight,
+ '#attributes' => array('class' => array("language-provider-weight-$type")),
+ );
+
+ $table_form['title'][$id] = array('#markup' => check_plain($provider['name']));
+
+ $table_form['enabled'][$id] = array('#type' => 'checkbox', '#default_value' => $enabled);
+ if ($id === LANGUAGE_NEGOTIATION_DEFAULT) {
+ $table_form['enabled'][$id]['#default_value'] = TRUE;
+ $table_form['enabled'][$id]['#attributes'] = array('disabled' => 'disabled');
+ }
+
+ $table_form['description'][$id] = array('#markup' => filter_xss_admin($provider['description']));
+
+ $config_op = array();
+ if (isset($provider['config'])) {
+ $config_op = array('#type' => 'link', '#title' => t('Configure'), '#href' => $provider['config']);
+ // If there is at least one operation enabled show the operation column.
+ $table_form['#show_operations'] = TRUE;
+ }
+ $table_form['operation'][$id] = $config_op;
+ }
+ }
+
+ $form[$type] = $table_form;
+}
+
+/**
+ * Theme the language configure form.
+ *
+ * @ingroup themeable
+ */
+function theme_locale_languages_configure_form($variables) {
+ $form = $variables['form'];
+ $output = '';
+
+ foreach ($form['#language_types'] as $type) {
+ $rows = array();
+ $info = $form['#language_types_info'][$type];
+ $title = '<label>' . $form[$type]['#title'] . '</label>';
+ $description = '<div class="description">' . $form[$type]['#description'] . '</div>';
+
+ foreach ($form[$type]['title'] as $id => $element) {
+ // Do not take form control structures.
+ if (is_array($element) && element_child($id)) {
+ $row = array(
+ 'data' => array(
+ '<strong>' . drupal_render($form[$type]['title'][$id]) . '</strong>',
+ drupal_render($form[$type]['description'][$id]),
+ drupal_render($form[$type]['enabled'][$id]),
+ drupal_render($form[$type]['weight'][$id]),
+ ),
+ 'class' => array('draggable'),
+ );
+ if ($form[$type]['#show_operations']) {
+ $row['data'][] = drupal_render($form[$type]['operation'][$id]);
+ }
+ $rows[] = $row;
+ }
+ }
+
+ $header = array(
+ array('data' => t('Detection method')),
+ array('data' => t('Description')),
+ array('data' => t('Enabled')),
+ array('data' => t('Weight')),
+ );
+
+ // If there is at least one operation enabled show the operation column.
+ if ($form[$type]['#show_operations']) {
+ $header[] = array('data' => t('Operations'));
+ }
+
+ $variables = array(
+ 'header' => $header,
+ 'rows' => $rows,
+ 'attributes' => array('id' => "language-negotiation-providers-$type"),
+ );
+ $table = theme('table', $variables);
+ $table .= drupal_render_children($form[$type]);
+
+ drupal_add_tabledrag("language-negotiation-providers-$type", 'order', 'sibling', "language-provider-weight-$type");
+
+ $output .= '<div class="form-item">' . $title . $description . $table . '</div>';
+ }
+
+ $output .= drupal_render_children($form);
+ return $output;
+}
+
+/**
+ * Submit handler for language negotiation settings.
+ */
+function locale_languages_configure_form_submit($form, &$form_state) {
+ $language_types = array();
+ $configurable_types = $form['#language_types'];
+
+ foreach ($configurable_types as $type) {
+ $negotiation = array();
+ $enabled_providers = $form_state['values'][$type]['enabled'];
+ $enabled_providers[LANGUAGE_NEGOTIATION_DEFAULT] = TRUE;
+ $providers_weight = $form_state['values'][$type]['weight'];
+ $language_types[$type] = TRUE;
+
+ foreach ($providers_weight as $id => $weight) {
+ if ($enabled_providers[$id]) {
+ $provider = $form[$type]['#language_providers'][$id];
+ $provider['weight'] = $weight;
+ $negotiation[$id] = $provider;
+ }
+ }
+
+ language_negotiation_set($type, $negotiation);
+ variable_set("locale_language_providers_enabled_$type", $enabled_providers);
+ variable_set("locale_language_providers_weight_$type", $providers_weight);
+ }
+
+ // Save non-configurable language types negotiation.
+ $language_types_info = language_types_info();
+ $defined_providers = $form['#language_providers'];
+ foreach ($language_types_info as $type => $info) {
+ if (isset($info['fixed'])) {
+ $language_types[$type] = FALSE;
+ $negotiation = array();
+ foreach ($info['fixed'] as $id) {
+ if (isset($defined_providers[$id])) {
+ $negotiation[$id] = $defined_providers[$id];
+ }
+ }
+ language_negotiation_set($type, $negotiation);
+ }
+ }
+
+ // Save language types.
+ variable_set('language_types', $language_types);
+
+ $form_state['redirect'] = 'admin/config/regional/language';
+ drupal_set_message(t('Language negotiation configuration saved.'));
+}
+
+/**
+ * The URL language provider configuration form.
+ */
+function locale_language_providers_url_form() {
+ $form = array();
+
+ $form['locale_language_negotiation_url_part'] = array(
+ '#title' => t('The part of the URL that will determine the language.'),
+ '#type' => 'radios',
+ '#options' => array(
+ LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX => t('Path prefix'),
+ LOCALE_LANGUAGE_NEGOTIATION_URL_DOMAIN => t('Domain'),
+ ),
+ '#default_value' => variable_get('locale_language_negotiation_url_part', LOCALE_LANGUAGE_NEGOTIATION_URL_PREFIX),
+ );
+
+ $form['#redirect'] = 'admin/config/regional/language/configure';
+
+ return system_settings_form($form);
+}
+
+/**
+ * The URL language provider configuration form.
+ */
+function locale_language_providers_session_form() {
+ $form = array();
+
+ $form['locale_language_negotiation_session_param'] = array(
+ '#title' => t('Request/session parameter'),
+ '#type' => 'textfield',
+ '#default_value' => variable_get('locale_language_negotiation_session_param', 'language'),
+ '#description' => t('Name of the request/session parameter used to determine the desired language.'),
+ );
+
+ $form['#redirect'] = 'admin/config/regional/language/configure';
+
+ return system_settings_form($form);
+}
+
+/**
+ * @} End of "locale-languages-negotiation"
+ */
+
+/**
+ * @defgroup locale-translate-overview Translation overview screen.
+ * @{
+ */
+
+/**
+ * Overview screen for translations.
+ */
+function locale_translate_overview_screen() {
+ drupal_static_reset('language_list');
+ $languages = language_list('language');
+ $groups = module_invoke_all('locale', 'groups');
+
+ // Build headers with all groups in order.
+ $headers = array_merge(array(t('Language')), array_values($groups));
+
+ // Collect summaries of all source strings in all groups.
+ $sums = db_query("SELECT COUNT(*) AS strings, textgroup FROM {locales_source} GROUP BY textgroup");
+ $groupsums = array();
+ foreach ($sums as $group) {
+ $groupsums[$group->textgroup] = $group->strings;
+ }
+
+ // Set up overview table with default values, ensuring common order for values.
+ $rows = array();
+ foreach ($languages as $langcode => $language) {
+ $rows[$langcode] = array('name' => ($langcode == 'en' ? t('English (built-in)') : t($language->name)));
+ foreach ($groups as $group => $name) {
+ $rows[$langcode][$group] = ($langcode == 'en' ? t('n/a') : '0/' . (isset($groupsums[$group]) ? $groupsums[$group] : 0) . ' (0%)');
+ }
+ }
+
+ // Languages with at least one record in the locale table.
+ $translations = db_query("SELECT COUNT(*) AS translation, t.language, s.textgroup FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY textgroup, language");
+ foreach ($translations as $data) {
+ $ratio = (!empty($groupsums[$data->textgroup]) && $data->translation > 0) ? round(($data->translation/$groupsums[$data->textgroup]) * 100.0, 2) : 0;
+ $rows[$data->language][$data->textgroup] = $data->translation . '/' . $groupsums[$data->textgroup] . " ($ratio%)";
+ }
+
+ return theme('table', array('header' => $headers, 'rows' => $rows));
+}
+/**
+ * @} End of "locale-translate-overview"
+ */
+
+/**
+ * @defgroup locale-translate-seek Translation search screen.
+ * @{
+ */
+
+/**
+ * String search screen.
+ */
+function locale_translate_seek_screen() {
+ // Add CSS.
+ drupal_add_css(drupal_get_path('module', 'locale') . '/locale.css', array('preprocess' => FALSE));
+
+ $output = drupal_render(drupal_get_form('locale_translation_filter_form'));
+ $output .= _locale_translate_seek();
+ return $output;
+}
+
+/**
+ * List locale translation filters that can be applied.
+ */
+function locale_translation_filters() {
+ $filters = array();
+
+ // Get all languages, except English
+ drupal_static_reset('language_list');
+ $languages = locale_language_list('name');
+ unset($languages['en']);
+
+ $filters['string'] = array(
+ 'title' => t('String contains'),
+ 'description' => t('Leave blank to show all strings. The search is case sensitive.'),
+ );
+
+ $filters['language'] = array(
+ 'title' => t('Language'),
+ 'options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages),
+ );
+
+ $filters['translation'] = array(
+ 'title' => t('Search in'),
+ 'options' => array('all' => t('Both translated and untranslated strings'), 'translated' => t('Only translated strings'), 'untranslated' => t('Only untranslated strings')),
+ );
+
+ $groups = module_invoke_all('locale', 'groups');
+ $filters['group'] = array(
+ 'title' => t('Limit search to'),
+ 'options' => array_merge(array('all' => t('All text groups')), $groups),
+ );
+
+ return $filters;
+}
+
+/**
+ * Return form for locale translation filters.
+ *
+ * @ingroup forms
+ */
+function locale_translation_filter_form() {
+ $filters = locale_translation_filters();
+
+ $form['filters'] = array(
+ '#type' => 'fieldset',
+ '#title' => t('Filter translatable strings'),
+ '#collapsible' => TRUE,
+ '#collapsed' => FALSE,
+ );
+ foreach ($filters as $key => $filter) {
+ // Special case for 'string' filter.
+ if ($key == 'string') {
+ $form['filters']['status']['string'] = array(
+ '#type' => 'textfield',
+ '#title' => $filter['title'],
+ '#description' => $filter['description'],
+ );
+ }
+ else {
+ $form['filters']['status'][$key] = array(
+ '#title' => $filter['title'],
+ '#type' => 'select',
+ '#multiple' => FALSE,
+ '#size' => 0,
+ '#options' => $filter['options'],
+ );
+ }
+ if (!empty($_SESSION['locale_translation_filter'][$key])) {
+ $form['filters']['status'][$key]['#default_value'] = $_SESSION['locale_translation_filter'][$key];
+ }
+ }
+
+ $form['filters']['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions', 'container-inline')));
+ $form['filters']['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Filter'),
+ );
+ if (!empty($_SESSION['locale_translation_filter'])) {
+ $form['filters']['actions']['reset'] = array(
+ '#type' => 'submit',
+ '#value' => t('Reset')
+ );
+ }
+
+ return $form;
+}
+
+/**
+ * Validate result from locale translation filter form.
+ */
+function locale_translation_filter_form_validate($form, &$form_state) {
+ if ($form_state['values']['op'] == t('Filter') && empty($form_state['values']['language']) && empty($form_state['values']['group'])) {
+ form_set_error('type', t('You must select something to filter by.'));
+ }
+}
+
+/**
+ * Process result from locale translation filter form.
+ */
+function locale_translation_filter_form_submit($form, &$form_state) {
+ $op = $form_state['values']['op'];
+ $filters = locale_translation_filters();
+ switch ($op) {
+ case t('Filter'):
+ foreach ($filters as $name => $filter) {
+ if (isset($form_state['values'][$name])) {
+ $_SESSION['locale_translation_filter'][$name] = $form_state['values'][$name];
+ }
+ }
+ break;
+ case t('Reset'):
+ $_SESSION['locale_translation_filter'] = array();
+ break;
+ }
+
+ $form_state['redirect'] = 'admin/config/regional/translate/translate';
+}
+
+/**
+ * @} End of "locale-translate-seek"
+ */
+
+/**
+ * @defgroup locale-translate-import Translation import screen.
+ * @{
+ */
+
+/**
+ * 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']['group'] = array('#type' => 'radios',
+ '#title' => t('Text group'),
+ '#default_value' => 'default',
+ '#options' => module_invoke_all('locale', 'groups'),
+ '#description' => t('Imported translations will be added to this text group.'),
+ );
+ $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'),
+ LOCALE_IMPORT_KEEP => t('Existing strings 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) {
+ // Ensure we have the file uploaded
+ if ($file = file_save_upload('file')) {
+
+ // 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'], $form_state['values']['group']) == 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;
+}
+/**
+ * @} End of "locale-translate-import"
+ */
+
+/**
+ * @defgroup locale-translate-export Translation export screen.
+ * @{
+ */
+
+/**
+ * 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)) {
+ $output = drupal_render(drupal_get_form('locale_translate_export_po_form', $names));
+ }
+ $output .= drupal_render(drupal_get_form('locale_translate_export_pot_form'));
+ 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'] = array('#type' => 'fieldset',
+ '#title' => t('Export translation'),
+ '#collapsible' => TRUE,
+ );
+ $form['export']['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['export']['group'] = array('#type' => 'radios',
+ '#title' => t('Text group'),
+ '#default_value' => 'default',
+ '#options' => module_invoke_all('locale', 'groups'),
+ );
+ $form['export']['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'] = array('#type' => 'fieldset',
+ '#title' => t('Export template'),
+ '#collapsible' => TRUE,
+ '#description' => t('Generate a Gettext Portable Object Template (<em>.pot</em>) file with all strings from the Drupal locale database.'),
+ );
+ $form['export']['group'] = array('#type' => 'radios',
+ '#title' => t('Text group'),
+ '#default_value' => 'default',
+ '#options' => module_invoke_all('locale', 'groups'),
+ );
+ $form['export']['submit'] = array('#type' => 'submit', '#value' => t('Export'));
+ // Reuse PO export submission callback.
+ $form['#submit'][] = 'locale_translate_export_po_form_submit';
+ $form['#validate'][] = 'locale_translate_export_po_form_validate';
+ 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, $form_state['values']['group'])));
+}
+/**
+ * @} End of "locale-translate-export"
+ */
+
+/**
+ * @defgroup locale-translate-edit Translation text editing
+ * @{
+ */
+
+/**
+ * User interface for string editing.
+ */
+function locale_translate_edit_form($form, &$form_state, $lid) {
+ // Fetch source string, if possible.
+ $source = db_query('SELECT source, context, textgroup, location FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject();
+ if (!$source) {
+ drupal_set_message(t('String not found.'), 'error');
+ drupal_goto('admin/config/regional/translate/translate');
+ }
+
+ // Add original text to the top and some values for form altering.
+ $form['original'] = array(
+ '#type' => 'item',
+ '#title' => t('Original text'),
+ '#markup' => check_plain(wordwrap($source->source, 0)),
+ );
+ if (!empty($source->context)) {
+ $form['context'] = array(
+ '#type' => 'item',
+ '#title' => t('Context'),
+ '#markup' => check_plain($source->context),
+ );
+ }
+ $form['lid'] = array(
+ '#type' => 'value',
+ '#value' => $lid
+ );
+ $form['textgroup'] = array(
+ '#type' => 'value',
+ '#value' => $source->textgroup,
+ );
+ $form['location'] = array(
+ '#type' => 'value',
+ '#value' => $source->location
+ );
+
+ // Include default form controls with empty values for all languages.
+ // This ensures that the languages are always in the same order in forms.
+ $languages = language_list();
+ $default = language_default();
+ // We don't need the default language value, that value is in $source.
+ $omit = $source->textgroup == 'default' ? 'en' : $default->language;
+ unset($languages[($omit)]);
+ $form['translations'] = array('#tree' => TRUE);
+ // Approximate the number of rows to use in the default textarea.
+ $rows = min(ceil(str_word_count($source->source) / 12), 10);
+ foreach ($languages as $langcode => $language) {
+ $form['translations'][$langcode] = array(
+ '#type' => 'textarea',
+ '#title' => t($language->name),
+ '#rows' => $rows,
+ '#default_value' => '',
+ );
+ }
+
+ // Fetch translations and fill in default values in the form.
+ $result = db_query("SELECT DISTINCT translation, language FROM {locales_target} WHERE lid = :lid AND language <> :omit", array(':lid' => $lid, ':omit' => $omit));
+ foreach ($result as $translation) {
+ $form['translations'][$translation->language]['#default_value'] = $translation->translation;
+ }
+
+ $form['submit'] = array('#type' => 'submit', '#value' => t('Save translations'));
+ return $form;
+}
+
+/**
+ * Validate string editing form submissions.
+ */
+function locale_translate_edit_form_validate($form, &$form_state) {
+ // Locale string check is needed for default textgroup only.
+ $safe_check_needed = $form_state['values']['textgroup'] == 'default';
+ foreach ($form_state['values']['translations'] as $key => $value) {
+ if ($safe_check_needed && !locale_string_is_safe($value)) {
+ form_set_error('translations', t('The submitted string contains disallowed HTML: %string', array('%string' => $value)));
+ watchdog('locale', 'Attempted submission of a translation string with disallowed HTML: %string', array('%string' => $value), WATCHDOG_WARNING);
+ }
+ }
+}
+
+/**
+ * Process string editing form submissions.
+ *
+ * Saves all translations of one string submitted from a form.
+ */
+function locale_translate_edit_form_submit($form, &$form_state) {
+ $lid = $form_state['values']['lid'];
+ foreach ($form_state['values']['translations'] as $key => $value) {
+ $translation = db_query("SELECT translation FROM {locales_target} WHERE lid = :lid AND language = :language", array(':lid' => $lid, ':language' => $key))->fetchField();
+ if (!empty($value)) {
+ // Only update or insert if we have a value to use.
+ if (!empty($translation)) {
+ db_update('locales_target')
+ ->fields(array(
+ 'translation' => $value,
+ ))
+ ->condition('lid', $lid)
+ ->condition('language', $key)
+ ->execute();
+ }
+ else {
+ db_insert('locales_target')
+ ->fields(array(
+ 'lid' => $lid,
+ 'translation' => $value,
+ 'language' => $key,
+ ))
+ ->execute();
+ }
+ }
+ elseif (!empty($translation)) {
+ // Empty translation entered: remove existing entry from database.
+ db_delete('locales_target')
+ ->condition('lid', $lid)
+ ->condition('language', $key)
+ ->execute();
+ }
+
+ // Force JavaScript translation file recreation for this language.
+ _locale_invalidate_js($key);
+ }
+
+ drupal_set_message(t('The string has been saved.'));
+
+ // Clear locale cache.
+ _locale_invalidate_js();
+ cache_clear_all('locale:', 'cache', TRUE);
+
+ $form_state['redirect'] = 'admin/config/regional/translate/translate';
+ return;
+}
+/**
+ * @} End of "locale-translate-edit"
+ */
+
+/**
+ * @defgroup locale-translate-delete Translation delete interface.
+ * @{
+ */
+
+/**
+ * String deletion confirmation page.
+ */
+function locale_translate_delete_page($lid) {
+ if ($source = db_query('SELECT lid, source FROM {locales_source} WHERE lid = :lid', array(':lid' => $lid))->fetchObject()) {
+ return drupal_get_form('locale_translate_delete_form', $source);
+ }
+ else {
+ return drupal_not_found();
+ }
+}
+
+/**
+ * User interface for the string deletion confirmation screen.
+ */
+function locale_translate_delete_form($form, &$form_state, $source) {
+ $form['lid'] = array('#type' => 'value', '#value' => $source->lid);
+ return confirm_form($form, t('Are you sure you want to delete the string "%source"?', array('%source' => $source->source)), 'admin/config/regional/translate/translate', t('Deleting the string will remove all translations of this string in all languages. This action cannot be undone.'), t('Delete'), t('Cancel'));
+}
+
+/**
+ * Process string deletion submissions.
+ */
+function locale_translate_delete_form_submit($form, &$form_state) {
+ db_delete('locales_source')
+ ->condition('lid', $form_state['values']['lid'])
+ ->execute();
+ db_delete('locales_target')
+ ->condition('lid', $form_state['values']['lid'])
+ ->execute();
+ // Force JavaScript translation file recreation for all languages.
+ _locale_invalidate_js();
+ cache_clear_all('locale:', 'cache', TRUE);
+ drupal_set_message(t('The string has been removed.'));
+ $form_state['redirect'] = 'admin/config/regional/translate/translate';
+}
+/**
+ * @} End of "locale-translate-delete"
+ */
+
+/**
+ * Theme locale date format form.
+ *
+ * @ingroup themeable
+ */
+function theme_locale_date_format_form($variables) {
+ $form = $variables['form'];
+ $header = array(
+ t('Date type'),
+ t('Format'),
+ );
+
+ foreach (element_children($form['date_formats']) as $key) {
+ $row = array();
+ $row[] = $form['date_formats'][$key]['#title'];
+ unset($form['date_formats'][$key]['#title']);
+ $row[] = array('data' => drupal_render($form['date_formats'][$key]));
+ $rows[] = $row;
+ }
+
+ $output = drupal_render($form['language']);
+ $output .= theme('table', array('header' => $header, 'rows' => $rows));
+ $output .= drupal_render_children($form);
+
+ return $output;
+}
+
+/**
+ * Display edit date format links for each language.
+ */
+function locale_date_format_language_overview_page() {
+ $header = array(
+ t('Language'),
+ array('data' => t('Operations'), 'colspan' => '2'),
+ );
+
+ // Get list of languages.
+ $languages = locale_language_list('native');
+
+ foreach ($languages as $langcode => $info) {
+ $row = array();
+ $row[] = $languages[$langcode];
+ $row[] = l(t('edit'), 'admin/config/regional/date-time/locale/' . $langcode . '/edit');
+ $row[] = l(t('reset'), 'admin/config/regional/date-time/locale/' . $langcode . '/reset');
+ $rows[] = $row;
+ }
+
+ return theme('table', array('header' => $header, 'rows' => $rows));
+}
+
+/**
+ * Provide date localization configuration options to users.
+ */
+function locale_date_format_form($form, &$form_state, $langcode) {
+ $languages = locale_language_list('native');
+ $language_name = $languages[$langcode];
+
+ // Display the current language name.
+ $form['language'] = array(
+ '#type' => 'item',
+ '#title' => t('Language'),
+ '#markup' => check_plain($language_name),
+ '#weight' => -10,
+ );
+ $form['langcode'] = array(
+ '#type' => 'value',
+ '#value' => $langcode,
+ );
+
+ // Get list of date format types.
+ $types = system_get_date_types();
+
+ // Get list of available formats.
+ $formats = system_get_date_formats();
+ $choices = array();
+ foreach ($formats as $type => $list) {
+ foreach ($list as $f => $format) {
+ $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
+ }
+ }
+
+ // Get configured formats for each language.
+ $locale_formats = system_date_format_locale($langcode);
+ // Display a form field for each format type.
+ foreach ($types as $type => $type_info) {
+ if (!empty($locale_formats) && in_array($type, array_keys($locale_formats))) {
+ $default = $locale_formats[$type];
+ }
+ else {
+ $default = variable_get('date_format_' . $type, array_shift(array_keys($formats)));
+ }
+
+ // Show date format select list.
+ $form['date_formats']['date_format_' . $type] = array(
+ '#type' => 'select',
+ '#title' => check_plain($type_info['title']),
+ '#attributes' => array('class' => array('date-format')),
+ '#default_value' => (isset($choices[$default]) ? $default : 'custom'),
+ '#options' => $choices,
+ );
+ }
+
+ $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
+ $form['actions']['submit'] = array(
+ '#type' => 'submit',
+ '#value' => t('Save configuration'),
+ );
+
+ return $form;
+}
+
+/**
+ * Submit handler for configuring localized date formats on the locale_date_format_form.
+ */
+function locale_date_format_form_submit($form, &$form_state) {
+ include_once DRUPAL_ROOT . '/includes/locale.inc';
+ $langcode = $form_state['values']['langcode'];
+
+ // Get list of date format types.
+ $types = system_get_date_types();
+ foreach ($types as $type => $type_info) {
+ $format = $form_state['values']['date_format_' . $type];
+ if ($format == 'custom') {
+ $format = $form_state['values']['date_format_' . $type . '_custom'];
+ }
+ locale_date_format_save($langcode, $type, $format);
+ }
+ drupal_set_message(t('Configuration saved.'));
+ $form_state['redirect'] = 'admin/config/regional/date-time/locale';
+}
+
+/**
+ * Reset locale specific date formats to the global defaults.
+ *
+ * @param $langcode
+ * Language code, e.g. 'en'.
+ */
+function locale_date_format_reset_form($form, &$form_state, $langcode) {
+ $form['langcode'] = array('#type' => 'value', '#value' => $langcode);
+ $languages = language_list();
+ return confirm_form($form,
+ t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' => $languages[$langcode]->name)),
+ 'admin/config/regional/date-time/locale',
+ t('Resetting will remove all localized date formats for this language. This action cannot be undone.'),
+ t('Reset'), t('Cancel'));
+}
+
+/**
+ * Reset date formats for a specific language to global defaults.
+ */
+function locale_date_format_reset_form_submit($form, &$form_state) {
+ db_delete('date_format_locale')
+ ->condition('language', $form_state['values']['langcode'])
+ ->execute();
+ $form_state['redirect'] = 'admin/config/regional/date-time/locale';
+}
diff --git a/modules/locale/locale.info b/modules/locale/locale.info
index 3cae81c78..181f0a191 100644
--- a/modules/locale/locale.info
+++ b/modules/locale/locale.info
@@ -7,5 +7,6 @@ core = 7.x
files[] = locale.module
files[] = locale.install
files[] = locale.field.inc
+files[] = locale.admin.inc
files[] = locale.test
configure = admin/config/regional/language
diff --git a/modules/locale/locale.module b/modules/locale/locale.module
index 1d976a9f0..dff3570aa 100644
--- a/modules/locale/locale.module
+++ b/modules/locale/locale.module
@@ -108,8 +108,7 @@ function locale_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_languages_overview_form'),
'access arguments' => array('administer languages'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/language/overview'] = array(
'title' => 'List',
@@ -122,8 +121,7 @@ function locale_menu() {
'access arguments' => array('administer languages'),
'weight' => 5,
'type' => MENU_LOCAL_ACTION,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/language/configure'] = array(
'title' => 'Configure',
@@ -131,8 +129,7 @@ function locale_menu() {
'page arguments' => array('locale_languages_configure_form'),
'access arguments' => array('administer languages'),
'weight' => 10,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
'type' => MENU_LOCAL_TASK,
);
$items['admin/config/regional/language/configure/url'] = array(
@@ -140,24 +137,21 @@ function locale_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_language_providers_url_form'),
'access arguments' => array('administer languages'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/language/configure/session'] = array(
'title' => 'Session language provider configuration',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_language_providers_session_form'),
'access arguments' => array('administer languages'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/language/edit/%'] = array(
'title' => 'Edit language',
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_languages_edit_form', 5),
'access arguments' => array('administer languages'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
'type' => MENU_CALLBACK,
);
$items['admin/config/regional/language/delete/%'] = array(
@@ -165,8 +159,7 @@ function locale_menu() {
'page callback' => 'drupal_get_form',
'page arguments' => array('locale_languages_delete_form', 5),
'access arguments' => array('administer languages'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
'type' => MENU_CALLBACK,
);
@@ -174,11 +167,9 @@ function locale_menu() {
$items['admin/config/regional/translate'] = array(
'title' => 'Translate interface',
'description' => 'Translate the built in interface and optionally other text.',
- 'page callback' => 'locale_inc_callback',
- 'page arguments' => array('locale_translate_overview_screen'), // not a form, just a table
+ 'page callback' => 'locale_translate_overview_screen',
'access arguments' => array('translate interface'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/translate/overview'] = array(
'title' => 'Overview',
@@ -191,8 +182,7 @@ function locale_menu() {
'type' => MENU_LOCAL_TASK,
'page callback' => 'locale_translate_seek_screen', // search results and form concatenated
'access arguments' => array('translate interface'),
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/translate/import'] = array(
'title' => 'Import',
@@ -201,8 +191,7 @@ function locale_menu() {
'access arguments' => array('translate interface'),
'weight' => 20,
'type' => MENU_LOCAL_TASK,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/translate/export'] = array(
'title' => 'Export',
@@ -210,8 +199,7 @@ function locale_menu() {
'access arguments' => array('translate interface'),
'weight' => 30,
'type' => MENU_LOCAL_TASK,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/translate/edit/%'] = array(
'title' => 'Edit string',
@@ -219,8 +207,7 @@ function locale_menu() {
'page arguments' => array('locale_translate_edit_form', 5),
'access arguments' => array('translate interface'),
'type' => MENU_CALLBACK,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/translate/delete/%'] = array(
'title' => 'Delete string',
@@ -228,8 +215,7 @@ function locale_menu() {
'page arguments' => array(5),
'access arguments' => array('translate interface'),
'type' => MENU_CALLBACK,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
// Localize date formats.
@@ -240,8 +226,7 @@ function locale_menu() {
'access arguments' => array('administer site configuration'),
'type' => MENU_LOCAL_TASK,
'weight' => -8,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/date-time/locale/%/edit'] = array(
'title' => 'Localize date formats',
@@ -250,8 +235,7 @@ function locale_menu() {
'page arguments' => array('locale_date_format_form', 5),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
$items['admin/config/regional/date-time/locale/%/reset'] = array(
'title' => 'Reset date formats',
@@ -260,8 +244,7 @@ function locale_menu() {
'page arguments' => array('locale_date_format_reset_form', 5),
'access arguments' => array('administer site configuration'),
'type' => MENU_CALLBACK,
- 'file' => 'locale.inc',
- 'file path' => 'includes',
+ 'file' => 'locale.admin.inc',
);
return $items;
@@ -557,7 +540,7 @@ function locale_language_negotiation_info() {
$providers[LOCALE_LANGUAGE_NEGOTIATION_BROWSER] = array(
'callbacks' => array('language' => 'locale_language_from_browser'),
- 'name' => $file,
+ 'file' => $file,
'weight' => -2,
'cache' => CACHE_DISABLED,
'name' => t('Browser'),
@@ -611,7 +594,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL, $reset = FALS
$langcode = isset($langcode) ? $langcode : $language->language;
- // Store database cached translations in a static variable. Only build the
+ // Store database cached translations in a static variable. Only build the
// cache after $language has been set to avoid an unnecessary cache rebuild.
if (!isset($locale_t[$langcode]) && isset($language)) {
$locale_t[$langcode] = array();
@@ -900,163 +883,6 @@ function locale_block_view($type) {
}
/**
- * Theme locale date format form.
- *
- * @ingroup themeable
- */
-function theme_locale_date_format_form($variables) {
- $form = $variables['form'];
- $header = array(
- t('Date type'),
- t('Format'),
- );
-
- foreach (element_children($form['date_formats']) as $key) {
- $row = array();
- $row[] = $form['date_formats'][$key]['#title'];
- unset($form['date_formats'][$key]['#title']);
- $row[] = array('data' => drupal_render($form['date_formats'][$key]));
- $rows[] = $row;
- }
-
- $output = drupal_render($form['language']);
- $output .= theme('table', array('header' => $header, 'rows' => $rows));
- $output .= drupal_render_children($form);
-
- return $output;
-}
-
-/**
- * Display edit date format links for each language.
- */
-function locale_date_format_language_overview_page() {
- $header = array(
- t('Language'),
- array('data' => t('Operations'), 'colspan' => '2'),
- );
-
- // Get list of languages.
- $languages = locale_language_list('native');
-
- foreach ($languages as $langcode => $info) {
- $row = array();
- $row[] = $languages[$langcode];
- $row[] = l(t('edit'), 'admin/config/regional/date-time/locale/' . $langcode . '/edit');
- $row[] = l(t('reset'), 'admin/config/regional/date-time/locale/' . $langcode . '/reset');
- $rows[] = $row;
- }
-
- return theme('table', array('header' => $header, 'rows' => $rows));
-}
-
-/**
- * Provide date localization configuration options to users.
- */
-function locale_date_format_form($form, &$form_state, $langcode) {
- $languages = locale_language_list('native');
- $language_name = $languages[$langcode];
-
- // Display the current language name.
- $form['language'] = array(
- '#type' => 'item',
- '#title' => t('Language'),
- '#markup' => check_plain($language_name),
- '#weight' => -10,
- );
- $form['langcode'] = array(
- '#type' => 'value',
- '#value' => $langcode,
- );
-
- // Get list of date format types.
- $types = system_get_date_types();
-
- // Get list of available formats.
- $formats = system_get_date_formats();
- $choices = array();
- foreach ($formats as $type => $list) {
- foreach ($list as $f => $format) {
- $choices[$f] = format_date(REQUEST_TIME, 'custom', $f);
- }
- }
-
- // Get configured formats for each language.
- $locale_formats = system_date_format_locale($langcode);
- // Display a form field for each format type.
- foreach ($types as $type => $type_info) {
- if (!empty($locale_formats) && in_array($type, array_keys($locale_formats))) {
- $default = $locale_formats[$type];
- }
- else {
- $default = variable_get('date_format_' . $type, array_shift(array_keys($formats)));
- }
-
- // Show date format select list.
- $form['date_formats']['date_format_' . $type] = array(
- '#type' => 'select',
- '#title' => check_plain($type_info['title']),
- '#attributes' => array('class' => array('date-format')),
- '#default_value' => (isset($choices[$default]) ? $default : 'custom'),
- '#options' => $choices,
- );
- }
-
- $form['actions'] = array('#type' => 'container', '#attributes' => array('class' => array('form-actions')));
- $form['actions']['submit'] = array(
- '#type' => 'submit',
- '#value' => t('Save configuration'),
- );
-
- return $form;
-}
-
-/**
- * Submit handler for configuring localized date formats on the locale_date_format_form.
- */
-function locale_date_format_form_submit($form, &$form_state) {
- include_once DRUPAL_ROOT . '/includes/locale.inc';
- $langcode = $form_state['values']['langcode'];
-
- // Get list of date format types.
- $types = system_get_date_types();
- foreach ($types as $type => $type_info) {
- $format = $form_state['values']['date_format_' . $type];
- if ($format == 'custom') {
- $format = $form_state['values']['date_format_' . $type . '_custom'];
- }
- locale_date_format_save($langcode, $type, $format);
- }
- drupal_set_message(t('Configuration saved.'));
- $form_state['redirect'] = 'admin/config/regional/date-time/locale';
-}
-
-/**
- * Reset locale specific date formats to the global defaults.
- *
- * @param $langcode
- * Language code, e.g. 'en'.
- */
-function locale_date_format_reset_form($form, &$form_state, $langcode) {
- $form['langcode'] = array('#type' => 'value', '#value' => $langcode);
- $languages = language_list();
- return confirm_form($form,
- t('Are you sure you want to reset the date formats for %language to the global defaults?', array('%language' => $languages[$langcode]->name)),
- 'admin/config/regional/date-time/locale',
- t('Resetting will remove all localized date formats for this language. This action cannot be undone.'),
- t('Reset'), t('Cancel'));
-}
-
-/**
- * Reset date formats for a specific language to global defaults.
- */
-function locale_date_format_reset_form_submit($form, &$form_state) {
- db_delete('date_format_locale')
- ->condition('language', $form_state['values']['langcode'])
- ->execute();
- $form_state['redirect'] = 'admin/config/regional/date-time/locale';
-}
-
-/**
* Implements hook_url_outbound_alter().
*
* Rewrite outbound URLs with language based prefixes.