diff --git a/includes/locale.inc b/includes/locale.inc index d0b11f8..780459b 100644 --- a/includes/locale.inc +++ b/includes/locale.inc @@ -522,11 +522,8 @@ function locale_add_language($langcode, $name = NULL, $native = NULL, $direction * @param $mode * Should existing translations be replaced LOCALE_IMPORT_KEEP or * LOCALE_IMPORT_OVERWRITE. - * @param $group - * Text group to import PO file into (eg. 'default' for interface - * translations). */ -function _locale_import_po($file, $langcode, $mode, $group = NULL) { +function _locale_import_po($file, $langcode, $mode) { // Try to allocate enough time to parse and import the data. drupal_set_time_limit(240); @@ -537,7 +534,7 @@ function _locale_import_po($file, $langcode, $mode, $group = NULL) { } // Get strings from file (returns on failure after a partial import, or on success) - $status = _locale_import_read_po('db-store', $file, $mode, $langcode, $group); + $status = _locale_import_read_po('db-store', $file, $mode, $langcode); if ($status === FALSE) { // Error messages are set in _locale_import_read_po(). return FALSE; @@ -579,11 +576,8 @@ function _locale_import_po($file, $langcode, $mode, $group = NULL) { * LOCALE_IMPORT_OVERWRITE. * @param $lang * Language code. - * @param $group - * Text group to import PO file into (eg. 'default' for interface - * translations). */ -function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = 'default') { +function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL) { // The file will get closed by PHP on returning from this function. $fd = fopen($file->uri, 'rb'); @@ -635,7 +629,7 @@ function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = } elseif (($context == 'MSGSTR') || ($context == 'MSGSTR_ARR')) { // We are currently in string token, close it out. - _locale_import_one_string($op, $current, $mode, $lang, $file, $group); + _locale_import_one_string($op, $current, $mode, $lang, $file); // Start a new entry for the comment. $current = array(); @@ -679,7 +673,7 @@ function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = if (($context == 'MSGSTR') || ($context == 'MSGSTR_ARR')) { // We are currently in a message string, close it out. - _locale_import_one_string($op, $current, $mode, $lang, $file, $group); + _locale_import_one_string($op, $current, $mode, $lang, $file); // Start a new context for the id. $current = array(); @@ -709,7 +703,7 @@ function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = if (($context == 'MSGSTR') || ($context == 'MSGSTR_ARR')) { // We are currently in a message, start a new one. - _locale_import_one_string($op, $current, $mode, $lang, $file, $group); + _locale_import_one_string($op, $current, $mode, $lang, $file); $current = array(); } elseif (!empty($current['msgctxt'])) { @@ -823,7 +817,7 @@ function _locale_import_read_po($op, $file, $mode = NULL, $lang = NULL, $group = // End of PO file, closed out the last entry. if (($context == 'MSGSTR') || ($context == 'MSGSTR_ARR')) { - _locale_import_one_string($op, $current, $mode, $lang, $file, $group); + _locale_import_one_string($op, $current, $mode, $lang, $file); } elseif ($context != 'COMMENT') { _locale_import_message('The translation file %filename ended unexpectedly at line %line.', $file, $lineno); @@ -865,11 +859,8 @@ function _locale_import_message($message, $file, $lineno = NULL) { * @param $file * Object representation of file being imported, only required when op is * 'db-store'. - * @param $group - * Text group to import PO file into (eg. 'default' for interface - * translations). */ -function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL, $group = 'default') { +function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NULL, $file = NULL) { $report = &drupal_static(__FUNCTION__, array('additions' => 0, 'updates' => 0, 'deletes' => 0, 'skips' => 0)); $header_done = &drupal_static(__FUNCTION__ . ':header_done', FALSE); $strings = &drupal_static(__FUNCTION__ . ':strings', array()); @@ -940,7 +931,7 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL if ($key == 0) { $plid = 0; } - $plid = _locale_import_one_string_db($report, $lang, isset($value['msgctxt']) ? $value['msgctxt'] : '', $english[$key], $trans, $group, $comments, $mode, $plid, $key); + $plid = _locale_import_one_string_db($report, $lang, isset($value['msgctxt']) ? $value['msgctxt'] : '', $english[$key], $trans, $comments, $mode, $plid, $key); } } @@ -948,7 +939,7 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL // A simple string to import. $english = $value['msgid']; $translation = $value['msgstr']; - _locale_import_one_string_db($report, $lang, isset($value['msgctxt']) ? $value['msgctxt'] : '', $english, $translation, $group, $comments, $mode); + _locale_import_one_string_db($report, $lang, isset($value['msgctxt']) ? $value['msgctxt'] : '', $english, $translation, $comments, $mode); } } } // end of db-store operation @@ -968,8 +959,6 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL * Source string. * @param $translation * Translation to language specified in $langcode. - * @param $textgroup - * Name of textgroup to store translation in. * @param $location * Location value to save with source string. * @param $mode @@ -982,14 +971,12 @@ function _locale_import_one_string($op, $value = NULL, $mode = NULL, $lang = NUL * @return * The string ID of the existing string modified or the new string added. */ -function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $textgroup, $location, $mode, $plid = 0, $plural = 0) { - $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context AND textgroup = :textgroup", array(':source' => $source, ':context' => $context, ':textgroup' => $textgroup))->fetchField(); +function _locale_import_one_string_db(&$report, $langcode, $context, $source, $translation, $location, $mode, $plid = 0, $plural = 0) { + $lid = db_query("SELECT lid FROM {locales_source} WHERE source = :source AND context = :context", array(':source' => $source, ':context' => $context))->fetchField(); if (!empty($translation)) { // Skip this string unless it passes a check for dangerous code. - // Text groups other than default still can contain HTML tags - // (i.e. translatable blocks). - if ($textgroup == "default" && !locale_string_is_safe($translation)) { + if (!locale_string_is_safe($translation)) { $report['skips']++; $lid = 0; } @@ -1040,7 +1027,6 @@ function _locale_import_one_string_db(&$report, $langcode, $context, $source, $t 'location' => $location, 'source' => $source, 'context' => (string) $context, - 'textgroup' => $textgroup, )) ->execute(); @@ -1413,7 +1399,7 @@ function _locale_parse_js_file($filepath) { // Remove the quotes and string concatenations from the string. $string = implode('', preg_split('~(? $string))->fetchObject(); + $source = db_query("SELECT lid, location FROM {locales_source} WHERE source = :source", array(':source' => $string))->fetchObject(); if ($source) { // We already have this source string and now have to add the location // to the location column, if this file is not yet present in there. @@ -1439,7 +1425,6 @@ function _locale_parse_js_file($filepath) { 'location' => $filepath, 'source' => $string, 'context' => '', - 'textgroup' => 'default', )) ->execute(); } @@ -1460,16 +1445,13 @@ function _locale_parse_js_file($filepath) { * @param $language * Language object to generate the output for, or NULL if generating * translation template. - * @param $group - * Text group to export PO file from (eg. 'default' for interface - * translations). */ -function _locale_export_get_strings($language = NULL, $group = 'default') { +function _locale_export_get_strings($language = NULL) { if (isset($language)) { - $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':language' => $language->language, ':textgroup' => $group)); + $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.translation, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language ORDER BY t.plid, t.plural", array(':language' => $language->language)); } else { - $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid WHERE s.textgroup = :textgroup ORDER BY t.plid, t.plural", array(':textgroup' => $group)); + $result = db_query("SELECT s.lid, s.source, s.context, s.location, t.plid, t.plural FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid ORDER BY t.plid, t.plural"); } $strings = array(); foreach ($result as $child) { @@ -1740,7 +1722,7 @@ function _locale_rebuild_js($langcode = NULL) { // Construct the array for JavaScript translations. // Only add strings with a translation to the translations array. - $result = db_query("SELECT s.lid, s.source, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.location LIKE '%.js%' AND s.textgroup = :textgroup", array(':language' => $language->language, ':textgroup' => 'default')); + $result = db_query("SELECT s.lid, s.source, t.translation FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.location LIKE '%.js%'", array(':language' => $language->language)); $translations = array(); foreach ($result as $data) { diff --git a/modules/locale/locale.admin.inc b/modules/locale/locale.admin.inc index ad7a583..8a4e71f 100644 --- a/modules/locale/locale.admin.inc +++ b/modules/locale/locale.admin.inc @@ -779,12 +779,6 @@ function locale_translate_import_form($form) { '#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, @@ -818,7 +812,7 @@ function locale_translate_import_form_submit($form, &$form_state) { } // Now import strings into the language - if ($return = _locale_import_po($file, $langcode, $form_state['values']['mode'], $form_state['values']['group']) == FALSE) { + if ($return = _locale_import_po($file, $langcode, $form_state['values']['mode']) == FALSE) { $variables = array('%filename' => $file->filename); drupal_set_message(t('The translation import of %filename failed.', $variables), 'error'); watchdog('locale', 'The translation import of %filename failed.', $variables, WATCHDOG_ERROR); @@ -868,11 +862,6 @@ function locale_translate_export_po_form($form, &$form_state, $names) { '#options' => $names, '#description' => t('Select the language to export in Gettext Portable Object (.po) format.'), ); - $form['group'] = array('#type' => 'radios', - '#title' => t('Text group'), - '#default_value' => 'default', - '#options' => module_invoke_all('locale', 'groups'), - ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export')); return $form; @@ -887,11 +876,6 @@ function locale_translate_export_pot_form() { '#title' => t('Export template'), '#description' => t('Generate a Gettext Portable Object Template (.pot) file with all strings from the Drupal locale database.'), ); - $form['group'] = array('#type' => 'radios', - '#title' => t('Text group'), - '#default_value' => 'default', - '#options' => module_invoke_all('locale', 'groups'), - ); $form['actions'] = array('#type' => 'actions'); $form['actions']['submit'] = array('#type' => 'submit', '#value' => t('Export')); // Reuse PO export submission callback. @@ -909,7 +893,7 @@ function locale_translate_export_po_form_submit($form, &$form_state) { $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']))); + _locale_export_po($language, _locale_export_po_generate($language, _locale_export_get_strings($language))); } /** diff --git a/modules/locale/locale.api.php b/modules/locale/locale.api.php index 2808f33..e327401 100644 --- a/modules/locale/locale.api.php +++ b/modules/locale/locale.api.php @@ -11,19 +11,6 @@ */ /** - * Allows modules to define their own text groups that can be translated. - * - * @param $op - * Type of operation. Currently, only supports 'groups'. - */ -function hook_locale($op = 'groups') { - switch ($op) { - case 'groups': - return array('custom' => t('Custom')); - } -} - -/** * Allows modules to act after language initialization has been performed. * * This is primarily needed to provide translation for configuration variables diff --git a/modules/locale/locale.install b/modules/locale/locale.install index a144813..7fbc81d 100644 --- a/modules/locale/locale.install +++ b/modules/locale/locale.install @@ -177,13 +177,6 @@ function locale_schema() { 'size' => 'big', 'description' => 'Drupal path in case of online discovered translations or file path in case of imported strings.', ), - 'textgroup' => array( - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => 'default', - 'description' => 'A module defined group of translations, see hook_locale().', - ), 'source' => array( 'type' => 'text', 'mysql_type' => 'blob', diff --git a/modules/locale/locale.module b/modules/locale/locale.module index 871048b..da8ad13 100644 --- a/modules/locale/locale.module +++ b/modules/locale/locale.module @@ -48,8 +48,7 @@ function locale_help($path, $arg) { $output = '
' . t('Determine the language from a request/session parameter. Example: "http://example.com?language=de" sets language to German based on the use of "de" within the "language" parameter.') . '
'; return $output; case 'admin/config/regional/translate': - $output = '' . t('This page provides an overview of available translatable strings. Drupal displays translatable strings in text groups; modules may define additional text groups containing other translatable strings. Because text groups provide a method of grouping related strings, they are often used to focus translation efforts on specific areas of the Drupal interface.') . '
'; - $output .= '' . t('See the Languages page for more information on adding support for additional languages.', array('@languages' => url('admin/config/regional/language'))) . '
'; + $output = '' . t('This page provides an overview of available translatable strings. See the Languages page for more information on adding support for additional languages.', array('@languages' => url('admin/config/regional/language'))) . '
'; return $output; case 'admin/config/regional/translate/import': $output = '' . t('This page imports the translated strings contained in an individual Gettext Portable Object (.po) file. Normally distributed as part of a translation package (each translation package may contain several .po files), a .po file may need to be imported after offline editing in a Gettext translation editor. Importing an individual .po file may be a lengthy process.') . '
'; @@ -58,7 +57,7 @@ function locale_help($path, $arg) { case 'admin/config/regional/translate/export': return '' . t('This page exports the translated strings used by your site. An export file may be in Gettext Portable Object (.po) form, which includes both the original string and the translation (used to share translations with others), or in Gettext Portable Object Template (.pot) form, which includes the original strings only (used to create new translations with a Gettext translation editor).') . '
'; case 'admin/config/regional/translate/translate': - return '' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: For translation tasks involving many strings, it may be more convenient to export strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings found within a specific text group or in a specific language.', array('@export' => url('admin/config/regional/translate/export'))) . '
'; + return '' . t('This page allows a translator to search for specific translated and untranslated strings, and is used when creating or editing translations. (Note: For translation tasks involving many strings, it may be more convenient to export strings for offline editing in a desktop Gettext translation editor.) Searches may be limited to strings in a specific language.', array('@export' => url('admin/config/regional/translate/export'))) . '
'; case 'admin/structure/block/manage/%/%': if ($arg[4] == 'locale' && $arg[5] == 'language') { return '' . t('This block is only shown if at least two languages are enabled and language negotiation is set to URL or Session.', array('@languages' => url('admin/config/regional/language'), '@configuration' => url('admin/config/regional/language/configure'))) . '
'; @@ -258,16 +257,6 @@ function locale_permission() { } /** - * Implements hook_locale(). - */ -function locale_locale($op = 'groups') { - switch ($op) { - case 'groups': - return array('default' => t('Built-in interface')); - } -} - -/** * Form builder callback to display language selection widget. * * @ingroup forms @@ -655,7 +644,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) { // Refresh database stored cache of translations for given language. // We only store short strings used in current version, to improve // performance and consume less memory. - $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.textgroup = 'default' AND s.version = :version AND LENGTH(s.source) < :length", array(':language' => $langcode, ':version' => VERSION, ':length' => variable_get('locale_cache_length', 75))); + $result = db_query("SELECT s.source, s.context, t.translation, t.language FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.version = :version AND LENGTH(s.source) < :length", array(':language' => $langcode, ':version' => VERSION, ':length' => variable_get('locale_cache_length', 75))); foreach ($result as $data) { $locale_t[$langcode][$data->context][$data->source] = (empty($data->translation) ? TRUE : $data->translation); } @@ -669,7 +658,7 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) { if (!isset($locale_t[$langcode][$context][$string])) { // We do not have this translation cached, so get it from the DB. - $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context AND s.textgroup = 'default'", array( + $translation = db_query("SELECT s.lid, t.translation, s.version FROM {locales_source} s LEFT JOIN {locales_target} t ON s.lid = t.lid AND t.language = :language WHERE s.source = :source AND s.context = :context", array( ':language' => $langcode, ':source' => $string, ':context' => (string) $context, @@ -697,7 +686,6 @@ function locale($string = NULL, $context = NULL, $langcode = NULL) { 'location' => request_uri(), 'source' => $string, 'context' => (string) $context, - 'textgroup' => 'default', 'version' => VERSION, )) ->execute(); diff --git a/modules/locale/locale.pages.inc b/modules/locale/locale.pages.inc index b4ccb6b..45816b9 100644 --- a/modules/locale/locale.pages.inc +++ b/modules/locale/locale.pages.inc @@ -1,11 +1,8 @@ textgroup] = $group->strings; - } + $headers = array(t('Language'), t('Interface translation status')); + $num_strings = db_query("SELECT COUNT(*) FROM {locales_source}")->fetchField(); // 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%)'); - } + $rows[$langcode] = array( + 'name' => ($langcode == 'en' ? t('English (built-in)') : t($language->name)), + 'status' => ($langcode == 'en' ? t('n/a') : '0/' . $num_strings . ' (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%)"; + if (!empty($num_strings)) { + // If we have source strings, match translations and compute progress. Not + // all languages may have information. + $translations = db_query("SELECT COUNT(*) AS translation, t.language FROM {locales_source} s INNER JOIN {locales_target} t ON s.lid = t.lid GROUP BY language"); + foreach ($translations as $data) { + $ratio = ($data->translation > 0) ? round(($data->translation/$num_strings) * 100.0, 2) : 0; + $rows[$data->language]['status'] = $data->translation . '/' . $num_strings . " ($ratio%)"; + } } return theme('table', array('header' => $headers, 'rows' => $rows)); @@ -68,7 +59,6 @@ function _locale_translate_seek() { if (!($query = _locale_translate_seek_query())) { $query = array( 'translation' => 'all', - 'group' => 'all', 'language' => 'all', 'string' => '', ); @@ -76,7 +66,7 @@ function _locale_translate_seek() { $sql_query = db_select('locales_source', 's'); $sql_query->leftJoin('locales_target', 't', 't.lid = s.lid'); - $sql_query->fields('s', array('source', 'location', 'context', 'lid', 'textgroup')); + $sql_query->fields('s', array('source', 'location', 'context', 'lid')); $sql_query->fields('t', array('translation', 'language')); // Compute LIKE section. @@ -110,22 +100,15 @@ function _locale_translate_seek() { $limit_language = $query['language']; } - // Add a condition on the text group. - if (!empty($query['group']) && $query['group'] != 'all') { - $sql_query->condition('s.textgroup', $query['group']); - } - $sql_query = $sql_query->extend('PagerDefault')->limit(50); $locales = $sql_query->execute(); - $groups = module_invoke_all('locale', 'groups'); - $header = array(t('Text group'), t('String'), t('Context'), ($limit_language) ? t('Language') : t('Languages'), array('data' => t('Operations'), 'colspan' => '2')); + $header = array(t('String'), t('Context'), ($limit_language) ? t('Language') : t('Languages'), array('data' => t('Operations'), 'colspan' => '2')); $strings = array(); foreach ($locales as $locale) { if (!isset($strings[$locale->lid])) { $strings[$locale->lid] = array( - 'group' => $locale->textgroup, 'languages' => array(), 'location' => $locale->location, 'source' => $locale->source, @@ -140,7 +123,6 @@ function _locale_translate_seek() { $rows = array(); foreach ($strings as $lid => $string) { $rows[] = array( - $groups[$string['group']], array('data' => check_plain(truncate_utf8($string['source'], 150, FALSE, TRUE)) . '