# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: includes/common.inc --- includes/common.inc Base (1.799) +++ includes/common.inc Locally Modified (Based On 1.799) @@ -3005,10 +3005,6 @@ 'pager_link' => array( 'arguments' => array('text' => NULL, 'page_new' => NULL, 'element' => NULL, 'parameters' => array(), 'attributes' => array()), ), - // from locale.inc - 'locale_admin_manage_screen' => array( - 'arguments' => array('form' => NULL), - ), // from menu.inc 'menu_item_link' => array( 'arguments' => array('item' => NULL), Index: modules/locale/locale.admin.inc --- modules/locale/locale.admin.inc No Base Revision +++ modules/locale/locale.admin.inc Locally New @@ -0,0 +1,867 @@ + TRUE); + foreach ($languages as $langcode => $language) { + + $options[$langcode] = ''; + if ($language->enabled) { + $enabled[] = $langcode; + } + $form['weight'][$langcode] = array( + '#type' => 'weight', + '#default_value' => $language->weight + ); + $form['name'][$langcode] = array('#value' => check_plain($language->name)); + $form['native'][$langcode] = array('#value' => check_plain($language->native)); + $form['direction'][$langcode] = array('#value' => ($language->direction == LANGUAGE_RTL ? 'Right to left' : '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['submit'] = array('#type' => 'submit', '#value' => t('Save configuration')); + $form['#theme'] = 'locale_languages_overview_form'; + + return $form; +} + +/** + * Theme the language overview form. + * + * @ingroup themeable + */ +function theme_locale_languages_overview_form($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( + array('data' => drupal_render($form['enabled'][$key]), 'align' => 'center'), + check_plain($key), + ''. drupal_render($form['name'][$key]) .'', + drupal_render($form['native'][$key]), + drupal_render($form['direction'][$key]), + drupal_render($form['site_default'][$key]), + drupal_render($form['weight'][$key]), + l(t('edit'), 'admin/settings/language/edit/'. $key) . (($key != 'en' && $key != $default->language) ? ' '. l(t('delete'), 'admin/settings/language/delete/'. $key) : '') + ); + } + } + $header = array(array('data' => t('Enabled')), array('data' => t('Code')), array('data' => t('English name')), array('data' => t('Native name')), array('data' => t('Direction')), array('data' => t('Default')), array('data' => t('Weight')), array('data' => t('Operations'))); + $output = theme('table', $header, $rows); + $output .= drupal_render($form); + + 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_query("UPDATE {languages} SET enabled = %d, weight = %d WHERE language = '%s'", $language->enabled, $language->weight, $langcode); + $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); + + $form_state['redirect'] = 'admin/settings/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() { + $output = drupal_get_form('locale_languages_predefined_form'); + $output .= drupal_get_form('locale_languages_custom_form'); + return $output; +} + +/** + * Predefined language setup form. + */ +function locale_languages_predefined_form() { + $predefined = _locale_prepare_predefined_list(); + $form = array(); + $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 Add language button. (Use the Custom language options if your desired language does not appear in this list.)'), + ); + $form['language list']['submit'] = array('#type' => 'submit', '#value' => t('Add language')); + return $form; +} + +/** + * Custom language addition form. + */ +function locale_languages_custom_form() { + $form = array(); + $form['custom language'] = array('#type' => 'fieldset', + '#title' => t('Custom language'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + ); + _locale_languages_common_controls($form['custom language']); + $form['custom language']['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_state, $langcode) { + if ($language = db_fetch_object(db_query("SELECT * FROM {languages} WHERE language = '%s'", $langcode))) { + $form = array(); + _locale_languages_common_controls($form, $language); + $form['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(); + } +} + +/** + * 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'), + '#value' => $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('RFC 4646 compliant language identifier. Language codes typically use a country code, and optionally, a script or regional variant name. Examples: "en", "en-US" and "zh-Hant".', 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 Path prefix only or Path prefix with language fallback, 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. Modifying this value will break existing URLs and should be used with caution in a production environment. Example: Specifying "deutsch" as the path prefix for German results in URLs in the form "www.example.com/deutsch/node".') + ); + $form['domain'] = array('#type' => 'textfield', + '#title' => t('Language domain'), + '#maxlength' => 64, + '#default_value' => @$language->domain, + '#description' => t('Language-specific URL, with protocol. With language negotiation set to Domain name only, 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. This value must include a protocol as part of the string. 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.'), + ); + $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_result(db_query("SELECT COUNT(*) FROM {languages} WHERE language = '%s'", $langcode)) != 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. + $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 help screen.', array('%language' => t($form_state['values']['name']), '@locale-help' => url('admin/help/locale')))); + } + else { + // Predefined language selection. + $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 help screen.', 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); + } + + $form_state['redirect'] = 'admin/settings/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_fetch_object(db_query("SELECT language FROM {languages} WHERE domain = '%s' AND language != '%s'", $form_state['values']['domain'], $form_state['values']['langcode']))) { + 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_fetch_object(db_query("SELECT language FROM {languages} WHERE prefix = '%s' AND language != '%s'", $form_state['values']['prefix'], $form_state['values']['langcode']))) { + 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_query("UPDATE {languages} SET name = '%s', native = '%s', domain = '%s', prefix = '%s', direction = %d WHERE language = '%s'", $form_state['values']['name'], $form_state['values']['native'], $form_state['values']['domain'], $form_state['values']['prefix'], $form_state['values']['direction'], $form_state['values']['langcode']); + $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/settings/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_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/settings/language'); + } + + if (language_default('language') == $langcode) { + drupal_set_message(t('The default language cannot be deleted.')); + drupal_goto('admin/settings/language'); + } + + // For other languages, warn user that data loss is ahead. + $languages = language_list(); + + if (!isset($languages[$langcode])) { + drupal_not_found(); + } + 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/settings/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_query("DELETE FROM {locales_target} WHERE language = '%s'", $form_state['values']['langcode']); + 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_query("DELETE FROM {languages} WHERE language = '%s'", $form_state['values']['langcode']); + db_query("UPDATE {node} SET language = '' WHERE language = '%s'", $form_state['values']['langcode']); + $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/settings/language'; + return; +} +/** + * @} End of "locale-language-add-edit" + */ + +/** + * @defgroup locale-languages-negotiation Language negotiation options screen + * @{ + */ + +/** + * Setting for language negotiation options + */ +function locale_languages_configure_form() { + $form['language_negotiation'] = array( + '#title' => t('Language negotiation'), + '#type' => 'radios', + '#options' => array( + LANGUAGE_NEGOTIATION_NONE => t('None.'), + LANGUAGE_NEGOTIATION_PATH_DEFAULT => t('Path prefix only.'), + LANGUAGE_NEGOTIATION_PATH => t('Path prefix with language fallback.'), + LANGUAGE_NEGOTIATION_DOMAIN => t('Domain name only.')), + '#default_value' => variable_get('language_negotiation', LANGUAGE_NEGOTIATION_NONE), + '#description' => t("Select the mechanism used to determine your site's presentation language. Modifying this setting may break all incoming URLs and should be used with caution in a production environment.") + ); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save settings') + ); + return $form; +} + +/** + * Submit function for language negotiation settings. + */ +function locale_languages_configure_form_submit($form, &$form_state) { + variable_set('language_negotiation', $form_state['values']['language_negotiation']); + drupal_set_message(t('Language negotiation configuration saved.')); + $form_state['redirect'] = 'admin/settings/language'; + return; +} +/** + * @} End of "locale-languages-negotiation" + */ + +/** + * @defgroup locale-translate-overview Translation overview screen. + * @{ + */ + +/** + * Overview screen for translations. + */ +function locale_translate_overview_screen() { + $languages = language_list('language', TRUE); + $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(); + while ($group = db_fetch_object($sums)) { + $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"); + while ($data = db_fetch_object($translations)) { + $ratio = (!empty($groupsums[$data->textgroup]) && $data->translation > 0) ? round(($data->translation/$groupsums[$data->textgroup])*100., 2) : 0; + $rows[$data->language][$data->textgroup] = $data->translation .'/'. $groupsums[$data->textgroup] ." ($ratio%)"; + } + + return theme('table', $headers, $rows); +} +/** + * @} End of "locale-translate-overview" + */ + +/** + * @defgroup locale-translate-seek Translation search screen. + * @{ + */ + +/** + * String search screen. + */ +function locale_translate_seek_screen() { + $output = _locale_translate_seek(); + $output .= drupal_get_form('locale_translate_seek_form'); + return $output; +} + +/** + * User interface for the string search screen. + */ +function locale_translate_seek_form() { + // Get all languages, except English + $languages = locale_language_list('name', TRUE); + unset($languages['en']); + + // Present edit form preserving previous user settings + $query = _locale_translate_seek_query(); + $form = array(); + $form['search'] = array('#type' => 'fieldset', + '#title' => t('Search'), + ); + $form['search']['string'] = array('#type' => 'textfield', + '#title' => t('String contains'), + '#default_value' => @$query['string'], + '#description' => t('Leave blank to show all strings. The search is case sensitive.'), + ); + $form['search']['language'] = array('#type' => 'radios', + '#title' => t('Language'), + '#default_value' => (!empty($query['language']) ? $query['language'] : 'all'), + '#options' => array_merge(array('all' => t('All languages'), 'en' => t('English (provided by Drupal)')), $languages), + ); + $form['search']['translation'] = array('#type' => 'radios', + '#title' => t('Search in'), + '#default_value' => (!empty($query['translation']) ? $query['translation'] : 'all'), + '#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'); + $form['search']['group'] = array('#type' => 'radios', + '#title' => t('Limit search to'), + '#default_value' => (!empty($query['group']) ? $query['group'] : 'all'), + '#options' => array_merge(array('all' => t('All text groups')), $groups), + ); + + $form['search']['submit'] = array('#type' => 'submit', '#value' => t('Search')); + $form['#redirect'] = FALSE; + + return $form; +} +/** + * @} End of "locale-translate-seek" + */ + +/** + * @defgroup locale-translate-import Translation import screen. + * @{ + */ + +/** + * User interface for the translation import screen. + */ +function locale_translate_import_form() { + // Get all languages, except English + $names = locale_language_list('name', TRUE); + unset($names['en']); + + if (!count($names)) { + $languages = _locale_prepare_predefined_list(); + $default = array_shift(array_keys($languages)); + } + else { + $languages = array( + t('Already added languages') => $names, + t('Languages not yet added') => _locale_prepare_predefined_list() + ); + $default = array_shift(array_keys($names)); + } + + $form = array(); + $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 (.po) 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' => 'overwrite', + '#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')); + $form['#attributes']['enctype'] = 'multipart/form-data'; + + 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 + $languages = language_list('language', TRUE); + $langcode = $form_state['values']['langcode']; + if (!isset($languages[$langcode])) { + $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 ($ret = _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'); + return 'admin/build/translate/import'; + } + + $form_state['redirect'] = 'admin/build/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 + $names = locale_language_list('name', TRUE); + unset($names['en']); + $output = ''; + // Offer translation export if any language is set up. + if (count($names)) { + $output = drupal_get_form('locale_translate_export_po_form', $names); + } + $output .= 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_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 (.po) 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 (.pot) 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_state, $lid) { + // Fetch source string, if possible. + $source = db_fetch_object(db_query('SELECT source, textgroup, location FROM {locales_source} WHERE lid = %d', $lid)); + if (!$source) { + drupal_set_message(t('String not found.'), 'error'); + drupal_goto('admin/build/translate/search'); + } + + // Add original text to the top and some values for form altering. + $form = array( + 'original' => array( + '#type' => 'item', + '#title' => t('Original text'), + '#value' => check_plain(wordwrap($source->source, 0)), + ), + 'lid' => array( + '#type' => 'value', + '#value' => $lid + ), + 'textgroup' => array( + '#type' => 'value', + '#value' => $source->textgroup, + ), + '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 = %d AND language != '%s'", $lid, $omit); + while ($translation = db_fetch_object($result)) { + $form['translations'][$translation->language]['#default_value'] = $translation->translation; + } + + $form['submit'] = array('#type' => 'submit', '#value' => t('Save translations')); + return $form; +} + +/** + * 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_result(db_query("SELECT translation FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $key)); + if (!empty($value)) { + // Only update or insert if we have a value to use. + if (!empty($translation)) { + db_query("UPDATE {locales_target} SET translation = '%s' WHERE lid = %d AND language = '%s'", $value, $lid, $key); + } + else { + db_query("INSERT INTO {locales_target} (lid, translation, language) VALUES (%d, '%s', '%s')", $lid, $value, $key); + } + } + elseif (!empty($translation)) { + // Empty translation entered: remove existing entry from database. + db_query("DELETE FROM {locales_target} WHERE lid = %d AND language = '%s'", $lid, $key); + } + + // Force JavaScript translation file recreation for this language. + _locale_invalidate_js($key); + } + + drupal_set_message(t('The string has been saved.')); + + // Clear locale cache. + cache_clear_all('locale:', 'cache', TRUE); + + $form_state['redirect'] = 'admin/build/translate/search'; + return; +} +/** + * @} End of "locale-translate-edit" + */ + +/** + * @defgroup locale-translate-delete Translation delete interface. + * @{ + */ + +/** + * Delete a language string. + */ +function locale_translate_delete($lid) { + db_query('DELETE FROM {locales_source} WHERE lid = %d', $lid); + db_query('DELETE FROM {locales_target} WHERE lid = %d', $lid); + // 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.')); + drupal_goto('admin/build/translate/search'); +} +/** + * @} End of "locale-translate-delete" + */ + Index: modules/locale/locale.module --- modules/locale/locale.module Base (1.223) +++ modules/locale/locale.module Locally Modified (Based On 1.223) @@ -86,42 +86,46 @@ $items['admin/settings/language'] = array( 'title' => 'Languages', 'description' => 'Configure languages for content and the user interface.', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('drupal_get_form', 'locale_languages_overview_form'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_languages_overview_form'), 'access arguments' => array('administer languages'), + 'file' => 'locale.admin.inc', ); $items['admin/settings/language/overview'] = array( 'title' => 'List', 'weight' => 0, 'type' => MENU_DEFAULT_LOCAL_TASK, + 'file' => 'locale.admin.inc', ); $items['admin/settings/language/add'] = array( 'title' => 'Add language', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('locale_languages_add_screen'), // two forms concatenated + 'page callback' => 'locale_languages_add_screen', // two forms concatenated 'access arguments' => array('administer languages'), 'weight' => 5, 'type' => MENU_LOCAL_TASK, + 'file' => 'locale.admin.inc', ); $items['admin/settings/language/configure'] = array( 'title' => 'Configure', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('drupal_get_form', 'locale_languages_configure_form'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_languages_configure_form'), 'access arguments' => array('administer languages'), 'weight' => 10, 'type' => MENU_LOCAL_TASK, + 'file' => 'locale.admin.inc', ); $items['admin/settings/language/edit/%'] = array( 'title' => 'Edit language', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('drupal_get_form', 'locale_languages_edit_form', 4), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_languages_edit_form', 4), 'access arguments' => array('administer languages'), 'type' => MENU_CALLBACK, + 'file' => 'locale.admin.inc', ); $items['admin/settings/language/delete/%'] = array( 'title' => 'Confirm', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('drupal_get_form', 'locale_languages_delete_form', 4), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_languages_delete_form', 4), 'access arguments' => array('administer languages'), 'type' => MENU_CALLBACK, ); @@ -130,9 +134,9 @@ $items['admin/build/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', // not a form, just a table 'access arguments' => array('translate interface'), + 'file' => 'locale.admin.inc', ); $items['admin/build/translate/overview'] = array( 'title' => 'Overview', @@ -143,55 +147,48 @@ 'title' => 'Search', 'weight' => 10, 'type' => MENU_LOCAL_TASK, - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('locale_translate_seek_screen'), // search results and form concatenated + 'page callback' => 'locale_translate_seek_screen', // search results and form concatenated 'access arguments' => array('translate interface'), + 'file' => 'locale.admin.inc', ); $items['admin/build/translate/import'] = array( 'title' => 'Import', 'page callback' => 'locale_inc_callback', - 'page arguments' => array('drupal_get_form', 'locale_translate_import_form'), - 'access arguments' => array('translate interface'), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_translate_import_form'), 'weight' => 20, 'type' => MENU_LOCAL_TASK, + 'file' => 'locale.admin.inc', ); $items['admin/build/translate/export'] = array( 'title' => 'Export', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('locale_translate_export_screen'), // possibly multiple forms concatenated + 'page callback' => 'locale_translate_export_screen', // possibly multiple forms concatenated 'access arguments' => array('translate interface'), 'weight' => 30, 'type' => MENU_LOCAL_TASK, + 'file' => 'locale.admin.inc', ); $items['admin/build/translate/edit/%'] = array( 'title' => 'Edit string', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('drupal_get_form', 'locale_translate_edit_form', 4), + 'page callback' => 'drupal_get_form', + 'page arguments' => array('locale_translate_edit_form', 4), 'access arguments' => array('translate interface'), 'type' => MENU_CALLBACK, + 'file' => 'locale.admin.inc', ); $items['admin/build/translate/delete/%'] = array( 'title' => 'Delete string', - 'page callback' => 'locale_inc_callback', - 'page arguments' => array('locale_translate_delete_page', 4), + 'page callback' => 'locale_translate_delete', // directly deletes, no confirmation + 'page arguments' => array(4), 'access arguments' => array('translate interface'), 'type' => MENU_CALLBACK, + 'file' => 'locale.admin.inc', ); return $items; } /** - * Wrapper function to be able to set callbacks in locale.inc - */ -function locale_inc_callback() { - $args = func_get_args(); - $function = array_shift($args); - include_once DRUPAL_ROOT . '/includes/locale.inc'; - return call_user_func_array($function, $args); -} - -/** * Implementation of hook_perm(). */ function locale_perm() {