diff --git a/i18n.install b/i18n.install index fdbd84e56a86fce3c59a82ad59853db68765aa64..f6919a001b83b48927c1c3a6ecb439b02986f4b2 100644 --- a/i18n.install +++ b/i18n.install @@ -1,5 +1,11 @@ '.t('This module improves support for multilingual content in Drupal sites:').'

'; + $output = '

' . t('This module improves support for multilingual content in Drupal sites:') . '

'; $output .= ''; - $output .= '

'.t('This is the base module for several others adding different features:').'

'; + $output .= '

' . t('This is the base module for several others adding different features:') . '

'; $output .= ''; $output .= '

'. t('For more information, see the online handbook entry for Internationalization module.', array('@i18n' =>'http://drupal.org/node/133977')) .'

'; return $output; + case 'admin/settings/i18n': $output = ''; return $output; } @@ -552,7 +552,7 @@ function i18n_form_alter_settings(&$form, &$variables) { $result += i18n_form_alter_settings($form[$field], $variables); } elseif (in_array($field, $variables)) { - $form[$field]['#description'] .= ' '.t('This is a multilingual variable.').''; + $form[$field]['#description'] .= ' ' . t('This is a multilingual variable.') . ''; $result++; } } diff --git a/i18nblocks/i18nblocks.install b/i18nblocks/i18nblocks.install index 1c8ca6ebc18fdcdbadd25b6a50120d1ebaa6e1f0..2d5bec8769c07120c8e247e908a89037c704fa9d 100644 --- a/i18nblocks/i18nblocks.install +++ b/i18nblocks/i18nblocks.install @@ -1,6 +1,11 @@ '.t('This module provides support for multilingual blocks.').'

'; - $output .= '

'.t('You can set up a language for a block or define it as translatable:').'

'; + $output = '

' . t('This module provides support for multilingual blocks.') . '

'; + $output .= '

' . t('You can set up a language for a block or define it as translatable:') . '

'; $output .= ''; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; return $output; @@ -45,7 +46,7 @@ function i18nblocks_help($section, $arg) { } /** - * Implementation of hook_db_rewrite_sql() + * Implementation of hook_db_rewrite_sql(). */ function i18nblocks_db_rewrite_sql($query, $primary_table, $primary_key) { global $language; @@ -57,9 +58,9 @@ function i18nblocks_db_rewrite_sql($query, $primary_table, $primary_key) { } /** - * Implementation of hook_block() + * Implementation of hook_block(). * - * Blocks in i18n_blocks with no language are suppossed to be translatable + * Blocks in i18n_blocks with no language are suppossed to be translatable. */ /* function i18nblocks_block($op = 'list', $delta = 0, $edit = array()) { @@ -71,11 +72,13 @@ function i18nblocks_block($op = 'list', $delta = 0, $edit = array()) { $blocks[$data->ibid]['info'] = $data->info . t('[Translatable]'); } return $blocks; + case 'view': return i18nblocks_get_block($delta, i18n_get_lang()); break; + case 'configure': - $form['i18nblocks']['#value'] = t('This is a localizable block'); + $form['i18nblocks']['#value'] = t('This is a localizable block.'); return $form; } } @@ -102,18 +105,22 @@ function i18nblocks_form_alter(&$form, $form_state, $form_id) { $module = $form['module']['#value']; $delta = $form['delta']['#value']; $form['i18n'] = array( - '#type' => 'fieldset', - '#title' => t('Multilingual settings'), - '#collapsible' => TRUE, - '#weight' => -1, - ); - // For i18nblocks, just a help text + '#type' => 'fieldset', + '#title' => t('Multilingual settings'), + '#collapsible' => TRUE, + '#weight' => -1, + ); + // For i18nblocks, just a help text. if ($module == 'i18nblocks') { $form['i18n']['text'] = array('#value' => t('This is a translatable block.')); // Unset block title unset($form['block_settings']['title']); - $form['block_settings']['title'] = array('#type' => 'value', '#value' => ''); - } else { + $form['block_settings']['title'] = array( + '#type' => 'value', + '#value' => '' + ); + } + else { $i18nblock = i18nblocks_load($module, $delta); $form['i18n'] = array( '#type' => 'fieldset', @@ -121,7 +128,7 @@ function i18nblocks_form_alter(&$form, $form_state, $form_id) { '#collapsible' => TRUE, '#weight' => 0, ); - // Language options will depend on block type + // Language options will depend on block type. $options = array('' => t('All languages')); if ($module == 'block') { $options[I18N_BLOCK_LOCALIZE] = t('All languages (Translatable)'); @@ -129,12 +136,12 @@ function i18nblocks_form_alter(&$form, $form_state, $form_id) { $options += locale_language_list('name'); $form['i18n']['language'] = array( - '#type' => 'radios', - '#title' => t('Language'), - '#default_value' => $i18nblock->language, - '#options' => $options, + '#type' => 'radios', + '#title' => t('Language'), + '#default_value' => $i18nblock->language, + '#options' => $options, ); - // Pass i18ndelta value + // Pass i18ndelta value. $form['i18n']['ibid'] = array('#type' => 'value', '#value' => $i18nblock->ibid); $form['#submit'][] = 'i18nblocks_form_submit'; } @@ -142,7 +149,7 @@ function i18nblocks_form_alter(&$form, $form_state, $form_id) { } /** - * Forms api callback. Submit function + * Forms api callback. Submit function. */ function i18nblocks_form_submit($form, &$form_state) { $values = $form_state['values']; @@ -153,22 +160,27 @@ function i18nblocks_form_submit($form, &$form_state) { $values['delta'] = db_result(db_query("SELECT MAX(bid) FROM {boxes}")); } switch ($values['language']) { - case I18N_BLOCK_LOCALIZE: // Translatable block + case I18N_BLOCK_LOCALIZE: + // Translatable block. $values['language'] = ''; i18nblocks_save($values); break; - case '': // No language, delete all i18n information + + case '': + // No language, delete all i18n information. if ($values['ibid']) { db_query("DELETE FROM {i18n_blocks} WHERE ibid = %d", $values['ibid']); } break; - default: // The block has a language + + default: + // The block has a language. i18nblocks_save($values); } } /** - * Get block language data + * Get block language data. */ function i18nblocks_load($module, $delta) { $block = db_fetch_object(db_query("SELECT * FROM {i18n_blocks} WHERE module = '%s' AND delta = '%s'", $module, $delta)); @@ -180,16 +192,17 @@ function i18nblocks_load($module, $delta) { } /** - * Set block language data + * Set block language data. * * @param array $block - * Array of block parameters: module, delata, ibid (internal i18nblocks delta) + * Array of block parameters: module, delata, ibid (internal i18nblocks delta). */ function i18nblocks_save($block) { - // Update strings for localizable blocks + // Update strings for localizable blocks. if ($block['ibid']) { db_query("UPDATE {i18n_blocks} SET language = '%s' WHERE ibid = %d", $block['language'], $block['ibid']); - } else { + } + else { db_query("INSERT INTO {i18n_blocks}(module, delta, language) VALUES('%s', '%s', '%s')", $block['module'], $block['delta'], $block['language']); $block['ibid'] = db_last_insert_id('i18n_blocks', 'ibid'); } @@ -200,27 +213,27 @@ function i18nblocks_save($block) { } } - /** - * Load and translate block data + * Load and translate block data. * * @param $delta * Block id * @param $language - * Language to localize the block + * Language to localize the block. */ function i18nblocks_get_block($delta, $language){ - // Get block metadata + // Get block metadata. $meta = db_fetch_object(db_query("SELECT b.* FROM {blocks} b INNER JOIN {i18n_blocks} i ON i.delta = b.delta AND i.module = b.module WHERE i.ibid = '%d'", $delta)); - // Get block data from module + // Get block data from module. $block = module_invoke($meta->module, 'block', 'view', $meta->delta); if ($block) { - // Override the default title + // Override the default title. if ($meta->title) { // Check plain here to allow module generated titles to keep any markup. $block['subject'] = $meta->title == '' ? '' : check_plain(tt("blocks:block:$delta:title", $meta->title, $language)); - } elseif (!empty($block['subject'])) { + } + elseif (!empty($block['subject'])) { $block['subject'] = tt("blocks:block:$delta:title", $block['subject'], $language); } $block['content'] = tt("blocks:block:$delta:content", $block['content'], $language); @@ -229,13 +242,14 @@ function i18nblocks_get_block($delta, $language){ } /** - * Translate localizable block + * Translate localizable block. */ function i18nblocks_translate_block($block) { if ($block->title) { // Check plain here to allow module generated titles to keep any markup. $block->subject = $block->title == '' ? '' : check_plain(tt("blocks:block:$block->delta:title", $block->title)); - } elseif (!empty($block->subject)) { + } + elseif (!empty($block->subject)) { $block->subject = tt("blocks:block:$block->delta:title", $block->subject); } $block->content = tt("blocks:block:$block->delta:content", $block->content); @@ -243,11 +257,10 @@ function i18nblocks_translate_block($block) { } /** - * Implementation of hook_theme() + * Implementation of hook_theme(). * - * This will be used to override the theme_blocks() definition + * This will be used to override the theme_blocks() definition. */ - function i18nblocks_theme() { return array( 'i18nblocks' => array( @@ -258,19 +271,19 @@ function i18nblocks_theme() { } /** - * Implementation of hook theme_registry_alter() + * Implementation of hook theme_registry_alter(). * * Replace theme_blocks with theme_i18nblocks. There may be a better way to do this but - * I cannot figure out an easier way to build the whole registry entry + * I cannot figure out an easier way to build the whole registry entry. * - * Warning: this can mess with themes implementing the _blocks function + * Warning: this can mess with themes implementing the _blocks function. */ function i18nblocks_theme_registry_alter(&$theme_registry) { $theme_registry['blocks'] = $theme_registry['i18nblocks']; } /** - * Overrides theme_blocks() and translates blocks on the go + * Overrides theme_blocks() and translates blocks on the go. */ function i18nblocks_theme_blocks($region) { $output = ''; @@ -278,21 +291,22 @@ function i18nblocks_theme_blocks($region) { $i18nblocks = _i18nblocks_list(); if ($list = block_list($region)) { foreach ($list as $key => $block) { - // Configurable blocks, may be localizable + // Configurable blocks, may be localizable. if ($block->module == 'block') { if (isset($i18nblocks['block'][$block->delta])) { $block = i18nblocks_translate_block($block); } } elseif ($i18nmenu) { - // Replace menu blocks by their translated version + // Replace menu blocks by their translated version. if ($block->module == 'menu') { $block->content = i18nmenu_translated_tree($block->delta); - } elseif ($block->module == 'user' && $block->delta == 1) { + } + elseif ($block->module == 'user' && $block->delta == 1) { $block->content = i18nmenu_translated_tree('navigation'); } } - // Finally, render the block using standard theming + // Finally, render the block using standard theming. $output .= theme('block', $block); } } diff --git a/i18ncontent/i18ncontent.install b/i18ncontent/i18ncontent.install index b59a28266c4129d1b719f539bff65fbf47ffea69..0099c45aaac7a0ec29b61d01fd4d7c1844d21489 100644 --- a/i18ncontent/i18ncontent.install +++ b/i18ncontent/i18ncontent.install @@ -1,10 +1,14 @@ help && ($help = ts("nodetype:$type->type:help", $langcode))) { @@ -32,7 +36,7 @@ function i18ncontent_disable() { } /** - * The old module with the same name had a different approach, so the update will be full install + * The old module with the same name had a different approach, so the update will be full install. */ function i18ncontent_update_1() { $ret = array(); diff --git a/i18ncontent/i18ncontent.module b/i18ncontent/i18ncontent.module index 32d6a79165597e1ae0e9f2af70b41febe13fd8e8..57fd9a9847b7bba17f82a67bd339e82eb5504ab3 100644 --- a/i18ncontent/i18ncontent.module +++ b/i18ncontent/i18ncontent.module @@ -19,19 +19,20 @@ function i18ncontent_help($path, $arg) { switch ($path) { case 'admin/help#i18ncontent': - $output = '

'.t('This module will localize all content type configuration texts.').'

'; + $output = '

' . t('This module will localize all content type configuration texts.') . '

'; $output .= ''; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; return $output; } + if ($arg[0] == 'node' && $arg[1] == 'add' && $arg[2]) { $type = str_replace('-', '_', $arg[2]); if ($help = ts("nodetype:$type:help")) { - return '

'. filter_xss_admin($help) .'

'; + return '

' . filter_xss_admin($help) . '

'; } } } @@ -43,6 +44,7 @@ function i18ncontent_locale($op = 'groups', $group = NULL) { switch ($op) { case 'groups': return array('nodetype' => t('Content type')); + case 'refresh': if ($group == 'nodetype') { return i18ncontent_locale_refresh(); @@ -51,7 +53,7 @@ function i18ncontent_locale($op = 'groups', $group = NULL) { } /** - * Refresh content type strings + * Refresh content type strings. */ function i18ncontent_locale_refresh() { foreach (node_get_types() as $type) { @@ -67,10 +69,10 @@ function i18ncontent_locale_refresh() { } /** - * Implementation of hook_form_alter() + * Implementation of hook_form_alter(). */ function i18ncontent_form_alter(&$form, $form_state, $form_id) { - // Translate field names for title and body for the node edit form + // Translate field names for title and body for the node edit form. if (isset($form['#id']) && $form['#id'] == 'node-form') { $type = $form['#node']->type; if (!empty($form['title']['#title'])) { @@ -80,12 +82,12 @@ function i18ncontent_form_alter(&$form, $form_state, $form_id) { $form['body_field']['body']['#title'] = tt("nodetype:$type:body", $form['body_field']['body']['#title']); } } - // Handle submissions for node_type_forms + // Handle submissions for node_type_forms. if ($form_id == 'node_type_form') { $type = $form['#node_type']->type; - // We are using default language for this + // We are using default language for this. $language = language_default('language'); - // If we are creating a new one, just add the submission hook + // If we are creating a new one, just add the submission hook. if ($type) { //$form['description']['#default_value'] = ts("nodetype:$type:description"); $form['submission']['help']['#default_value'] = ts("nodetype:$type:help", $form['submission']['help']['#default_value'], $language); @@ -95,7 +97,7 @@ function i18ncontent_form_alter(&$form, $form_state, $form_id) { } /** - * Handle content type form submissions + * Handle content type form submissions. */ function i18ncontent_form_submit($form, &$form_state) { $language = language_default('language'); @@ -106,17 +108,18 @@ function i18ncontent_form_submit($form, &$form_state) { // Do anything?; } elseif ($op == t('Delete content type')) { - // Delete strings + // Delete strings. tt("nodetype:$type:name", NULL, NULL, TRUE); tt("nodetype:$type:help", NULL, NULL, TRUE); - } else { - // Update sources if changed type id + } + else { + // Update sources if changed type id. if ($old_type && $old_type != $type) { i18nstrings_update_context("nodetype:$old_type:*", "nodetype:$type:*"); } tt("nodetype:$type:name", $form_state['values']['name'], $language, TRUE); ts("nodetype:$type:help", $form_state['values']['help'], $language, TRUE); - // We remove help text so it's not produced later by node module + // We remove help text so it's not produced later by node module. $form_state['values']['help'] = ''; } } @@ -124,21 +127,20 @@ function i18ncontent_form_submit($form, &$form_state) { /** * Implementation of hook_menu_alter(). * - * Take over the node add pages + * Take over the node add pages. */ function i18ncontent_menu_alter(&$menu) { foreach ($menu as $path => $item) { if (!empty($item['page callback']) && $item['page callback'] == 'node_add') { $arg = arg(NULL, $path); $menu[$path]['title callback'] = 'i18nstrings_title_callback'; - $menu[$path]['title arguments'] = array('nodetype:'.$arg[2].':name', $item['title']); + $menu[$path]['title arguments'] = array('nodetype:' . $arg[2] . ':name', $item['title']); } } } - /** - * Replacement for node_add_page + * Replacement for node_add_page. */ function i18ncontent_node_add_page() { $item = menu_get_item(); @@ -146,4 +148,3 @@ function i18ncontent_node_add_page() { //dsm($content); return theme('node_add_list', $content); } - diff --git a/i18nmenu/i18nmenu.info b/i18nmenu/i18nmenu.info index 65d5284cc7fb6cd01af5b4c0ca42c54ff682aec2..9f608b787180d483c4840e6bc557a052f5d26973 100644 --- a/i18nmenu/i18nmenu.info +++ b/i18nmenu/i18nmenu.info @@ -1,3 +1,4 @@ +; $Id$ name = Menu translation description = Supports translatable custom menu items. dependencies[] = i18n diff --git a/i18nmenu/i18nmenu.install b/i18nmenu/i18nmenu.install index ea0cc61229f45253c658fba58be7412ee5587dee..fd32de67c2da6c3def8ea075d7e68ba47fe6e022 100644 --- a/i18nmenu/i18nmenu.install +++ b/i18nmenu/i18nmenu.install @@ -1,9 +1,15 @@ t('Menu')); + case 'refresh': if ($group == 'menu') { return i18nmenu_locale_refresh(); @@ -23,7 +25,7 @@ function i18nmenu_locale($op = 'groups', $group = NULL) { } /** - * Refresh locale strings + * Refresh locale strings. */ function i18nmenu_locale_refresh() { foreach (menu_get_menus() as $name => $title) { @@ -42,7 +44,8 @@ function i18nmenu_menu_link_alter(&$item, $menu) { // This should handle language only as the links are being manually updated if (!empty($item['language'])) { $item['options']['langcode'] = $item['language']; - } elseif(isset($item['language'])) { + } + elseif(isset($item['language'])) { unset($item['options']['langcode']); } // @ TO DO: Refresh texts @@ -53,15 +56,15 @@ function i18nmenu_menu_link_alter(&$item, $menu) { } /** - * Implementation of hook_help() + * Implementation of hook_help(). */ -function i18nmenu_help($section, $arg) { - switch ($section) { +function i18nmenu_help($path, $arg) { + switch ($path) { case 'admin/help#i18nmenu' : - $output = '

'.t('This module provides support for translatable custom menu items:').'

'; + $output = '

' . t('This module provides support for translatable custom menu items:') . '

'; $output .= ''; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; return $output; @@ -69,7 +72,7 @@ function i18nmenu_help($section, $arg) { } /** - * Get localized menu tree + * Get localized menu tree. */ function i18nmenu_translated_tree($menu_name) { static $menu_output = array(); @@ -83,26 +86,27 @@ function i18nmenu_translated_tree($menu_name) { } /** - * Localize menu tree + * Localize menu tree. */ function i18nmenu_localize_tree(&$tree) { global $language; - foreach($tree as $index => $item) { + foreach ($tree as $index => $item) { $link = $item['link']; if ($link['customized']) { - // Remove links for other languages than current - // Links with language wont be localized + // Remove links for other languages than current. + // Links with language wont be localized. if (!empty($link['options']['langcode'])) { - if($link['options']['langcode'] != $language->language) { + if ($link['options']['langcode'] != $language->language) { unset($tree[$index]); //dsm("Removed because language:".$link['title'].' language='.$link['options']['langcode']); } - } else { + } + else { $router = i18nmenu_get_router($link['router_path']); - // If the title is the same it will be localized by the menu system - if ($link['link_title'] != $router['title']){ + // If the title is the same it will be localized by the menu system. + if ($link['link_title'] != $router['title']) { //$tree[$index]['link']['title'] = 'Translated'; - $tree[$index]['link']['title'] = tt('menu:item:'.$link['mlid'].':title', $link['link_title'], NULL, TRUE); + $tree[$index]['link']['title'] = tt('menu:item:' . $link['mlid'] . ':title', $link['link_title'], NULL, TRUE); } // Localize subtree if ($item['below'] !== FALSE) { @@ -114,9 +118,9 @@ function i18nmenu_localize_tree(&$tree) { } /** - * Get the menu router for this router path + * Get the menu router for this router path. * - * We need the untranslated title to comparte, and this will be fast + * We need the untranslated title to compare, and this will be fast. * There's no api function to do this? */ function i18nmenu_get_router($path) { @@ -135,7 +139,8 @@ function i18nmenu_form_alter(&$form, $form_state, $form_id){ //dsm ($form); if ($form['menu']['#item'] && isset($form['menu']['#item']['options']['langcode'])) { $language = $form['menu']['#item']['options']['langcode']; - } else { + } + else { $language = ''; } $form['menu']['language'] = array( diff --git a/i18npoll/i18npoll.module b/i18npoll/i18npoll.module index d0d8207b6f8c31d9445f10a303086a21864ab70e..a0a67e40b8e882a791f24a4eb141ee7f9e20acce 100644 --- a/i18npoll/i18npoll.module +++ b/i18npoll/i18npoll.module @@ -1,13 +1,15 @@ readmore = FALSE; $links = module_invoke_all('link', 'node', $node, 1); - $links[] = array('title' => t('Older polls'), 'href' => 'poll', 'attributes' => array('title' => t('View the list of polls on this site.'))); + $links[] = array( + 'title' => t('Older polls'), + 'href' => 'poll', + 'attributes' => array( + 'title' => t('View the list of polls on this site.') + ) + ); if ($node->allowvotes && $block) { - $links[] = array('title' => t('Results'), 'href' => 'node/'. $node->nid .'/results', 'attributes' => array('title' => t('View the current poll results.'))); + $links[] = array( + 'title' => t('Results'), + 'href' => 'node/' . $node->nid . '/results', + 'attributes' => array( + 'title' => t('View the current poll results.') + ) + ); } $node->links = $links; @@ -128,7 +142,7 @@ function i18npoll_view_results(&$node, $teaser, $page, $block) { // Load the appropriate choices into the $poll object. $result = db_query("SELECT c.chorder, SUM(c.chvotes) AS votes FROM {poll_choices} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.tnid = %d GROUP BY c.chorder", $node->tnid); while ($choice = db_fetch_object($result)) { - // If this option not set for the source node, do not show + // If this option not set for the source node, do not show. if (isset($node->choice[$choice->chorder])) { $node->choice[$choice->chorder]['chvotes'] = $choice->votes; } @@ -137,9 +151,9 @@ function i18npoll_view_results(&$node, $teaser, $page, $block) { } /** - * Get user vote for this node or its translations + * Get user vote for this node or its translations. * - * Returns object with nid, chorder. Has static caching as this will typically be called twice + * Returns object with nid, chorder. Has static caching as this will typically be called twice. */ function i18npoll_get_vote($tnid) { global $user; diff --git a/i18nprofile/i18nprofile.info b/i18nprofile/i18nprofile.info index 299b23033125a8cdbaff688d8704ca2c81f2a2f2..b4736dc53c5e18807451ed7537eb63dd036255a5 100644 --- a/i18nprofile/i18nprofile.info +++ b/i18nprofile/i18nprofile.info @@ -1,3 +1,4 @@ +; $Id$ name = Profile translation description = Enables multilingual profile fields. dependencies[] = profile diff --git a/i18nprofile/i18nprofile.install b/i18nprofile/i18nprofile.install index bf032b636cf4f1a69eccfa1346f6459e91f4e36f..464d051225741b93a0fa9cb15abb32b8c2e6357a 100644 --- a/i18nprofile/i18nprofile.install +++ b/i18nprofile/i18nprofile.install @@ -2,40 +2,39 @@ // $Id$ /** - * Nothing to install for Drupal 6 + * @file + * Installation file for i18nprofile module. */ -function i18nprofile_install() { -} /** - * Refresh strings when enabled + * Refresh strings when enabled. */ function i18nprofile_enable() { i18nprofile_locale_refresh(); } -// Drupal 6 updates +// Drupal 6 updates. /** - * Drop old table and fields + * Drop old table and fields. */ function i18nprofile_update_2() { $items = array(); - // Create source strings for translations + // Create source strings for translations. $categories = array(); $result = db_query("SELECT * FROM {profile_fields}"); while ($field = db_fetch_object($result)) { - // Store strings to translate: title, explanation, options + // Store strings to translate: title, explanation, options. to("profile:field:$field->name", $field, array('title', 'explanation', 'options'), NULL, TRUE); if (!in_array($field->category, $categories)) { $categories[] = $field->category; tt("profile:category", $field->category, NULL, TRUE); } } - // Category translations from variables + // Category translations from variables. foreach (array_keys(language_list()) as $lang) { - if ($translation = variable_get('i18nprofile_'.$lang, FALSE)) { + if ($translation = variable_get('i18nprofile_' . $lang, FALSE)) { foreach ($translation as $category => $translation) { if (in_array($category, $categories) && $translation) { $context = i18nstrings_context('profile:category', $category); @@ -44,7 +43,7 @@ function i18nprofile_update_2() { } } } - // Move current data into string translations + // Move current data into string translations. $result = db_query("SELECT * FROM {i18n_profile_fields}"); while ($field = db_fetch_object($result)) { foreach (array('title', 'explanation', 'options') as $property) { @@ -57,7 +56,7 @@ function i18nprofile_update_2() { return $items; } -// Clean up. Uncomment when it all works +// Clean up. Uncomment when it all works. /* function i18nprofile_update_3() { $items[] = update_sql("DROP TABLE {i18n_profile_fields};"); diff --git a/i18nprofile/i18nprofile.module b/i18nprofile/i18nprofile.module index 30d16c70abb52ad4500fe3a217f9ad375ad43912..304631019c4531c850c55e01588e0490c5089ed8 100644 --- a/i18nprofile/i18nprofile.module +++ b/i18nprofile/i18nprofile.module @@ -2,19 +2,19 @@ // $Id$ /** - * Internationalization (i18n) submodule: Profile translation + * @file + * Internationalization (i18n) submodule: Profile translation. * - * Allows translation of profile categories and fields + * Allows translation of profile categories and fields. * * @author Jose A. Reyero, 2006 - * */ /** - * Implementation of hook_help() + * Implementation of hook_help(). */ -function i18nprofile_help($section, $arg) { - switch ($section) { +function i18nprofile_help($path, $arg) { + switch ($path) { case 'admin/modules#description' : $output = '

' . t('Supports translation for profile module field names and descriptions.') . '

'; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; @@ -29,6 +29,7 @@ function i18nprofile_locale($op = 'groups', $group = NULL) { switch ($op) { case 'groups': return array('profile' => t('Profile')); + case 'refresh': if ($group == 'profile') { return i18nprofile_locale_refresh(); @@ -37,15 +38,15 @@ function i18nprofile_locale($op = 'groups', $group = NULL) { } /** - * Refresh strings + * Refresh strings. */ function i18nprofile_locale_refresh() { $result = db_query('SELECT * FROM {profile_fields}'); $categories = array(); while ($field = db_fetch_object($result)) { - // Store strings to translate: title, explanation, options + // Store strings to translate: title, explanation, options. to("profile:field:$field->name", $field, array('title', 'explanation', 'options'), NULL, TRUE); - // Store category if not there yet + // Store category if not there yet. if (!isset($categories[$field->category])) { tt("profile:category", $field->category, NULL, TRUE); $categories[$field->category] = 1; @@ -56,14 +57,14 @@ function i18nprofile_locale_refresh() { /** * Implementation of hook_menu_alter(). * - * Replace title callbacks for profile categories + * Replace title callbacks for profile categories. */ function i18nprofile_menu_alter(&$items) { $empty_account = new stdClass(); if (($categories = _user_categories($empty_account)) && (count($categories) > 1)) { foreach ($categories as $key => $category) { // 'account' is already handled by the MENU_DEFAULT_LOCAL_TASK. - $path = 'user/%user_category/edit/'. $category['name']; + $path = 'user/%user_category/edit/' . $category['name']; if ($category['name'] != 'account' && !empty($items[$path])) { $items[$path]['title callback'] = 'i18nprofile_translate_category'; // Was 'check_plain', $items[$path]['title arguments'] = array($category['title']); // Was array($category['title']) @@ -77,51 +78,53 @@ function i18nprofile_translate_category($title) { } /** - * Implementation of hook_profile_alter() + * Implementation of hook_profile_alter(). * - * Translates categories and fields + * Translates categories and fields. */ function i18nprofile_profile_alter(&$account) { foreach (profile_categories() as $category) { $name = $category['name']; if (!empty($account->content[$name])) { - // First ranslate category title then fields + // First ranslate category title then fields. $account->content[$name]['#title'] = tt('profile:category', $account->content[$name]['#title']); foreach (element_children($account->content[$name]) as $field) { i18nprofile_form_translate_field($account->content[$name], $field); // Translate value if options field if (!empty($account->content[$name][$field]['#value']) && $options = i18nprofile_field_options($field)) { - // Get the value from the account because this one may have been formatted + // Get the value from the account because this one may have been formatted. if (isset($options[$account->$field])) { - // It may be a link or a paragraph, trick for not loading the field again + // It may be a link or a paragraph, trick for not loading the field again. if ($account->content[$name][$field]['#value'] == check_markup($account->$field)) { $account->content[$name][$field]['#value'] = check_markup($options[$account->$field]); // Plain html - } else { + } + else { // Link - $account->content[$name][$field]['#value'] == check_markup(l($account->$field, 'profile/'. $field .'/'. $account->$field)); + $account->content[$name][$field]['#value'] == check_markup(l($account->$field, 'profile/' . $field . '/' . $account->$field)); } } } - } } } } /** - * Implementation of hook_form_alter() + * Implementation of hook_form_alter(). */ function i18nprofile_form_alter(&$form, $form_state, $form_id) { switch ($form_id) { case 'profile_field_form': $form['#submit'][] = 'i18nprofile_field_form_submit'; break; + case 'user_profile_form': if (($category = $form['_category']['#value']) && $category != 'account') { i18nprofile_form_translate_category($form, $category); } break; + case 'user_register': i18nprofile_form_translate_all($form_id, $form); break; @@ -133,19 +136,19 @@ function i18nprofile_form_alter(&$form, $form_state, $form_id) { */ function i18nprofile_field_form_submit($form, &$form_state) { $values = (object)$form_state['values']; - // Check old field name in case it has changed + // Check old field name in case it has changed. $oldname = $form['fields']['name']['#default_value']; if ($oldname != 'profile_' && $oldname != $values->name) { i18nstrings_update_context("profile:field:$oldname:*", "profile:field:$values->name:*"); } - // Store category + // Store category. tt("profile:category", $values->category, NULL, TRUE); - // Store strings to translate: title, explanation, options + // Store strings to translate: title, explanation, options. to("profile:field:$values->name", $values, array('title', 'explanation', 'options'), NULL, TRUE); } /** - * Translate form fields for a given category + * Translate form fields for a given category. */ function i18nprofile_form_translate_category(&$form, $category){ if (!empty($form[$category])) { @@ -157,8 +160,7 @@ function i18nprofile_form_translate_category(&$form, $category){ } /** - * Translate form field - * + * Translate form field. */ function i18nprofile_form_translate_field(&$form, $field) { if (!empty($form[$field]['#title'])) { @@ -176,7 +178,7 @@ function i18nprofile_form_translate_field(&$form, $field) { } /** - * Translates field options + * Translates field options. */ function i18nprofile_field_options($field, $source = array()) { if ($translation = tt("profile:field:$field:options", '')) { @@ -185,10 +187,12 @@ function i18nprofile_field_options($field, $source = array()) { $translation = split("[,\n]", $translation); if ($source) { $options = $source; - } else if($source = db_result(db_query("SELECT options FROM {profile_fields} WHERE name = '%s'", $field))) { + } + elseif ($source = db_result(db_query("SELECT options FROM {profile_fields} WHERE name = '%s'", $field))) { $source = split("[,\n\r]", $source); $options = array(); - } else { + } + else { return NULL; } foreach ($source as $value) { @@ -202,9 +206,9 @@ function i18nprofile_field_options($field, $source = array()) { } /** - * Translate form fields for all categories + * Translate form fields for all categories. * - * This is useful when we don't know which categories we have, like in the user register form + * This is useful when we don't know which categories we have, like in the user register form. */ function i18nprofile_form_translate_all($form_id, &$form) { $categories = profile_categories(); @@ -218,46 +222,50 @@ function i18nprofile_form_translate_all($form_id, &$form) { } /** - * Returns translated categories + * Returns translated categories. * * @ TODO Drupal 6 * - * Note: weight must be minor than profile module's for them to be added first + * Note: weight must be minor than profile module's for them to be added first. * * @param $getraw - * Return the raw array of translations + * Return the raw array of translations. */ function i18nprofile_categories($getraw = FALSE) { $language = i18n_get_lang(); if ($translation = variable_get('i18nprofile_'.$language, 0)) { - if($getraw) { + if ($getraw) { return $translation; } - foreach($translation as $name => $value) { - $categories[] = array('name' => $name, 'title' => $value, 'weight' => 2); + foreach ($translation as $name => $value) { + $categories[] = array( + 'name' => $name, + 'title' => $value, + 'weight' => 2 + ); } return $categories; - } else { + } + else { return array(); } } /** - * Returns field translations + * Returns field translations. * * @ TODO Drupal 6 */ function i18nprofile_fields($category){ static $_fields; $language = i18n_get_lang(); - if(!isset($_fields[$category])) { + if (!isset($_fields[$category])) { $_fields[$category] = array(); - // Some special categories + // Some special categories. $result = db_query("SELECT p.name, p.type, t.* FROM {profile_fields} p INNER JOIN {i18n_profile_fields} t ON p.fid = t.fid WHERE LOWER(p.category) = LOWER('%s') AND t.language='%s'", $category, $language); - while($field = db_fetch_object($result)) { + while ($field = db_fetch_object($result)) { $_fields[$category][$field->name] = $field; } } return $_fields[$category]; } - diff --git a/i18nstrings/i18nstrings.admin.inc b/i18nstrings/i18nstrings.admin.inc index 1c20d3e2c01058019376e0816d08a9f7403c63b0..b763e3869333c9a58a093feb0826acefab8d0057 100644 --- a/i18nstrings/i18nstrings.admin.inc +++ b/i18nstrings/i18nstrings.admin.inc @@ -13,20 +13,23 @@ function i18nstrings_admin_refresh_page() { } /** - * Form callback. Refresh textgroups + * Form callback. Refresh textgroups. */ function i18nstrings_admin_refresh() { - // Select textgroup/s + // Select textgroup/s. $groups = module_invoke_all('locale', 'groups'); unset($groups['default']); - $form['groups'] = array('#type' => 'checkboxes', + $form['groups'] = array( + '#type' => 'checkboxes', '#title' => t('Select text groups'), '#options' => $groups, ); - $form['refresh'] = array('#type' => 'submit', '#value' => t('Refresh strings'), - '#suffix' => '

'.t('This will create all the missing strings for the selected text groups.').'

', + $form['refresh'] = array( + '#type' => 'submit', + '#value' => t('Refresh strings'), + '#suffix' => '

' . t('This will create all the missing strings for the selected text groups.') . '

', ); - // Get all languages, except default language + // Get all languages, except default language. $languages = locale_language_list('name', TRUE); unset($languages[language_default('language')]); $form['languages'] = array( @@ -34,14 +37,16 @@ function i18nstrings_admin_refresh() { '#title' => t('Select languages'), '#options' => $languages, ); - $form['update'] = array('#type' => 'submit', '#value' => t('Update translations'), - '#suffix' => '

'.t('This will fetch all existing translations from the localization tables for the selected text groups and languages.').'

', + $form['update'] = array( + '#type' => 'submit', + '#value' => t('Update translations'), + '#suffix' => '

' . t('This will fetch all existing translations from the localization tables for the selected text groups and languages.') . '

', ); return $form; } /** - * Form submission + * Form submission. */ function i18nstrings_admin_refresh_submit($form, &$form_state) { $op = isset($form_state['values']['op']) ? $form_state['values']['op'] : ''; @@ -52,7 +57,8 @@ function i18nstrings_admin_refresh_submit($form, &$form_state) { foreach ($groups as $group) { module_invoke_all('locale', 'refresh', $group); } - } else if($op == t('Update translations') && $groups && $languages) { + } + elseif ($op == t('Update translations') && $groups && $languages) { $count = 0; foreach ($languages as $language) { $count += i18nstrings_admin_update($language, $groups); @@ -62,7 +68,7 @@ function i18nstrings_admin_refresh_submit($form, &$form_state) { } /** - * Update strings for language + * Update strings for language. */ function i18nstrings_admin_update($language, $groups) { $params = $groups; @@ -80,6 +86,3 @@ function i18nstrings_admin_update($language, $groups) { } return $count; } - - - diff --git a/i18nstrings/i18nstrings.install b/i18nstrings/i18nstrings.install index fa4ac674ce89c7ef211a68cab2d41f17d1b0d2e8..a97283e2ddf93c0b834a6059e98fe8d41c2d15d6 100644 --- a/i18nstrings/i18nstrings.install +++ b/i18nstrings/i18nstrings.install @@ -1,15 +1,20 @@ '; $output .= '

' . t('Read more on the Internationalization handbook: Translating user defined strings.') . '

'; return $output; + case 'admin/build/translate/refresh': $output = '

' . t('On this page you can refresh and update values for user defined strings.') . '

'; $output .= ''; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; return $output; + case 'admin/settings/language': $output .= '

' . t('Warning: Changing the default language may have unintended effects on string translations. Read more about String translation', array('@i18nstrings-help' => url('admin/help/i18nstrings'))) . '

'; return $output; @@ -65,7 +67,7 @@ function i18nstrings_menu() { /** * Implementation of hook_form_alter(); * - * Add English language in some string forms when it is not the default + * Add English language in some string forms when it is not the default. */ function i18nstrings_form_alter(&$form, $form_state, $form_id) { @@ -86,14 +88,14 @@ function i18nstrings_form_alter(&$form, $form_state, $form_id) { } /** - * Translate configurable string + * Translate configurable string. * * @param $name - * Textgroup and location glued with ':' + * Textgroup and location glued with ':'. * @param $string - * String in default language. Default language may or may not be English + * String in default language. Default language may or may not be English. * @param $langcode - * Optional language code if different from current request language + * Optional language code if different from current request language. * @param $update * Whether to force update/create for the string. */ @@ -108,7 +110,8 @@ function tt($name, $string, $langcode = NULL, $update = FALSE) { // If language is default, just return if (language_default('language') == $langcode) { return $string; - } else { + } + else { return i18nstrings_tt($name, $string, $langcode, FALSE); } } @@ -119,7 +122,7 @@ function tt($name, $string, $langcode = NULL, $update = FALSE) { * The difference with tt() is that it doesn't use a default string, it will be retrieved too. * This is used for source texts that we don't have stored anywhere else. * - * As the original language string will be stored in locales too so it should be only used when updating + * As the original language string will be stored in locales too so it should be only used when updating. */ function ts($name, $string = '', $langcode = NULL, $update = FALSE) { global $language; @@ -137,7 +140,8 @@ function ts($name, $string = '', $langcode = NULL, $update = FALSE) { if (!$translation) { if ($source = i18nstrings_get_source($name)) { $translation = $source->source; - } else { + } + else { $translation = ''; } } @@ -145,21 +149,21 @@ function ts($name, $string = '', $langcode = NULL, $update = FALSE) { } /** - * Debug util. Marks the translated strings + * Debug util. Marks the translated strings. */ function ttd($name, $string, $langcode = NULL, $update = FALSE) { $context = i18nstrings_context($name, $string); $context = implode('/', (array)$context); - return tt($name, $string, $langcode, $update).'[T:'.$string.'('.$context.')]'; + return tt($name, $string, $langcode, $update).'[T:' . $string . '(' . $context . ')]'; } /** - * Translate configurable string + * Translate configurable string. * - * Support for l10n client (patch pending for l10n client) + * Support for l10n client (patch pending for l10n client). * * @param $name - * Textgroup and location glued with ':' + * Textgroup and location glued with ':'. */ function i18nstrings_tt($name, $string, $langcode, $update = FALSE) { global $language, $l10n_client_strings; @@ -173,15 +177,15 @@ function i18nstrings_tt($name, $string, $langcode, $update = FALSE) { $translation = i18nstrings_get_string($context, $langcode, $string, !$update); if ($translation === FALSE) { - // If the string is missing, create it + // If the string is missing, create it. if (!$update) { i18nstrings_add_string($name, $string); i18nstrings_cache($context, $langcode, $string, TRUE); } $translation = TRUE; } - // If current language add to l10n list for later on page translation - // If language were the default one we are not supossed to reach here + // If current language add to l10n list for later on page translation. + // If language were the default one we are not supossed to reach here. if ($language->language == $langcode) { $l10n_client_strings[$string] = $translation; } @@ -189,23 +193,24 @@ function i18nstrings_tt($name, $string, $langcode, $update = FALSE) { } /** - * Translate object + * Translate object. */ function to($context, &$object, $properties = array(), $langcode = NULL, $update = FALSE) { global $language; $langcode = $langcode ? $langcode : $language->language; - // If language is default, just return + // If language is default, just return. if (language_default('language') == $langcode && !$update) { return $object; - } else { + } + else { i18nstrings_to($context, $object, $properties, $langcode, $update); } } /** - * Translate object properties + * Translate object properties. */ function i18nstrings_to($context, &$object, $properties = array(), $langcode = NULL, $update = FALSE, $create = TRUE) { $context = i18nstrings_context($context); @@ -223,7 +228,7 @@ function i18nstrings_to($context, &$object, $properties = array(), $langcode = N * Update / create / remove string * * @param $context - * String context + * String context. * @pram $string * New value of string for update/create. May be empty for removing. */ @@ -231,7 +236,8 @@ function i18nstrings_update_string($context, $string) { $context = i18nstrings_context($context, $string); if ($string) { $status = i18nstrings_add_string($context, $string); - } else { + } + else { $status = i18nstrings_remove_string($context); } $params = array( @@ -243,6 +249,7 @@ function i18nstrings_update_string($context, $string) { case SAVED_UPDATED: drupal_set_message(t('Updated string %location for textgroup %textgroup: %string', $params)); break; + case SAVED_NEW: drupal_set_message(t('Created string %location for text group %textgroup: %string', $params)); break; @@ -251,34 +258,34 @@ function i18nstrings_update_string($context, $string) { } /** - * Update string translation + * Update string translation. */ function i18nstrings_update_translation($context, $langcode, $translation) { if ($source = i18nstrings_get_source($context, $translation)) { - db_query("INSERT INTO {locales_target}(lid, language, translation) VALUES(%d, '%s', '%s')", $source->lid, $langcode, $translation); + db_query("INSERT INTO {locales_target} (lid, language, translation) VALUES(%d, '%s', '%s')", $source->lid, $langcode, $translation); } } /** * Add string * - * This function checks for already existing string without context for this textgroup + * This function checks for already existing string without context for this textgroup. * * @return - * Update status + * Update status. */ function i18nstrings_add_string($name, $string) { $context = i18nstrings_context($name, $string); $location = i18nstrings_location($context); - // Check if we have a source string + // Check if we have a source string. $source = i18nstrings_get_source($context, $string); $status = -1; if ($source) { if ($source->source != $string || $source->location != $location) { - // String has changed or didnt have location + // String has changed or didnt have location. db_query("UPDATE {locales_source} SET source = '%s' WHERE lid = %d", $string, $source->lid); $status = SAVED_UPDATED; } @@ -289,10 +296,10 @@ function i18nstrings_add_string($name, $string) { $source->lid = db_last_insert_id('locales_source', 'lid'); // Clear locale cache so this string can be added in a later request. cache_clear_all('locale:'.$context->textgroup.':', 'cache', TRUE); - // Create string + // Create string. $status = SAVED_NEW; } - // Update metadata + // Update metadata. db_query("DELETE FROM {i18n_strings} WHERE lid = %d", $source->lid); db_query("INSERT INTO {i18n_strings} (lid, type, objectid, property) VALUES(%d, '%s', %d, '%s')", $source->lid, $context->type, $context->objectid, $context->property); @@ -300,26 +307,26 @@ function i18nstrings_add_string($name, $string) { } /** - * Get source string provided a string context + * Get source string provided a string context. * * This will search first with the full context parameters and, if not found, - * it will search again only with textgroup and source string + * it will search again only with textgroup and source string. * * @param $context - * Context string or object + * Context string or object. * @return - * Context object if it exists + * Context object if it exists. */ function i18nstrings_get_source($context, $string = NULL) { $context = i18nstrings_context($context, $string); - // Check if we have the string for this location + // Check if we have the string for this location. list($where, $args) = i18nstrings_context_query($context); if ($source = db_fetch_object(db_query("SELECT s.*, i.type, i.objectid, i.property FROM {locales_source} s LEFT JOIN {i18n_strings} i ON s.lid = i.lid WHERE ". implode(' AND ', $where), $args))) { $source->context = $context; return $source; } - // Search for the same string for this textgroup without object data + // Search for the same string for this textgroup without object data. if ($string && $source = db_fetch_object(db_query("SELECT s.*, i.type, i.objectid, i.property FROM {locales_source} s LEFT JOIN {i18n_strings} i ON s.lid = i.lid WHERE s.textgroup = '%s' AND s.source = '%s' AND i.lid IS NULL", $context->textgroup, $string))) { $source->context = NULL; return $source; @@ -327,25 +334,26 @@ function i18nstrings_get_source($context, $string = NULL) { } /** - * Get string for a language + * Get string for a language. * * @param $context - * Context string or object + * Context string or object. * @param $langcode - * Language code to retrieve string for + * Language code to retrieve string for. * * @return - * - translation if found - * - TRUE if not found and cached - * - FALSE if not even cached + * - Translation if found. + * - TRUE if not found and cached. + * - FALSE if not even cached. * */ function i18nstrings_get_string($context, $langcode) { $context = i18nstrings_context($context); if ($translation = i18nstrings_cache($context, $langcode)) { return $translation; - } else { - // Search translation and add it to the cache + } + else { + // Search translation and add it to the cache. list($where, $args) = i18nstrings_context_query($context); $where[] = "t.language = '%s'"; $args[] = $langcode; @@ -354,7 +362,8 @@ function i18nstrings_get_string($context, $langcode) { if ($text && $text->translation) { i18nstrings_cache($context, $langcode, NULL, $text->translation); return $text->translation; - } else { + } + else { i18nstrings_cache($context, $langcode, NULL, TRUE); return $text ? NULL : FALSE ; } @@ -362,7 +371,7 @@ function i18nstrings_get_string($context, $langcode) { } /** - * Remove string for a given context + * Remove string for a given context. */ function i18nstrings_remove_string($context, $string = NULL) { if ($source = i18nstrings_get_source($context, $string)) { @@ -379,34 +388,34 @@ function i18nstrings_remove_string($context, $string = NULL) { * * As some string locations depend on configurable values, the field needs sometimes to be updated * without losing existing translations. I.e: - * - profile fields indexed by field name - * - content types indexted by low level content type name + * - profile fields indexed by field name. + * - content types indexted by low level content type name. * - * Example + * Example: * 'profile:field:oldfield:*' -> 'profile:field:newfield:*' */ function i18nstrings_update_context($oldname, $newname) { - // Get context replacing '*' with empty string + // Get context replacing '*' with empty string. $oldcontext = i18nstrings_context(str_replace('*', '', $oldname)); $newcontext = i18nstrings_context(str_replace('*', '', $newname)); - // Get location with placeholders + // Get location with placeholders. $location = i18nstrings_location(str_replace('*', '%', $oldname)); foreach (array('textgroup', 'type', 'objectid', 'property') as $field) { if ((!empty($oldcontext->$field) || !empty($newcontext->$field)) && $oldcontext->$field != $newcontext->$field) { $replace[$field] = $newcontext->$field; } } - // Query and replace + // Query and replace. $result = db_query("SELECT s.*, i.type, i.objectid, i.property FROM {locales_source} s LEFT JOIN {i18n_strings} i ON s.lid = i.lid WHERE s.textgroup = '%s' AND s.location LIKE '%s'", $oldcontext->textgroup, $location); while ($source = db_fetch_object($result)) { - // Make sure we have string and context - $context = i18nstrings_context($oldcontext->textgroup.':'.$source->location); + // Make sure we have string and context. + $context = i18nstrings_context($oldcontext->textgroup . ':' . $source->location); foreach ($replace as $field => $value) { $context->$field = $value; } - // Update source string + // Update source string. db_query("UPDATE {locales_source} SET textgroup = '%s', location = '%s' WHERE lid = %d", $context->textgroup, i18nstrings_location($context), $source->lid); - // Update object data + // Update object data. db_query("UPDATE {i18n_strings} SET type = '%s', objectid = '%s', property = '%s' WHERE lid = %d", $context->type, $context->objectid, $context->property, $source->lid); } drupal_set_message(t('Updating string names from %oldname to %newname.', array('%oldname' => $oldname, '%newname' => $newname))); @@ -430,14 +439,14 @@ function i18nstrings_textgroup($textgroup, $string = NULL, $langcode = NULL) { global $language; static $locale_t; - // Return all cached strings if no string was specified + // Return all cached strings if no string was specified. if (!isset($string)) { return isset($locale_t[$textgroup]) ? $locale_t[$textgroup] : array(); } $langcode = isset($langcode) ? $langcode : $language->language; - // Store database cached translations in a static var. + // Store database cached translations in a static variable. if (!isset($locale_t[$langcode])) { $locale_t[$langcode] = array(); // Disabling the usage of string caching allows a module to watch for @@ -456,7 +465,7 @@ function i18nstrings_textgroup($textgroup, $string = NULL, $langcode = NULL) { while ($data = db_fetch_object($result)) { $locale_t[$textgroup][$langcode][$data->source] = (empty($data->translation) ? TRUE : $data->translation); } - cache_set('locale:'.$textgroup.':'. $langcode, $locale_t[$textgroup][$langcode]); + cache_set('locale:' . $textgroup . ':' . $langcode, $locale_t[$textgroup][$langcode]); } } } @@ -476,7 +485,7 @@ function i18nstrings_textgroup($textgroup, $string = NULL, $langcode = NULL) { // and clear cache, to include the string into caching next time. Saved version is // also a string-history information for later pruning of the tables. db_query_range("UPDATE {locales_source} SET version = '%s' WHERE lid = %d", VERSION, $translation->lid, 0, 1); - cache_clear_all('locale:'.$textgroup.':', 'cache', TRUE); + cache_clear_all('locale:' . $textgroup . ':', 'cache', TRUE); } } else { @@ -484,7 +493,7 @@ function i18nstrings_textgroup($textgroup, $string = NULL, $langcode = NULL) { db_query("INSERT INTO {locales_source} (location, source, textgroup, version) VALUES ('%s', '%s', 'default', '%s')", request_uri(), $string, VERSION); $locale_t[$langcode][$string] = TRUE; // Clear locale cache so this string can be added in a later request. - cache_clear_all('locale:'.$textgroup.':', 'cache', TRUE); + cache_clear_all('locale:' . $textgroup . ':', 'cache', TRUE); } } @@ -492,15 +501,17 @@ function i18nstrings_textgroup($textgroup, $string = NULL, $langcode = NULL) { } /** - * Convert context string in a context object + * Convert context string in a context object. * * I.e. * 'taxonomy:term:1:name' + * * will become a $context object where * $context->textgroup = 'taxonomy'; * $context->type = 'term'; * $context->objectid = 1; * $context->property = 'name'; + * * Examples: * 'taxonomy:title' -> (taxonomy, title, 0, 0) * 'contenttypes:type:[type]:name' @@ -509,19 +520,20 @@ function i18nstrings_textgroup($textgroup, $string = NULL, $langcode = NULL) { * 'profile:field:[fid]:title' * * @param $context - * Context string or object + * Context string or object. * @param $string - * For some textgroups and objects that don't have ids we use the string itself as index + * For some textgroups and objects that don't have ids we use the string itself as index. * @return - * Context object with textgroup, type, objectid, property and location names + * Context object with textgroup, type, objectid, property and location names. */ function i18nstrings_context($context, $string = NULL) { - // Context may be already an object + // Context may be already an object. if (is_object($context)) { return $context; - } else { - // We add empty fields at the end before splitting - list($textgroup, $type, $objectid, $property) = split(':', $context.':::'); + } + else { + // We add empty fields at the end before splitting. + list($textgroup, $type, $objectid, $property) = split(':', $context . ':::'); $context = (object)array( 'textgroup' => $textgroup, 'type' => $type, @@ -537,7 +549,7 @@ function i18nstrings_context($context, $string = NULL) { } /** - * Get query conditions for this context + * Get query conditions for this context. */ function i18nstrings_context_query($context, $alias = 's') { $where = array("$alias.textgroup = '%s'", "$alias.location = '%s'"); @@ -550,9 +562,9 @@ function i18nstrings_context_query($context, $alias = 's') { } /** - * Get location string from context + * Get location string from context. * - * Returns the location for the locale table for a string context + * Returns the location for the locale table for a string context. */ function i18nstrings_location($context) { if (is_string($context)){ @@ -569,22 +581,23 @@ function i18nstrings_location($context) { } /** - * Prefetch a number of object strings + * Prefetch a number of object strings. */ function i18nstrings_prefetch($context, $langcode = NULL, $join = array(), $conditions = array()) { global $language; $langcode = $langcode ? $langcode : $language->language; - // Add language condition + // Add language condition. $conditions['t.language'] = $langcode; - // Get context conditions + // Get context conditions. $context = (array)i18nstrings_context($context); foreach ($context as $key => $value) { if ($value) { if ($key == 'textgroup') { $conditions['s.textgroup'] = $value; - } else { - $conditions['i.'. $key] = $value; + } + else { + $conditions['i.' . $key] = $value; } } } @@ -592,9 +605,10 @@ function i18nstrings_prefetch($context, $langcode = NULL, $join = array(), $cond $where = $params = array(); foreach ($conditions as $key => $value) { if (is_array($value)) { - $where[] = $key . ' IN ('.db_placeholders($value, is_int($value[0]) ? 'int' : 'string').')'; + $where[] = $key . ' IN (' . db_placeholders($value, is_int($value[0]) ? 'int' : 'string') . ')'; $params = array_merge($params, $value); - } else { + } + else { $where[] = $key . ' = ' . is_int($value) ? '%d' : "'%s'"; $params[] = $value; } @@ -604,7 +618,7 @@ function i18nstrings_prefetch($context, $langcode = NULL, $join = array(), $cond $sql .= implode(' ', $join) . ' ' . implode (' AND ', $where); $result = db_query($sql, $params); - // Fetch all rows and store in cache + // Fetch all rows and store in cache. while ($t = db_fetch_object($result)) { i18nstrings_cache($t, $langcode, $t->source, $t->translation); } @@ -620,20 +634,23 @@ function i18nstrings_cache($context, $langcode, $string = NULL, $translation = N $context = i18nstrings_context($context, $string); if (!$context->objectid && $context->source) { - // This is a type indexed by string + // This is a type indexed by string. $context->objectid = $context->source; } - // At this point context must have at least textgroup and type + // At this point context must have at least textgroup and type. if ($translation) { if ($context->property) { $strings[$langcode][$context->textgroup][$context->type][$context->objectid][$context->property] = $translation; - } elseif ($context->objectid) { + } + elseif ($context->objectid) { $strings[$langcode][$context->textgroup][$context->type][$context->objectid] = $translation; - } else { + } + else { $strings[$langcode][$context->textgroup][$context->type] = $translation; } - } else { - // Search up the tree for the object or a default + } + else { + // Search up the tree for the object or a default. $search = &$strings[$langcode]; $default = NULL; $list = array('textgroup', 'type', 'objectid', 'property'); @@ -643,19 +660,20 @@ function i18nstrings_cache($context, $langcode, $string = NULL, $translation = N if (isset($search['#default'])) { $default = $search['#default']; } - } else { - // We dont have cached this tree so we return the default + } + else { + // We dont have cached this tree so we return the default. return $default; } } - // Returns the part of the array we got to + // Returns the part of the array we got to. return $search; } } /** - * Callback for menu title translation + * Callback for menu title translation. */ function i18nstrings_title_callback($name, $string, $callback = NULL) { $string = tt($name, $string); @@ -664,4 +682,3 @@ function i18nstrings_title_callback($name, $string, $callback = NULL) { } return $string; } - diff --git a/i18nsync/README.txt b/i18nsync/README.txt index a480ba84197ad7a873842b41fc66376a0bdc1da9..8b96419304930fdf7ff62ffb0ab8b79f4aaaaedf 100644 --- a/i18nsync/README.txt +++ b/i18nsync/README.txt @@ -1,3 +1,5 @@ +// $Id$ + README.txt ========== Drupal module: i18nsync (Synchronization) @@ -7,15 +9,15 @@ This module will handle content synchronization accross translations. The available list of fields to synchronize will include standard node fields and cck fields. To have aditional fields, add the list in a variable in the settings.php file, like this: -// Available fields for synchronization, for all node types +// Available fields for synchronization, for all node types. $conf['i18nsync_fields_node'] = array( 'field1' => t('Field 1 name'), 'field2' => t('Field 2 name'), - ....................... + ... ); -// More fields for a specific content type 'nodetype' only +// More fields for a specific content type 'nodetype' only. $conf['i18nsync_fields_node_nodetype'] = array( 'field3' => t('Field 3 name'), - ....... + ... ); \ No newline at end of file diff --git a/i18nsync/i18nsync.install b/i18nsync/i18nsync.install index f7a0fc6ce7b6cacd23376257962f45cb93097d03..75315d54fc67696069503f5acdf997fd075ddd4f 100644 --- a/i18nsync/i18nsync.install +++ b/i18nsync/i18nsync.install @@ -1,6 +1,13 @@ '.t('This module synchronizes content taxonomy and fields accross translations:').'

'; - $output .= '

'.t('First you need to select which fields should be synchronized. Then, after a node has been updated, all enabled vocabularies and fields will be synchronized as follows:').'

'; + $output = '

' . t('This module synchronizes content taxonomy and fields accross translations:') . '

'; + $output .= '

' . t('First you need to select which fields should be synchronized. Then, after a node has been updated, all enabled vocabularies and fields will be synchronized as follows:') . '

'; $output .= ''; - $output .= '

'.t('Note that permissions are not checked for each node. So if someone can edit a node and it is set to synchronize, all the translations will be synchronized anyway.').'

'; - $output .= '

'.t('To enable synchronization check content type options to select which fields to synchronize for each node type').'

'; - $output .= '

'.t('The list of available fields for synchronization will include some standard node fields and all CCK fields. You can add more fields to the list in a configuration variable. See README.txt for how to do it.').'

'; + $output .= '

' . t('Note that permissions are not checked for each node. So if someone can edit a node and it is set to synchronize, all the translations will be synchronized anyway.') . '

'; + $output .= '

' . t('To enable synchronization check content type options to select which fields to synchronize for each node type') . '

'; + $output .= '

' . t('The list of available fields for synchronization will include some standard node fields and all CCK fields. You can add more fields to the list in a configuration variable. See README.txt for how to do it.') . '

'; $output .= '

'. t('For more information, see the online handbook entry for Internationalization module.', array('@i18n' => 'http://drupal.org/node/133977')) .'

'; return $output; } } /** - * Implementation of hook_theme() + * Implementation of hook_theme(). */ function i18nsync_theme() { return array( @@ -54,14 +54,15 @@ function i18nsync_theme() { * - Content type options */ function i18nsync_form_alter(&$form, $form_state, $form_id) { - // Taxonomy vocabulary form + // Taxonomy vocabulary form. switch ($form_id) { case 'node_type_form': $type = $form['#node_type']->type; $current = i18nsync_node_fields($type); $form['workflow']['i18n']['i18nsync_nodeapi'] = array( - '#type' => 'fieldset', '#tree' => TRUE, + '#type' => 'fieldset', + '#tree' => TRUE, '#title' => t('Synchronize translations'), '#collapsible' => TRUE, '#collapsed' => !count($current), @@ -90,10 +91,10 @@ function i18nsync_form_alter(&$form, $form_state, $form_id) { } /** - * Theming function for workflow checkboxes + * Theming function for workflow checkboxes. */ function theme_i18nsync_workflow_checkbox($element){ - $output = $element['#group_title'] ? '
'.$element['#group_title'].'
' : ''; + $output = $element['#group_title'] ? '
' . $element['#group_title'] . '
' : ''; $output .= theme('checkbox', $element); return $output; } @@ -102,17 +103,18 @@ function theme_i18nsync_workflow_checkbox($element){ * Implementation of hook_nodeapi(). */ function i18nsync_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { - global $i18nsync; // This variable will be true when a sync operation is in progress + global $i18nsync; // This variable will be true when a sync operation is in progress. // Only for nodes that have language and belong to a translation set. - if (translation_supported_type($node->type) && !empty($node->language) && !$i18nsync) { + if (translation_supported_type($node->type) && !empty($node->language) && !$i18nsync) { switch ($op) { case 'prepare translation': - // We copy over all the fields to be synchronized + // We copy over all the fields to be synchronized. if ($fields = i18nsync_node_fields($node->type)) { i18nsync_prepare_translation($node, $node->translation_source, $fields); } break; + case 'insert': // When creating a translation, there are some aditional steps, different from update if (!empty($node->translation_source)) { @@ -128,8 +130,9 @@ function i18nsync_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { } } } - // Intentional no break + case 'update': + // Intentional no break. // Let's go with field synchronization. if (!empty($node->tnid) && ($fields = i18nsync_node_fields($node->type)) && ($translations = translation_node_get_translations($node->tnid)) && count($translations) > 1) { $i18nsync = TRUE; @@ -147,7 +150,7 @@ function i18nsync_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) { } /** - * Prepare node translation. Copy over sincronizable fields + * Prepare node translation. Copy over sincronizable fields. */ function i18nsync_prepare_translation(&$node, $source, $field_list){ foreach ($field_list as $field) { @@ -156,6 +159,7 @@ function i18nsync_prepare_translation(&$node, $source, $field_list){ case 'taxonomy': i18nsync_taxonomyfield($node, $source); break; + default: $node->$field = $source->$field; break; @@ -164,33 +168,33 @@ function i18nsync_prepare_translation(&$node, $source, $field_list){ } /** - * Synchronizes fields for node translation + * Synchronizes fields for node translation. * * There's some specific handling for known fields like: - * - files, for file attachments - * - iid (CCK node attachments, translations for them will be handled too) + * - files, for file attachments. + * - iid (CCK node attachments, translations for them will be handled too). * * All the rest of the fields will be just copied over. - * The 'revision' field will have the special effect of creating a revision too for the translation + * The 'revision' field will have the special effect of creating a revision too for the translation. * * @param $node - * Source node being edited + * Source node being edited. * @param $translation - * Node translation to synchronize, just needs nid property + * Node translation to synchronize, just needs nid property. * @param $fields - * List of fields to synchronize + * List of fields to synchronize. * @param $op - * Node operation (insert|update) + * Node operation (insert|update). */ function i18nsync_node_translation($node, $translation, $fields, $op) { - // Load full node, we need all data here + // Load full node, we need all data here. $translation = node_load($translation->nid); // Collect info on any CCK fields. $content = module_invoke('content', 'types', $node->type); foreach ($fields as $field) { - // Check for CCK fields first + // Check for CCK fields first. if (isset($content['fields'][$field])) { switch ($content['fields'][$field]['type']) { // TODO take type specific actions. @@ -199,7 +203,7 @@ function i18nsync_node_translation($node, $translation, $fields, $op) { break; default: - // For fields that don't need special handling + // For fields that don't need special handling. if (isset($node->$field)) { $translation->$field = $node->$field; } @@ -209,37 +213,41 @@ function i18nsync_node_translation($node, $translation, $fields, $op) { } else { switch($field) { - case 'taxonomy': // Do nothing it has already been syncd + case 'taxonomy': // Do nothing it has already been syncd. i18nsync_taxonomyfield($translation, $node); break; - case 'parent': // Book outlines, translating parent page if exists - case 'iid': // Attached image nodes + + case 'parent': // Book outlines, translating parent page if exists. + case 'iid': // Attached image nodes. i18nsync_node_translation_attached_node($node, $translation, $field); break; + case 'files': - // Sync existing attached files + // Sync existing attached files. foreach ((array)$node->files as $fid => $file) { if (isset($translation->files[$fid])) { $translation->files[$fid]->list = $file->list; - } else { - // New file. Create new revision of file for the translation + } + else { + // New file. Create new revision of file for the translation. $translation->files[$fid] = $file; // If it's a new node revision it will just be created, but if it's not - // we have to update the table directly. The revision field was before this one in the list + // we have to update the table directly. The revision field was before this one in the list. if (!isset($translation->revision) || !$translation->revision) { db_query("INSERT INTO {upload} (fid, nid, vid, list, description) VALUES (%d, %d, %d, %d, '%s')", $file->fid, $translation->nid, $translation->vid, $file->list, $file->description); } } } - // Drop removed files + // Drop removed files. foreach ((array)$translation->files as $fid => $file) { if (!isset($node->files[$fid])) { $translation->files[$fid]->remove = TRUE; } } break; + default: - // For fields that don't need special handling + // For fields that don't need special handling. if (isset($node->$field)) { $translation->$field = $node->$field; } @@ -250,65 +258,69 @@ function i18nsync_node_translation($node, $translation, $fields, $op) { } /** - * Synchronize taxonomy + * Synchronize taxonomy. * - * Translate translatable terms, just copy over the rest + * Translate translatable terms, just copy over the rest. */ function i18nsync_taxonomyfield(&$node, $source) { if (module_exists('i18ntaxonomy')) { $node->taxonomy = i18ntaxonomy_translate_terms($source->taxonomy, $node->language); - } else { - // If not multilingual taxonomy enabled, just copy over + } + else { + // If not multilingual taxonomy enabled, just copy over. $node->taxonomy = $source->taxonomy; } } + /** - * Node attachments (CCK) that may have translation + * Node attachments (CCK) that may have translation. */ function i18nsync_node_translation_attached_node(&$node, &$translation, $field) { if (isset($node->$field) && $attached = node_load($node->$field)) { if (translation_supported_type($attached->type)) { - // This content type has translations, find the one + // This content type has translations, find the one. if (($attachedtrans = translation_node_get_translations($attached)) && isset($attachedtrans[$translation->language])) { $translation->$field = $attachedtrans[$translation->language]->nid; } - } else { - // Content type without language, just copy the nid + } + else { + // Content type without language, just copy the nid. $translation->$field = $node->$field; } } } /** - * Returns list of fields to synchronize for a given content type + * Returns list of fields to synchronize for a given content type. * * @param $type - * Node type + * Node type. */ function i18nsync_node_fields($type) { return variable_get('i18nsync_nodeapi_'.$type, array()); } + /** - * Returns list of available fields for given content type + * Returns list of available fields for given content type. * * @param $type - * Node type + * Node type. * @param $tree - * Whether to return in tree form or FALSE for flat list + * Whether to return in tree form or FALSE for flat list. */ function i18nsync_node_available_fields($type) { - // Default node fields + // Default node fields. $fields['node']['#title'] = t('Standard node fields.'); $options = variable_get('i18nsync_fields_node', array()); $options += array( - 'author' => t('Author'), - 'status' => t('Status'), - 'promote' => t('Promote'), - 'moderate' => t('Moderate'), - 'sticky' => t('Sticky'), - 'revision' => t('Revision (Create also new revision for translations)'), - 'parent' => t('Book outline (with the translated parent)'), - 'taxonomy' => t('Taxonomy terms'), + 'author' => t('Author'), + 'status' => t('Status'), + 'promote' => t('Promote'), + 'moderate' => t('Moderate'), + 'sticky' => t('Sticky'), + 'revision' => t('Revision (Create also new revision for translations)'), + 'parent' => t('Book outline (with the translated parent)'), + 'taxonomy' => t('Taxonomy terms'), ); if (module_exists('comment')) { $options['comment'] = t('Comment settings'); @@ -316,22 +328,22 @@ function i18nsync_node_available_fields($type) { if (module_exists('upload') || module_exists('image')) { $options['files'] = t('File attachments'); } - // If no type defined yet, that's it + // If no type defined yet, that's it. $fields['node']['#options'] = $options; if (!$type) { return $fields; } - // Get variable for this node type + // Get variable for this node type. $fields += variable_get("i18nsync_fields_node_$type", array()); - // Image attach - if (variable_get('image_attach_'. $type, 0)) { + // Image attach. + if (variable_get('image_attach_' . $type, 0)) { $fields['image']['#title'] = t('Image Attach module'); $fields['image']['#options']['iid'] = t('Attached image nodes'); } - // Event fields - if (variable_get('event_nodeapi_'. $type, 'never') != 'never') { + // Event fields. + if (variable_get('event_nodeapi_' . $type, 'never') != 'never') { $fields['event']['#title'] = t('Event fields'); $fields['event']['#options'] = array( 'event_start' => t('Event start'), @@ -340,9 +352,9 @@ function i18nsync_node_available_fields($type) { ); } - // Get CCK fields + // Get CCK fields. if (($content = module_invoke('content', 'types', $type)) && isset($content['fields'])) { - // Get context information + // Get context information. $info = module_invoke('content', 'fields', NULL, $type); $fields['cck']['#title'] = t('CCK fields'); foreach ($content['fields'] as $name => $data) { @@ -354,7 +366,7 @@ function i18nsync_node_available_fields($type) { } /* - * Sample CCK field definition for Drupal 5 + * Sample CCK field definition for Drupal 5. 'field_text' => array 'field_name' => string 'field_text' (length=10) diff --git a/i18ntaxonomy/i18ntaxonomy.admin.inc b/i18ntaxonomy/i18ntaxonomy.admin.inc index 206312214cdc99ff12366829553419971e79db3d..fe495af11f9c771819352a6f6f975c5343b6cc20 100644 --- a/i18ntaxonomy/i18ntaxonomy.admin.inc +++ b/i18ntaxonomy/i18ntaxonomy.admin.inc @@ -3,17 +3,17 @@ /** * @file - * Helper functions for taxonomy administration + * Helper functions for taxonomy administration. */ - /** - * This is the callback for taxonomy translations +/** + * This is the callback for taxonomy translations. * * Gets the urls: - * admin/content/taxonomy/%taxonomy_vocabulary/translation' + * admin/content/taxonomy/%taxonomy_vocabulary/translation * admin/content/taxonomy/i18n/term/xx - * admin/content/taxonomy/i18n/term/new/xx - * admin/content/taxonomy/vid/translation/op/trid + * admin/content/taxonomy/i18n/term/new/xx + * admin/content/taxonomy/vid/translation/op/trid */ function i18ntaxonomy_page_vocabulary($vocabulary, $op = NULL, $tid = NULL) { switch ($op) { @@ -21,6 +21,7 @@ function i18ntaxonomy_page_vocabulary($vocabulary, $op = NULL, $tid = NULL) { drupal_set_title(t('Edit term translations')); $output = drupal_get_form('i18ntaxonomy_translation_term_form', $vocabulary->vid, $tid); break; + default: $output = i18ntaxonomy_translation_overview($vocabulary->vid); } @@ -28,21 +29,28 @@ function i18ntaxonomy_page_vocabulary($vocabulary, $op = NULL, $tid = NULL) { } /** - * Produces a vocabulary translation form + * Produces a vocabulary translation form. */ function i18ntaxonomy_translation_term_form($form_state, $vid, $trid = NULL, $edit = array()) { $languages = i18n_supported_languages(); if ($trid == 'new') { $translations = array(); - $form['trid'] = array('#type' => 'hidden', '#value' => 0); - } else { - $form['trid'] = array('#type' => 'hidden', '#value' => $trid); + $form['trid'] = array( + '#type' => 'hidden', + '#value' => 0 + ); + } + else { + $form['trid'] = array( + '#type' => 'hidden', + '#value' => $trid + ); $translations = i18ntaxonomy_term_get_translations(array('trid' =>$trid)); } //var_dump($translations); $vocabulary = taxonomy_vocabulary_load($vid); - // List of terms for languages + // List of terms for languages. foreach ($languages as $lang => $langname) { $current = isset($translations[$lang]) ? $translations[$lang]->tid : ''; $list = i18ntaxonomy_vocabulary_get_terms($vid, $lang, 'all'); @@ -54,18 +62,30 @@ function i18ntaxonomy_translation_term_form($form_state, $vid, $trid = NULL, $ed '#default_value' => $current, '#options' => $list, ); - $form[$lang]['old'] = array('#type' => 'hidden', '#value' => $current); + $form[$lang]['old'] = array( + '#type' => 'hidden', + '#value' => $current + ); } - $form['submit'] = array('#type' => 'submit', '#value' => t('Save')); + $form['submit'] = array( + '#type' => 'submit', + '#value' => t('Save') + ); if ($trid != 'new') { - $form['delete'] = array('#type' => 'submit', '#value' => t('Delete')); + $form['delete'] = array( + '#type' => 'submit', + '#value' => t('Delete') + ); } - $form['destination'] = array('#type' => 'hidden', '#value' => 'admin/content/taxonomy/'.arg(3).'/translation'); + $form['destination'] = array( + '#type' => 'hidden', + '#value' => 'admin/content/taxonomy/' . arg(3) . '/translation' + ); return $form; } /** - * Form callback: Process vocabulary translation form + * Form callback: Process vocabulary translation form. */ function i18ntaxonomy_translation_term_form_submit($form, &$form_state) { switch ($form_state['values']['op']) { @@ -73,8 +93,9 @@ function i18ntaxonomy_translation_term_form_submit($form, &$form_state) { i18ntaxonomy_translation_save($form_state['values'], $form_state['values']['trid']); drupal_set_message(t('Term translations have been updated.')); break; + case t('Delete'): - // Delete old translations for this trid + // Delete old translations for this trid. db_query("UPDATE {term_data} SET trid = 0 WHERE trid = %d", $form_state['values']['trid']); drupal_set_message(t('The term translation has been deleted.')); break; @@ -82,26 +103,26 @@ function i18ntaxonomy_translation_term_form_submit($form, &$form_state) { } /** - * Save taxonomy term translations + * Save taxonomy term translations. * * @param $terms - * Array of terms indexed by language + * Array of terms indexed by language. * @param $trid - * Optional translation set id + * Optional translation set id. */ function i18ntaxonomy_translation_save($terms, $trid = 0) { - // Delete old translations for this trid + // Delete old translations for this trid. if ($trid){ db_query("UPDATE {term_data} SET trid = 0 WHERE trid = %d", $trid); } - // Now pick up all the tids in an array + // Now pick up all the tids in an array. $translations = array(); foreach (i18n_supported_languages() as $lang => $name) { if (isset($terms[$lang]) && ($term = (array)$terms[$lang]) && $tid = $term['tid']) { $translations[$lang] = $tid; } } - // Now set a translation set with all these terms. We need some table locking to avoid race conditions + // Now set a translation set with all these terms. We need some table locking to avoid race conditions. // when other translations created simulaneously. @TODO Find a better way. if (count($translations)) { db_query('LOCK TABLES {term_data} WRITE'); @@ -112,8 +133,6 @@ function i18ntaxonomy_translation_save($terms, $trid = 0) { } } - - /** * Get next free trid. */ @@ -134,7 +153,7 @@ function i18ntaxonomy_translation_overview($vid) { $header = array_merge($languages, array(t('Operations'))); $links = array(); $types = array(); - // Get terms/translations for this vocab + // Get terms/translations for this vocab. $result = db_query('SELECT * FROM {term_data} t WHERE vid = %d', $vocabulary->vid); $terms = $messages = array(); while ($term = db_fetch_object($result)) { @@ -142,17 +161,17 @@ function i18ntaxonomy_translation_overview($vid) { $terms[$term->trid][$term->language] = $term; } } - // Reorder data for rows and languages + // Reorder data for rows and languages. $rows = array(); foreach ($terms as $trid => $terms) { $thisrow = array(); foreach ($languages as $lang => $name) { if (array_key_exists($lang, $terms)) { - $thisrow[] = l($terms[$lang]->name, 'taxonomy/term/'.$terms[$lang]->tid); - } - else { + $thisrow[] = l($terms[$lang]->name, 'taxonomy/term/' . $terms[$lang]->tid); + } + else { $thisrow[] = '--'; - } + } } $thisrow[] = l(t('edit'), "admin/content/taxonomy/$vid/translation/edit/$trid"); $rows[] = $thisrow; diff --git a/i18ntaxonomy/i18ntaxonomy.install b/i18ntaxonomy/i18ntaxonomy.install index 8ba14c064b23c83c2d6831467eeabbf45c057a40..bbae305eecd8638ae8e5e69359fc71aa4f73755c 100644 --- a/i18ntaxonomy/i18ntaxonomy.install +++ b/i18ntaxonomy/i18ntaxonomy.install @@ -1,8 +1,14 @@ 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')); db_add_field($ret, 'term_data', 'language', array('type' => 'varchar', 'length' => 12, 'not null' => TRUE, 'default' => '')); db_add_field($ret, 'term_data', 'trid', array('type' => 'int', 'not null' => TRUE, 'default' => 0)); - // Set module weight for it to run after core modules + + // Set module weight for it to run after core modules. db_query("UPDATE {system} SET weight = 10 WHERE name = 'i18ntaxonomy' AND type = 'module'"); } /** - * Implementation of hook_enable() + * Implementation of hook_enable(). * - * Just add strings to locale tables + * Just add strings to locale tables. */ function i18ntaxonomy_enable() { i18ntaxonomy_locale_refresh(); } /** - * Drupal 6 update + * Drupal 6 update. * - * Move i18n vocabulary options to new variables + * Move i18n vocabulary options to new variables. */ function i18ntaxonomy_update_1() { $items = array(); @@ -35,20 +42,23 @@ function i18ntaxonomy_update_1() { foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) { if ($vocabulary->language) { $options[$vid] = I18N_TAXONOMY_LANGUAGE; - } elseif (isset($translate[$vid]) && $translate[$vid]) { + } + elseif (isset($translate[$vid]) && $translate[$vid]) { $options[$vid] = I18N_TAXONOMY_LOCALIZE; - } else { - // Search for terms with language + } + else { + // Search for terms with language. $count = db_result(db_query("SELECT COUNT(language) FROM {term_data} WHERE vid = %d AND NOT language = ''", $vid)); if ($count) { $options[$vid] = I18N_TAXONOMY_TRANSLATE; - } elseif (!isset($options[$vid])) { + } + elseif (!isset($options[$vid])) { $options[$vid] = I18N_TAXONOMY_NONE; } } } variable_set('i18ntaxonomy_vocabulary', $options); drupal_set_message(t('The multilingual vocabulary settings have been updated. Please review them in the taxonomy administration.', array('@taxonomy_admin' => url('admin/content/taxonomy')))); - // @ TODO Update strings in localization tables + // @ TODO Update strings in localization tables. return $items; } diff --git a/i18ntaxonomy/i18ntaxonomy.module b/i18ntaxonomy/i18ntaxonomy.module index 72191999fab5fa5e520b34083eef0aaee383032a..f9d91da865e80c3f8c7c54f985715f7f63c37810 100644 --- a/i18ntaxonomy/i18ntaxonomy.module +++ b/i18ntaxonomy/i18ntaxonomy.module @@ -3,21 +3,21 @@ /** * @file - * i18n taxonomy module + * i18n taxonomy module * - * Internationalization (i18n) package + * Internationalization (i18n) package. * * This module groups together all existing i18n taxonomy functionality - * providing several options for taxonomy translation + * providing several options for taxonomy translation. * - * Translates taxonomy term for selected vocabularies running them through the localization system - * It also translates terms for views filters and views results + * Translates taxonomy term for selected vocabularies running them through the localization system. + * It also translates terms for views filters and views results. * * @author Jose A. Reyero, 2004 */ /** - * Modes for multilingual vocabularies + * Modes for multilingual vocabularies. */ // No multilingual options define('I18N_TAXONOMY_NONE', 0); @@ -31,30 +31,34 @@ define('I18N_TAXONOMY_TRANSLATE', 3); /** * Implementation of hook_help(). */ -function i18ntaxonomy_help($section, $arg) { - switch ($section) { +function i18ntaxonomy_help($path, $arg) { + switch ($path) { case 'admin/help#i18ntaxonomy' : - $output = '

' .t('This module adds support for multilingual taxonomy. You can set up multilingual options for each vocabulary:').'

'; + $output = '

' . t('This module adds support for multilingual taxonomy. You can set up multilingual options for each vocabulary:') . '

'; $output .= ''; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; $output .= '

'. t('For more information, see the online handbook entry for Internationalization module.', array('@i18n' =>'http://drupal.org/node/133977')) . '

'; return $output; + case 'admin/settings/i18n': $output = ''; return $output; + case 'admin/content/taxonomy/%': $vocabulary = taxonomy_vocabulary_load($arg[3]); switch (i18ntaxonomy_vocabulary($vocabulary->vid)) { case I18N_TAXONOMY_LOCALIZE: - return '

'. t('%capital_name is a localizable vocabulary. You will be able to translate term names and descriptions using the localization interface.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '

'; + return '

' . t('%capital_name is a localizable vocabulary. You will be able to translate term names and descriptions using the localization interface.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name)) . '

'; + case I18N_TAXONOMY_LANGUAGE: return '

' . t('%capital_name is a vocabulary with a fixed language. All the terms in this vocabulary will have %language language.', array('%capital_name' => drupal_ucfirst($vocabulary->name), '%name' => $vocabulary->name, '%language' => i18n_language_property($vocabulary->language, 'name'))) . '

'; + case I18N_TAXONOMY_TRANSLATE: return '

' . t('%capital_name is a full multilingual vocabulary. You will be able to set a language for each term and create translation relationships.', array('%capital_name' => drupal_ucfirst($vocabulary->name))) . '

'; } @@ -63,7 +67,7 @@ function i18ntaxonomy_help($section, $arg) { } /** - * Returns list of vocabulary modes + * Returns list of vocabulary modes. */ function _i18ntaxonomy_vocabulary_options() { return array( @@ -73,6 +77,7 @@ function _i18ntaxonomy_vocabulary_options() { I18N_TAXONOMY_LANGUAGE => t('Set language to vocabulary. The vocabulary will have a global language and it will only show up for pages in that language.'), ); } + /** * Implementation of hook_menu(). */ @@ -96,10 +101,11 @@ function i18ntaxonomy_menu() { * Take over the taxonomy pages */ function i18ntaxonomy_menu_alter(&$items) { - // Taxonomy term page. Localize terms + // Taxonomy term page. Localize terms. $items['taxonomy/term/%']['module'] = 'i18ntaxonomy'; $items['taxonomy/term/%']['page callback'] = 'i18ntaxonomy_term_page'; $items['taxonomy/term/%']['file'] = 'i18ntaxonomy.pages.inc'; + // Localize autocomplete $items['taxonomy/autocomplete']['module'] = 'i18ntaxonomy'; $items['taxonomy/autocomplete']['page callback'] = 'i18ntaxonomy_autocomplete'; @@ -107,7 +113,7 @@ function i18ntaxonomy_menu_alter(&$items) { } /** - * Menu access callback. Show tab only for full multilingual vocabularies + * Menu access callback. Show tab only for full multilingual vocabularies. */ function _i18ntaxonomy_translation_tab($vocabulary) { return i18ntaxonomy_vocabulary($vocabulary->vid) == I18N_TAXONOMY_TRANSLATE; @@ -120,6 +126,7 @@ function i18ntaxonomy_locale($op = 'groups', $group = NULL) { switch ($op) { case 'groups': return array('taxonomy' => t('Taxonomy')); + case 'refresh': if ($group == 'taxonomy') { return i18ntaxonomy_locale_refresh(); @@ -128,7 +135,7 @@ function i18ntaxonomy_locale($op = 'groups', $group = NULL) { } /** - * Refresh strings + * Refresh strings. */ function i18ntaxonomy_locale_refresh() { foreach (taxonomy_get_vocabularies() as $vid => $vocabulary) { @@ -153,7 +160,7 @@ function i18ntaxonomy_locale_refresh() { * Replaces links with pointers to translated versions of the content. */ function i18ntaxonomy_translation_link_alter(&$links, $path) { - if (preg_match("/^(taxonomy\/term\/)([^\/]*)(.*)$/", $path, $matches)) {//or at a taxonomy-listing? + if (preg_match("/^(taxonomy\/term\/)([^\/]*)(.*)$/", $path, $matches)) { //or at a taxonomy-listing? foreach ($links as $langcode => $link) { if ($str_tids = i18ntaxonomy_translation_tids($matches[2], $langcode)) { $links[$langcode]['href'] = "taxonomy/term/$str_tids". $matches[3]; @@ -163,16 +170,16 @@ function i18ntaxonomy_translation_link_alter(&$links, $path) { } /** - * Get translated term's tid + * Get translated term's tid. * * @param $tid - * Node nid to search for translation + * Node nid to search for translation. * @param $language - * Language to search for the translation, defaults to current language + * Language to search for the translation, defaults to current language. * @param $default - * Value that will be returned if no translation is found + * Value that will be returned if no translation is found. * @return - * Translated term tid if exists, or $default + * Translated term tid if exists, or $default. */ function i18ntaxonomy_translation_term_tid($tid, $language = NULL, $default = NULL) { $translation = db_result(db_query("SELECT t.tid FROM {term_data} t INNER JOIN {term_data} a ON t.trid = a.trid AND t.tid <> a.tid WHERE a.tid = %d AND t.language = '%s' AND t.trid > 0", $tid, $language ? $language : i18n_get_lang())); @@ -180,7 +187,7 @@ function i18ntaxonomy_translation_term_tid($tid, $language = NULL, $default = NU } /** - * Returns an url for the translated taxonomy-page, if exists + * Returns an url for the translated taxonomy-page, if exists. */ function i18ntaxonomy_translation_tids($str_tids, $lang) { if (preg_match('/^([0-9]+[+ ])+[0-9]+$/', $str_tids)) { @@ -188,7 +195,7 @@ function i18ntaxonomy_translation_tids($str_tids, $lang) { // The '+' character in a query string may be parsed as ' '. $tids = preg_split('/[+ ]/', $str_tids); } - else if (preg_match('/^([0-9]+,)*[0-9]+$/', $str_tids)) { + elseif (preg_match('/^([0-9]+,)*[0-9]+$/', $str_tids)) { $separator = ','; $tids = explode(',', $str_tids); } @@ -203,8 +210,9 @@ function i18ntaxonomy_translation_tids($str_tids, $lang) { } return implode($separator, $translated_tids); } + /** - * Implementation of hook_taxonomy + * Implementation of hook_taxonomy. * * $edit parameter may be an array or an object !! */ @@ -216,22 +224,23 @@ function i18ntaxonomy_taxonomy($op, $type, $edit = NULL) { $tid = $edit['tid']; $language = isset($edit['language']) ? $edit['language'] : ''; db_query("UPDATE {term_data} SET language='%s' WHERE tid=%d", $language, $tid); - // From translation module + // From translation module. if (!$language && !empty($edit['trid'])) { // Removed language, remove trid db_query('UPDATE {term_data} SET trid = 0 WHERE tid = %d', $tid); if (db_affected_rows()) drupal_set_message(t('Removed translation information from term.')); } - // Update strings for localizable vocabulary + // Update strings for localizable vocabulary. if (i18ntaxonomy_vocabulary($edit['vid']) == I18N_TAXONOMY_LOCALIZE) { tt("taxonomy:term:$tid:name", $edit['name'], NULL, TRUE); tt("taxonomy:term:$tid:description", $edit['description'], NULL, TRUE); } break; + case 'vocabulary/insert': case 'vocabulary/update': $vid = $edit['vid']; - // Update vocabulary settings + // Update vocabulary settings. if (isset($edit['i18nmode'])) { i18ntaxonomy_vocabulary($vid, $edit['i18nmode']); @@ -241,7 +250,7 @@ function i18ntaxonomy_taxonomy($op, $type, $edit = NULL) { db_query("UPDATE {term_data} SET language='%s' WHERE vid = %d", $edit['language'], $edit['vid']); drupal_set_message(t('Reset language for all terms.')); } - // Always add vocabulary translation if !$language + // Always add vocabulary translation if !$language. if (!$language) { tt("taxonomy:vocabulary:$vid:name", $edit['name'], NULL, TRUE); } @@ -251,20 +260,20 @@ function i18ntaxonomy_taxonomy($op, $type, $edit = NULL) { } /** - * Implementation of hook_db_rewrite_sql() + * Implementation of hook_db_rewrite_sql(). */ function i18ntaxonomy_db_rewrite_sql($query, $primary_table, $primary_key){ - // No rewrite for administration pages or mode = off + // No rewrite for administration pages or mode = off. $mode = i18n_selection_mode(); if ($mode == 'off' || arg(0) == 'admin') return; switch ($primary_table) { case 't': case 'v': - // Taxonomy queries - // When loading specific terms, vocabs, language conditions shouldn't apply + // Taxonomy queries. + // When loading specific terms, vocabs, language conditions shouldn't apply. if (preg_match("/WHERE.* $primary_table\.tid\s*(=\s*\d|IN)/", $query)) return; - // Taxonomy for specific node, or when using the term_node table + // Taxonomy for specific node, or when using the term_node table. if (preg_match("/WHERE r\.nid = \%d/", $query)) return; if (preg_match("/{term_node}/", $query)) return; $result['where'] = i18n_db_rewrite_where($primary_table, 'taxonomy', $mode); @@ -273,11 +282,11 @@ function i18ntaxonomy_db_rewrite_sql($query, $primary_table, $primary_key){ } /** - * Implementation of hook_form_alter + * Implementation of hook_form_alter(). * - * This is the place to add language fields to all forms + * This is the place to add language fields to all forms. * - * @ TO DO The vocabulary form needs some javascript + * @ TO DO The vocabulary form needs some javascript. */ function i18ntaxonomy_form_alter(&$form, $form_state, $form_id) { switch ($form_id) { @@ -286,26 +295,29 @@ function i18ntaxonomy_form_alter(&$form, $form_state, $form_id) { $languages = locale_language_list('name'); foreach ($vocabularies as $vocabulary) { if ($vocabulary->language) { - $form[$vocabulary->vid]['types']['#value'] .= ' ('.$languages[$vocabulary->language].')'; + $form[$vocabulary->vid]['types']['#value'] .= ' (' . $languages[$vocabulary->language] . ')'; } } break; + case 'taxonomy_overview_terms': $mode = i18ntaxonomy_vocabulary($form['#vocabulary']['vid']); if ($mode == I18N_TAXONOMY_TRANSLATE) { $languages = locale_language_list('name'); foreach (element_children($form) as $key) { if (isset($form[$key]['#term']) && ($lang = $form[$key]['#term']['language'])) { - $form[$key]['view']['#value'] .= ' ('.$languages[$lang].')'; + $form[$key]['view']['#value'] .= ' (' . $languages[$lang] . ')'; } } } break; + case 'taxonomy_form_vocabulary': // Taxonomy vocabulary if (!empty($form['vid']['#value'])) { $vocabulary = taxonomy_vocabulary_load($form['vid']['#value']); $mode = i18ntaxonomy_vocabulary($vocabulary->vid); - } else { + } + else { $vocabulary = NULL; $mode = I18N_TAXONOMY_NONE; } @@ -320,7 +332,7 @@ function i18ntaxonomy_form_alter(&$form, $form_state, $form_id) { '#title' => t('Translation mode'), '#options' => _i18ntaxonomy_vocabulary_options(), '#default_value' => $mode, - '#description' => t('For localizable vocabularies, to have all terms available for translation visit the translation refresh page.', array('!locale-refresh' => url('admin/build/translate/refresh'))), + '#description' => t('For localizable vocabularies, to have all terms available for translation visit the translation refresh page.', array('@locale-refresh' => url('admin/build/translate/refresh'))), ); $form['i18n']['language'] = array( '#type' => 'select', @@ -335,7 +347,7 @@ function i18ntaxonomy_form_alter(&$form, $form_state, $form_id) { case 'taxonomy_form_term': // Taxonomy term $vocabulary = (object)$form['#vocabulary']; $term = (object)$form['#term']; - // Add language field or not depending on taxonomy mode + // Add language field or not depending on taxonomy mode. switch (i18ntaxonomy_vocabulary($vocabulary->vid)) { case I18N_TAXONOMY_TRANSLATE: $form['identification']['language'] = array( @@ -346,32 +358,36 @@ function i18ntaxonomy_form_alter(&$form, $form_state, $form_id) { '#description' => t('This term belongs to a multilingual vocabulary. You can set a language for it.'), ); break; + case I18N_TAXONOMY_LANGUAGE: $form['language'] = array('#type' => 'value', '#value' => $vocabulary->language); $form['identification']['language_info'] = array('#value' => t('All terms in this vocabulary have a fixed language: %language', array('%language' => i18n_language_property($vocabulary->language, 'name')))); break; + case I18N_TAXONOMY_LOCALIZE: $form['language'] = array('#type' => 'value', '#value' => ''); - $form['identification']['name']['#description'] .= ' '.t('This name will be localizable.').''; - $form['identification']['description']['#description'] .= ' '.t('This description will be localizable.').''; + $form['identification']['name']['#description'] .= ' ' . t('This name will be localizable.') .''; + $form['identification']['description']['#description'] .= ' ' . t('This description will be localizable.') . ''; break; + case I18N_TAXONOMY_NONE: default: $form['language'] = array('#type' => 'value', '#value' => ''); break; } break; + default: if (isset($form['type']) && $form['type']['#value'] .'_node_form' == $form_id && ($node = $form['#node']) && isset($form['taxonomy']) ) { - // Node form. Translate vocabularies + // Node form. Translate vocabularies. i18ntaxonomy_node_form($form); } } } /** - * Handle node form taxonomy + * Handle node form taxonomy. */ function i18ntaxonomy_node_form(&$form) { $node = $form['#node']; @@ -381,10 +397,10 @@ function i18ntaxonomy_node_form(&$form) { else { $terms = $node->taxonomy; } - // Regenerate the whole field for translatable vocabularies + // Regenerate the whole field for translatable vocabularies. foreach (element_children($form['taxonomy']) as $vid) { if (is_numeric($vid) && i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE) { - // Rebuild this vocabulary's form + // Rebuild this vocabulary's form. $vocabulary = taxonomy_vocabulary_load($vid); // Extract terms belonging to the vocabulary in question. $default_terms = array(); @@ -419,7 +435,9 @@ function i18ntaxonomy_vocabulary_form($vid, $value = 0, $help = NULL, $name = 't return _i18ntaxonomy_term_select(check_plain(tt("taxonomy:vocabulary:$vid:name", $vocabulary->name)), $name, $value, $vid, $help, intval($vocabulary->multiple), $blank); } -// Produces translated tree +/** + * Produces translated tree. + */ function _i18ntaxonomy_term_select($title, $name, $value, $vocabulary_id, $description, $multiple, $blank, $exclude = array()) { $tree = taxonomy_get_tree($vocabulary_id); $options = array(); @@ -437,7 +455,8 @@ function _i18ntaxonomy_term_select($title, $name, $value, $vocabulary_id, $descr } } - return array('#type' => 'select', + return array( + '#type' => 'select', '#title' => $title, '#default_value' => $value, '#options' => $options, @@ -448,17 +467,20 @@ function _i18ntaxonomy_term_select($title, $name, $value, $vocabulary_id, $descr '#theme' => 'taxonomy_term_select', ); } + /** - * Returns a list for terms for vocabulary, language + * Returns a list for terms for vocabulary, language. */ function i18ntaxonomy_vocabulary_get_terms($vid, $lang, $status = 'all') { switch($status) { case 'translated': $result = db_query("SELECT * FROM {term_data} WHERE vid = %d AND language = '%s' AND trid > 0", $vid, $lang); break; + case 'untranslated': $result = db_query("SELECT * FROM {term_data} WHERE vid = %d AND language = '%s' AND trid = 0", $vid, $lang); break; + default: $result = db_query("SELECT * FROM {term_data} WHERE vid = %d AND language = '%s'", $vid, $lang); break; @@ -471,22 +493,21 @@ function i18ntaxonomy_vocabulary_get_terms($vid, $lang, $status = 'all') { } /** - * Multilingual Taxonomy - * + * Multilingual Taxonomy. */ /** - * Get term translations + * Get term translations. * * @return - * An array of the from lang => Term + * An array of the from lang => Term. */ function i18ntaxonomy_term_get_translations($params, $getall = TRUE) { foreach ($params as $field => $value) { $conds[] = "i.$field = '%s'"; $values[] = $value; } - if (!$getall){ // If not all, a parameter must be tid + if (!$getall){ // If not all, a parameter must be tid. $conds[] = "t.tid != %d"; $values[] = $params['tid']; } @@ -500,9 +521,8 @@ function i18ntaxonomy_term_get_translations($params, $getall = TRUE) { return $items; } - /** - * Like nat_get_terms() but without caching + * Like nat_get_terms() but without caching. */ function i18ntaxonomy_nat_get_terms($nid) { $return = array(); @@ -515,25 +535,25 @@ function i18ntaxonomy_nat_get_terms($nid) { return $return; } - /** - * Implementation of hook_nodeapi() + * Implementation of hook_nodeapi(). * - * Prepare node for translation + * Prepare node for translation. */ function i18ntaxonomy_nodeapi(&$node, $op) { switch ($op) { case 'view': - // This runs after taxonomy:nodeapi, so we just localize terms here + // This runs after taxonomy:nodeapi, so we just localize terms here. if ($op == 'view' && array_key_exists('taxonomy', $node)) { $node->taxonomy = i18ntaxonomy_localize_terms($node->taxonomy); } break; + case 'prepare translation': $source = $node->translation_source; - // Taxonomy translation + // Taxonomy translation. if (is_array($source->taxonomy)) { - // Set translated taxonomy terms + // Set translated taxonomy terms. $node->taxonomy = i18ntaxonomy_translate_terms($source->taxonomy, $node->language); } break; @@ -541,9 +561,9 @@ function i18ntaxonomy_nodeapi(&$node, $op) { } /** - * Translate an array of taxonomy terms + * Translate an array of taxonomy terms. * - * Translates all terms with language, just passing over terms without it + * Translates all terms with language, just passing over terms without it. */ function i18ntaxonomy_translate_terms($taxonomy, $langcode) { $translation = array(); @@ -554,8 +574,9 @@ function i18ntaxonomy_translate_terms($taxonomy, $langcode) { if ($translated_terms && $newterm = $translated_terms[$langcode]) { $translation[$newterm->tid] = $newterm; } - } else { - // Term has no language. Should be ok + } + else { + // Term has no language. Should be ok. $translation[$index] = $term; } } @@ -564,14 +585,14 @@ function i18ntaxonomy_translate_terms($taxonomy, $langcode) { } /** - * Localize taxonomy terms for localizable vocabularies + * Localize taxonomy terms for localizable vocabularies. * * @param $terms - * Array of term objects + * Array of term objects. * @param $fields - * Object properties to localize + * Object properties to localize. * @return - * Array of terms with the right ones localized + * Array of terms with the right ones localized. */ function i18ntaxonomy_localize_terms($terms, $fields = array('name')) { $localize = i18ntaxonomy_vocabulary(NULL, I18N_TAXONOMY_LOCALIZE); @@ -586,17 +607,17 @@ function i18ntaxonomy_localize_terms($terms, $fields = array('name')) { } /** - * Taxonomy vocabulary settings + * Taxonomy vocabulary settings. * - * - If $vid and not $value, returns mode for vid - * - If $vid and $value, sets mode for vid - * - If !$vid and !$value returns all settings - * - If !$vid and $value returns all vids for this mode + * - If $vid and not $value, returns mode for vid. + * - If $vid and $value, sets mode for vid. + * - If !$vid and !$value returns all settings. + * - If !$vid and $value returns all vids for this mode. * * @param $vid - * Vocabulary id + * Vocabulary id. * @param $value - * Vocabulary mode + * Vocabulary mode. * */ function i18ntaxonomy_vocabulary($vid = NULL, $mode = NULL) { @@ -604,11 +625,14 @@ function i18ntaxonomy_vocabulary($vid = NULL, $mode = NULL) { if ($vid && !is_null($mode)) { $options[$vid] = $mode; variable_set('i18ntaxonomy_vocabulary', $options); - } elseif ($vid) { + } + elseif ($vid) { return array_key_exists($vid, $options) ? $options[$vid] : I18N_TAXONOMY_NONE; - } elseif (!is_null($mode)) { + } + elseif (!is_null($mode)) { return array_keys($options, $mode); - } else { + } + else { return $options; } -} \ No newline at end of file +} diff --git a/i18ntaxonomy/i18ntaxonomy.pages.inc b/i18ntaxonomy/i18ntaxonomy.pages.inc index 15bb7eea73409565f0ac354261b052ad4891f29d..d38b543a8eda1274fc8d0d23e07ee7334fc86da9 100644 --- a/i18ntaxonomy/i18ntaxonomy.pages.inc +++ b/i18ntaxonomy/i18ntaxonomy.pages.inc @@ -16,7 +16,7 @@ function i18ntaxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { } if ($terms['tids']) { - // We need vid here too + // We need vid here, too. $result = db_query(db_rewrite_sql('SELECT t.tid, t.vid, t.name FROM {term_data} t WHERE t.tid IN ('. db_placeholders($terms['tids']) .')', 't', 'tid'), $terms['tids']); $tids = array(); // we rebuild the $tids-array so it only contains terms the user has access to. $names = array(); @@ -24,7 +24,8 @@ function i18ntaxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { $tids[] = $term->tid; if (i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { $names[] = tt("taxonomy:term:$term->tid:name", $term->name); - } else { + } + else { $names[] = $term->name; } } @@ -55,12 +56,12 @@ function i18ntaxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { $channel['link'] = url('taxonomy/term/'. $str_tids .'/'. $depth, array('absolute' => TRUE)); $channel['title'] = variable_get('site_name', 'Drupal') .' - '. $title; - // Only display the description if we have a single term, to avoid clutter and confusion. - if (count($tids) == 1) { - $terms = array(taxonomy_get_term($tids[0])); - $terms = i18ntaxonomy_localize_terms($terms, array('description')); - // HTML will be removed from feed description, so no need to filter here. - $channel['description'] = $terms[0]->description; + // Only display the description if we have a single term, to avoid clutter and confusion. + if (count($tids) == 1) { + $terms = array(taxonomy_get_term($tids[0])); + $terms = i18ntaxonomy_localize_terms($terms, array('description')); + // HTML will be removed from feed description, so no need to filter here. + $channel['description'] = $terms[0]->description; } $result = taxonomy_select_nodes($tids, $terms['operator'], $depth, FALSE); @@ -93,7 +94,7 @@ function i18ntaxonomy_term_page($str_tids = '', $depth = 0, $op = 'page') { * @ingroup themeable */ function theme_taxonomy_term_page($tids, $result) { - drupal_add_css(drupal_get_path('module', 'taxonomy') .'/taxonomy.css'); + drupal_add_css(drupal_get_path('module', 'taxonomy') . '/taxonomy.css'); $output = ''; @@ -101,8 +102,9 @@ function theme_taxonomy_term_page($tids, $result) { if (count($tids) == 1) { $term = taxonomy_get_term($tids[0]); if (i18ntaxonomy_vocabulary($term->vid) == I18N_TAXONOMY_LOCALIZE) { - $description = tt('taxonomy:term:'.$term->tid.':description', $term->description); - } else { + $description = tt('taxonomy:term:' . $term->tid . ':description', $term->description); + } + else { $description = $term->description; } @@ -120,18 +122,18 @@ function theme_taxonomy_term_page($tids, $result) { } /** - * Helper function for autocompletion + * Helper function for autocompletion. * - * @ TODO Optimized localization. We cannot just tt() huge lists of terms + * @ TODO Optimized localization. We cannot just tt() huge lists of terms. */ function i18ntaxonomy_autocomplete($vid, $string = '') { // The user enters a comma-separated list of tags. We only autocomplete the last tag. $array = drupal_explode_tags($string); - // Is this vocabulary localizable ? + // Is this vocabulary localizable? $localizable = i18ntaxonomy_vocabulary($vid) == I18N_TAXONOMY_LOCALIZE; - // Fetch last tag + // Fetch last tag. $last_string = trim(array_pop($array)); $matches = array(); if ($last_string != '') { diff --git a/i18nviews/i18nviews.info b/i18nviews/i18nviews.info index ce6a60fd4ff98749a22dd3c16a31f414bfc20f13..453f9860aa3e1cb5190ed7c3065dab8a60544dd4 100644 --- a/i18nviews/i18nviews.info +++ b/i18nviews/i18nviews.info @@ -1,3 +1,4 @@ +; $Id$ name = Views translation description = Views support for i18n, translation of views strings (Experimental). dependencies[] = i18nstrings diff --git a/i18nviews/i18nviews.module b/i18nviews/i18nviews.module index ad7a82ced3c83b368f56d1b805446da4cf603a3d..d2be54c995ab85312f340724d723724a80db90b9 100644 --- a/i18nviews/i18nviews.module +++ b/i18nviews/i18nviews.module @@ -11,10 +11,10 @@ */ /** - * Implementation of hook_help() + * Implementation of hook_help(). */ -function i18nviews_help($section, $arg) { - switch ($section) { +function i18nviews_help($path, $arg) { + switch ($path) { case 'admin/modules#description' : $output = '

' . t('Supports translation for views strings: title, header, footer...') . '

'; $output .= '

' . t('To search and translate strings, use the translation interface pages.', array('@translate-interface' => url('admin/build/translate'))) . '

'; @@ -29,6 +29,7 @@ function i18nviews_locale($op = 'groups', $group = NULL) { switch ($op) { case 'groups': return array('views' => t('Views')); + case 'refresh': if ($group == 'views') { return i18nviews_locale_refresh(); @@ -37,7 +38,7 @@ function i18nviews_locale($op = 'groups', $group = NULL) { } /** - * Refresh views locales + * Refresh views locales. */ function i18nviews_locale_refresh() { // To be implemented @@ -46,14 +47,14 @@ function i18nviews_locale_refresh() { /** * Implementation of hook_views_pre_view(). * - * Views are identified by $view->name + * Views are identified by $view->name. * - * @TODO This needs a lot of research and work + * @TODO This needs a lot of research and work. * @TODO Ask Earl */ function i18nviews_views_pre_view(&$view, &$display_id, &$args) { - // Translate all possible display strings, step by step - // I.e. for a page, there seems to be a 'page' and a 'default' display + // Translate all possible display strings, step by step. + // I.e. for a page, there seems to be a 'page' and a 'default' display. $fields = array('title', 'header', 'footer', 'empty'); foreach (array($display_id, 'default') as $display) { if (!empty($view->display[$display])) { @@ -61,19 +62,20 @@ function i18nviews_views_pre_view(&$view, &$display_id, &$args) { } } - // Translate taxonomy fields - // @todo I don think this works at all + // Translate taxonomy fields. + // @todo I don think this works at all. if (module_exists('i18ntaxonomy') && is_array($view->field)) { $translate = variable_get('i18ntaxonomy_vocabularies', array()); foreach ($view->field as $index => $data) { $matches = array(); - if($data['id'] == 'term_node.name') { - // That's a full taxonomy box + if ($data['id'] == 'term_node.name') { + // That's a full taxonomy box. $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; - } elseif(preg_match("/term_node_(\d+)\.name/", $data['id'], $matches)) { + } + elseif(preg_match("/term_node_(\d+)\.name/", $data['id'], $matches)) { $vid = $matches[1]; if ($translate[$vid]) { - // Set new handler for this field + // Set new handler for this field. $view->field[$index]['handler'] = 'i18ntaxonomy_views_handler_field_allterms'; } } @@ -83,7 +85,7 @@ function i18nviews_views_pre_view(&$view, &$display_id, &$args) { } /** - * Translate a group of fields + * Translate a group of fields. * * We get the translated fields out of the array so they are not translated again. */ @@ -118,9 +120,9 @@ function _i18nviews_localize_object($name, $group, &$data, &$field_names, $trim } /** - * Field handler for taxonomy term fields + * Field handler for taxonomy term fields. * - * Remake of views_handler_field_allterms with term name translation + * Remake of views_handler_field_allterms with term name translation. */ function i18ntaxonomy_views_handler_field_allterms($fieldinfo, $fielddata, $value, $data) { if ($fieldinfo['vocabulary']) { @@ -129,7 +131,7 @@ function i18ntaxonomy_views_handler_field_allterms($fieldinfo, $fielddata, $valu else { $terms = taxonomy_node_get_terms($data->nid); } - // Translate all these terms + // Translate all these terms. _i18ntaxonomy_translate_terms($terms); if ($fielddata['options'] == 'nolink') {