Wednesday, May 21, 2014

Drupal 7 translation gotchas

Don't slip.

Entity Reference fields have no clue about languages. To them, everything is Language Neutral. Don't expect them to display the referenced entitys translation. Safest bet is to either translate the field or do field translation on the referenced entitys.

Content loaded (from Drupal) via Ajax will not work with the language system. You need to either pass the language code as an argument or set it globally at some other point in your process.
I've done two fixes on this, one being that I pass the nodeid as an argument and check it for language. Another is in the preprocess_node function in template.php adding the following:
drupal_add_js('jQuery(document).ready(function () { window.nodeid="'.$vars['node']->nid.'";window.lang="'.$vars['node']->language.'" });', 'inline');

Taxonomy Menu will beat you with a stick everytime you edit any term. You need to regenerate the menu or else your listings that are based on the vocabulary you're using for the taxonomy menu will fail miserably.

Don't forget to update any Display Suite Code Fields you've used as you've probably left enough UND in there to sound like a german techno parade. And this is the time when you kick yourself and wonder why you ever went down the code field route in the first place. It's a bad bad idea that starts with that one odd field that just needs some special treatment since the client requires it. Then you end up with 30 code fields with hardcoded UND UND UND UND...

Using Drupal.t()? Don't forget that Drupal can't build it's string index for this function unless everything you're using the function in gets added as files with drupal_add_js()

One basic gotcha that I ran across is that t() expects english as the input language regardless of you sites source language. Which is kind of backwards since I'm Swedish and my source language and default language is Swedish. Well well.

Here are some links I've found useful:

No comments:

Post a Comment