Last updated April 2, 2012. Created by mooffie on August 20, 2010.
Edited by BrightBold, heatherann. Log in to edit this page.
This page lists some issues with Flag's i18n support.
"Flag translations of content as a group"
When the "Flag translations of content as a group" setting is chosen, then flagging or unflagging a node is carried out on the translation source node instead. For example, if you have a French translation of an English node, and the English node is considered the "source", then the flag links displayed beneath both nodes will flag or unflag the English node.
Usually you don't have to be aware of this fact when you write PHP snippets. I.e., the $flag->flag() and $flag->is_flagged() and flag_create_link() methods described in the API section will work as "expected". These methods accept the $nid of the translated node and they internally convert it to the $nid of the source.
Views
However, the "Flag translations of content as a group" magic described above doesn't extend to Views. The flag relationships and flag fields operate on the immediate node and the source node is ignored. This means that some steps you'll have to carry out explicitly.
Displaying the correct flag link
When you format your view as a "Table" or "Fields" (as opposed to node's "Full" or "Teaser") you'll note that the "flag this!" and "unflag link!" links don't reflect the state of the node's source. Probably the easiest workaround is this:
For Drupal 6.x:
- Install the Views Custom Field module.
- Add the "Customfield: PHP code" field to your view.
- Into the field's "Value:" setting type:
<?php
// Replace 'bookmarks' with the machine-name of your flag.
print flag_create_link('bookmarks', $data->nid);
?>
For Drupal 7.x:
- Install the Views PHP module.
- Add the "Global: PHP code" field to your view.
- Into the field's "Output:" setting type:
<?php
// Replace 'bookmarks' with the machine-name of your flag.
print flag_create_link('bookmarks', $data->nid);
?>
Filtering the nodes to the flagged ones only
It seems there are two approaches:
- Start with the translations. Then bring in the "Node translation: Source translation" relationship to have access to the source node, and filter on it.
- Start with a view of the source nodes, filter them, then bring in the "Node translation: Translations" relationship to show the translated nodes. Here is a step-by-step example of how to do this.
(@todo: It's possible that we can use the i18n module's query rewriting to do all or some of this work. Investigate.)
Comments
Translation helpers required
It took me some time (and digging through the code) to find out that the translation_helpers module is required to see the i18n settings for flags. It might be I missed something. Mentioning this here for the people who are missing the same info.