Flag and i18n

Last updated on
30 April 2025

This page lists some issues with Flag's i18n support.

"Flag translations of content as a group"

If you install and enable Translation helpers module, the setting "Flag translations of content as a group" becomes available in each node flag setting page. When the 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.

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:

  1. Install the Views Custom Field module.
  2. Add the "Customfield: PHP code" field to your view.
  3. Into the field's "Value:" setting type:
    // Replace 'bookmarks' with the machine-name of your flag.
    print flag_create_link('bookmarks', $data->nid);
    

For Drupal 7.x:

  1. Install the Views PHP module.
  2. Add the "Global: PHP code" field to your view.
  3. Into the field's "Output:" setting type:
    // 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.)

Help improve this page

Page status: Not set

You can: