Not sure where this belongs, but on our site we are using the core block - "Most recent poll". It doesn't seem to be set up to handle translations / language switching very well. It just pulls the most recent poll regardless of what language that poll is created in.

I added this code to a custom module, to correct that. It checks the current site language global, and pulls the most recent poll created in that language. (Another way to do this would be to get the actual translation of the most recent poll in the base language, but this was fine for us).

/**
 * Implements hook_block_view().
 * alter the recent poll block to show correct translation
 * over-writing the poll recent block
 */
function mymodule_block_view_alter(&$data, $block) {
 if ($block->module == 'poll' && isset($data['content'])) {
		global $language; 
		if (user_access('access content')) {
			// Retrieve the latest poll.
			$select = db_select('node', 'n');
			$select->join('poll', 'p', 'p.nid = n.nid');
			$select->fields('n', array('nid'))
			  ->condition('n.status', 1)
			  ->condition('p.active', 1)
			  ->condition('n.language', $language->language)
			  ->orderBy('n.created', 'DESC')
			  ->range(0, 1)
			  ->addTag('node_access');

			$record = $select->execute()->fetchObject();
			if ($record) {
			  $poll = node_load($record->nid);
			  if ($poll->nid) {
				$poll = poll_block_latest_poll_view($poll);
				$data['content'] = $poll->content;
				}
			}
		}
    }
}

Comments

jose reyero’s picture

Project: Internationalization » Internationalization UI
Version: 7.x-1.2 » 6.x-1.x-dev
Component: Blocks » Code

You can also produce a new block with this result.

As there are no plans to extend current i18n with poll support, these widgets will be welcomed in the i18n UI module.