Sunday, April 17, 2011

Content Translation (field translation) in Drupal 7

Drupal has long been a leader in the ability to present a website in multiple languages. In Drupal 7 we continue that tradition: Field translation or "content translation" made it into Drupal 7, but it's not obvious from a plain Drupal 7 install how you would use it.

This article is fundamentally about content translation, not about interface translation, which is a completely different thing in Drupal (and always has been). Interface translation is about prompts, labels, menu entries and the like, all of which are handled by the core locale module and various contrib modules like i18n. I will explain how to import basic interface translation files, however.

Drupal 6 has a node translation system which basically allows you to make "translation sets" of nodes. You start with a node in a source language (and set the language on that node), and then you can create additional translations of that node to other languages. So for example, we might start with a node in English, then use the "translate" tab to add additional nodes in different languages that are tied to that original node. That node translation system is still supported in Drupal 7, but it doesn't support translation of CCK fields, and is quite awkward in reality because you're dealing with a number of separate nodes, instead of translations of a single node. Edit: See Gabor's comment below for more on this, and considerations regarding it.

Drupal 7 got field translation (yay!), also referred to as "content translation", which is an entirely different thing. In content translation you have a single node, but with different translations for each field on the node that should be translatable. And the body is a field. Unfortunately the title is not a field, and therefore is not translatable, but more on that later. To restate this: In Drupal 7 "content translation" there is just one node, and translatable fields on it are translated to provide the translations, but are still part of that single node. The gotcha in field translation (content translation) though is that in core it didn't get a user interface. As a result the contrib Entity Translation module improves content translation and provides a UI and works alongside the core content translation module, and it's fundamental to the approach described here.

Here is the process I went through to set up a basic multilingual site:

1. The core field translation facilities have no user interface, so you'll need the Entity Translation module. After installing and enabling it (which also enables translation and locale modules), you may need to run update.php.
2. You need to enable languages for your site.
* Add languages at admin/config/regional/language
* Download interface translation files from http://localize.drupal.org
* Import interface translations into the configured languages at admin/config/regional/translate/import (under "Translate Interface"
* Click "Enabled" on the languages you've configured
* At "Detection and Selection" (admin/config/regional/language/configure), choose how you want languages to be chosen. My experience is that URL selection is the best approach, so you'll need to configure subdomains or some related approach. Note that when you use URLs you need to enter the full URL including "http://". There doesn't seem to be any error checking on this. Also remember to click "enabled" on the strategy that you choose.
* On the same "Detection and Selection" page, in the lower section of the page under "Content language detection" select "Interface", so that the same language is chosen for content language detection as for interface language detection.
3. Enable translation of nodes and any other entities that should be translatable at admin/config/regional/translation.
4. Enable "Multilingual support: Enabled, with content translation" on the content type edit form under "Publishing options". For example, for a content type named "example", this would be at admin/structure/types/manage/example/edit in the "publishing options" fieldset.
5. For each field that should be translatable, go to field settings and check "users may translate this field". For the body field of the "example" content type, this would be at admin/structure/types/manage/example/fields/body/field-settings.
6. Now you can create and translate fields.
* Create a node and set its language to a specific language.
* When you've saved it a "Translate" tab will appear allowing you to translate into other configured languages.
* Click "Add translation" to add translations for the fields that have translation enabled.
* Make sure to publish the translation. Publication is unfortunately hidden in the collapsed-by-default "translation options" fieldset

Some gotchas regarding field translation:

* The Title module is required to make titles translatable. This currently only works for nodes, not entities. All the work is actually being done in #924968 so you have to apply the patch from that issue.
* Entities other than nodes are not translatable out of the box. The entity must be specifically enabled to allow its fields to be translated. das-peter will elaborate on this later.

Since I'm a newbie at the D7 translation scene, I'm sure there are errors or omissions here, so please correct this and I'll update the article based on your corrections.

15 comments:

  1. I am actually searching for blogs regarding translation and found yours. Thanks for the good information you've shared. I find it really informative.
    ---
    Seff
    website translation services

    ReplyDelete
  2. thanks, i understand the differences with content vs interface translation a lot better now too :)

    ReplyDelete
  3. Thank you for this blog. That’s all I can say.
    You most definitely have made this blog into something that’s eye opening and important.
    You clearly know so much about the subject, you’ve covered so many bases.
    Great stuff from this part of the internet. Again, thank you for this blog.

    ReplyDelete
  4. Thank you for bringing more information to this topic for me. I'm truly grateful and really impressed.
    I love to read this blog very interesting

    ReplyDelete
  5. Original version of this post is written by Randy Fay and it can be found at http://randyfay.com/node/88

    Anish Boral has nothing to do with this post and he most certainly isn't the original author of this blog post.

    To Anish Boral, you might wanna give credit to the ORIGINAL POSTER before posting this stuff on your own blog and take credit from it as your own text.

    Idiot.

    ReplyDelete
  6. I have no words for this great post such a awe-some information i got gathered. Thanks to Author.

    ReplyDelete
  7. You should most def give credit to Randy Fay a truly great contributor.

    ReplyDelete
  8. If you're interested in localizing Drupal websites, be sure to check the online translation platform https://poeditor.com/
    It's a real gem for making such sites multilingual.

    ReplyDelete
  9. Two French Cavalry defeats by Platov kept the French in the dark and Bagration was no better informed with both overestimating the other’s strength, Davout thought Bagration had some 60,000 men and Bagration thought Davout had 70,000. Bagration was getting orders from both Human translation Alexander’s staff and Barclay (which Barclay didn’t know) and left Bagration without a clear picture of what was expected of him and the general situation.

    ReplyDelete
  10. wow, great post! your post is really informative and helpful. thanks for sharing.
    mobile apps development companies melbourne | ipad app development company

    ReplyDelete
  11. Thanks for Nice and Informative Post. This article is really contains lot more information about This Topic.  agencia de traducción

    ReplyDelete
  12. I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favorites blog site list and will be checking back soon. Please check out my site as well and let me know what you think. Official translation

    ReplyDelete
  13. This is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. Traductor Jurado Valencia

    ReplyDelete
  14. Great! I appreciate the inclusion of both lifestyle changes and professional resources for those in need of more support. If you want the best service for your vehicle then look at this DMV In Las Vegas it is too good.

    ReplyDelete