Monday, December 21, 2009

Drupal - Better way to translate blocks

There are custom blocks on a site I manage that contain simple English text. We just started a push to add Spanish to the site. So I researched how to make blocks multilingual. The documentation I found mentioned 2 ways to do this: 1) use Drupal's string translation to translate whole blocks into different languages, or 2) create separate blocks for each language and enable them only for the nodes in the associated language.

I wasn't happy with either of these options. I don't want my contributors creating and maintaining string translations, and neither do I want them editing blocks.

Meanwhile, content (node) translation in Drupal is elegantly implemented. To translate a node, you go to the node and create a translated version. The translated versions are then always tied to each other. With this my contributors can create English and Spanish content easily.

Happily, I found another - and I think better - way to do this with the "node as block" module. I don't think this module was developed with multilingual content management as a prime driver, and I don't see much discussion about this valuable use.

There are a couple of quirks you have to know about. One, by default the block only displays a subset of the content of your node, so you have to include the "<!--break-->" tag to make sure all preceding content is displayed (if you know a way around this, let me know!). Two, when you translate a node, you have to make sure to specify with the translation that you want a block created (even if you've done so with the original node). And yes, this means you'll end up with 2 blocks.

Even with these quirks, this is going to be a much better way for my contributors to edit content in multilingual blocks.

Note that there are several other seemingly similar modules that I haven't researched, including "nodes in block" and "node blocks". If you've found that these or other modules serve this purpose better, let me know!