Hello, in d6 I think it was possible to make a true multilanguage poll instead of 2 independent polls for 2 languages. Will this feature be in (a future) D7 release?

I would most like the vote counts to be synchronised as that is the most important thing..


Thanks for all other work, the module runs fine on my d7!

Greets Wappie

Comments

jose reyero’s picture

Yes, I guess we'd need something to translate poll choices. Maybe for next version.

jose reyero’s picture

Component: Code » Blocks
Status: Active » Closed (won't fix)

No time, it seems no one else interested.

(Feel free to reopen if you are posting a patch).

caktux’s picture

Status: Closed (won't fix) » Needs work
StatusFileSize
new6.85 KB

Here's a mostly direct and hackish port of i18npoll.module from D6. It works but choices' order has to be the same.

kanast’s picture

thanks caktux
When anonymous users are allowed to vote on polls, drupal crashes and this error appears when they try to access the site:

PDOException: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens: SELECT v.chid FROM {poll_vote} v INNER JOIN {node} n ON n.nid = v.nid WHERE n.tnid = :tnid AND v.hostname = ':hostname'; Array ( [tnid] => 1 [hostname] => 127.0.0.1 ) in i18n_poll_get_vote() (line 187 of /var/www/drupal/modules/poll/i18n_poll.module).
The website encountered an unexpected error. Please try again later.

I'm using ubuntu 12.04 - drupal 7.16, i18n-7.x-1.7

  • This patch is working if anonymous users are not allowed to vote.

is there any other solution vote counts to be synchronised with anonymous users allowed to vote?

s_leu’s picture

StatusFileSize
new6.83 KB

The patch had another bug besides the one kanast mentioned above. It's now fixed in the attached patch. Please commit this.

s_leu’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Reviewed & tested by the community

Looks ok to me.

jose reyero’s picture

Status: Reviewed & tested by the community » Needs work

I have a few issues with this patch:
- It's not a full D7 upgrade, we do this stuff with different field formatters now.
- The hook_node_view() has some important comment that seems to be missed:
"We don't add all language results on loading to avoid the data being trashed
when editing and saving nodes again."
- I think the D7 strategy, to be consistent with the rest of the package, should be to make poll choices translatable as strings, and then let Entity Translation figure out the rest.

And overall: you want me to add a new module (without tests) to the package when we should start thinking about porting it to D8 instead of growing it more and more?
Really, the solution is way easier, either:
- Create a new module (project) for it.
- Or add it to this one, if you want to commit it right away, https://drupal.org/project/i18n_contrib

However, @Berdir, you have full commit access to this project so if you think this really needs to be here for some reason, and you intend to be maintaining this piece for the future, feel free..

berdir’s picture

Thanks for the quick feedback and sorry for the too quick RTBC :) We tested and fixed the existing patch, so I thought it to be most useful if others can use it too.

Some feedback:

- It's not a field, so we can't do something like field formatters.
- Poll.module is a lot of custom code and forms and it's not any better in D8 (nor will it be removed)
- The proper way forward might be entity translation and pollfield.module (but I haven't checked it) or entity_translation and poll.module with label translation, as you suggested. I'm not sure.

We are already using poll.module in our project and can't easily switch, so we continued with the patch here. Others might be in the same situation.

i18n_contrib doesn't really make sense, as it's a core module :) Making it a separate project with only a dev release that allows users to easily test it and also expose it is probably the best option at this point.

jose reyero’s picture

Project: Internationalization » Internationalization contributions
Component: Blocks » Code

@Berdir,
Ok, let's say then it's a core module that doesn't meet the standards for i18n package. Really, i18n_contrib is the place for this, so you can make it available for others, track issues, etc..

The project's description is: "Internationalization contributions is a set of modules that are add ons for Internationalization module to provide compatibility with other contributed modules or some other features."

Also that module is not meant to have stable releases, though there may be some point releases (alpha versions) for better issue tracking.

So you can add the module as a stand alone or here, as you prefer.

drpl’s picture

I added this to get nid by using the current langauge

/**
 * Implements hook_block_view().
 */
function i18n_poll_block_view($delta = '') {
	    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('n.language', $language->language)
      ->condition('p.active', 1)
      ->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 = i18n_poll_block_latest_poll_view($poll, 'full', TRUE);
        $block['subject'] = t('Poll');
        $block['content'] = $poll->content;
        return $block;
      }
    }
  }
}
Boymix81’s picture

Hi,

for me this patch with many of 2 languages not works.

I fixed the function

i18n_poll_view_results(&$node, $view_mode, $block)

adding relative index of option and now for me it works.

   // Load the appropriate choices into the $poll object.
   $result = db_query("SELECT c.chid, SUM(c.chvotes) AS votes FROM {poll_choice} c INNER JOIN {node} n ON c.nid = n.nid WHERE n.tnid = :tnid AND n.nid != :nid GROUP BY c.chid", array('tnid' => $node->tnid, 'nid' => $node->nid));
   $choices = array_values($node->choice);
+
+  $nLanguages=sizeof(language_list()) -1; //remove count of language selected
   foreach ($result as $i => $choice) {
     // If this option not set for the source node, do not show.
-    if (!empty($choices[$i])) {
-      $choices[$i]['chvotes'] += $choice->votes;
+    
+    // Recalc correnct based on weight concept
+    $optionIndex=$i%$nLanguages;
+    if (!empty($choices[$optionIndex])) {
+      $choices[$optionIndex]['chvotes'] += $choice->votes;
     }
   }
   $node->choice = $choices;
donapis’s picture

Issue summary: View changes

Thanks Boymix81 for the patch.