I've written a module that defines a hook allowing other modules to modify the contents of the Translate tab for each node. Only a very small part of it is slightly hackish! But because of this, I'm wondering if it wouldn't be better to include the hook in core. I've no idea if this is too late for D7, but would stress that it doesn't change existing functionality for anyone, just adds an extra capability.

Or is there a better way to do this than the approach I've taken, which doesn't require either changing core or the hackish step d (see below)? Your input would be most welcome.

Use cases (true stories):
(1) One of the sites I am working on is intended to operate in dozens or even hundreds of languages, but each page will only be translated into a few of those languages. Specifically, for each term in the taxonomy vocabulary, there is a handful of 'relevant languages' which are the only ones I want to show up on the Translate tab (any more than this would be overwhelming).
(2) (This is probably a terrible way of doing it, but I don't propose to release it generally, so for me it works well enough.) For another site, I have written a cloning node type which allows certain nodes of an existing node type (webform) to be designated as templates for re-use. Users start creating the clone, choose the webform node to use as a template, and then when the clone is saved, it becomes a webform node too. I want translations of webform nodes to be created by this cloning method, rather than starting as empty webforms. So I need to modify the 'add translation' link on the Translate tab.

My solution
(a) I have written a small module called Custom Translation Tab to deal with these and other potential use cases. Basically it replicates the function translation_node_overview() but also defines hook_custom_translation_tab_data() which allows other modules to:
- rename or add columns
- replace or add data to any language row in the table
- delete rows or columns

(b) A key change* to the overview function is that the arrays containing rows and row headers use named keys rather than arrays with unspecified keys.

(* pun not intended - sorry!)

(c) A new function custom_translation_tab_redirect() invokes the hook, examines the results and then calls either custom_translation_node_overview() or the standard translation_node_overview(), depending on whether or not there are results from the hook for this node(type).

(d) And to ensure that this all happens, I overwrite an entry in the menu to call custom_translation_tab_redirect() from node/%node/translate.

The full code is attached. All feedback very welcome!

CommentFileSizeAuthor
custom_translation_tab.tar_.gz5.33 KBmartin_q
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

plach’s picture

Version: 8.x-dev » 7.x-dev

I'm afraid this will have to wait for D8.

You may want to switch to http://drupal.org/project/translation to make this available in D7.

plach’s picture

Version: 7.x-dev » 8.x-dev