How to deal with translated nodes programmatically

I had to import four different languages nodes into my Drupal 7 installation programmatically. It’s easy when you know where to begin with.

First, you have to enable different languages you will use into your Drupal administration. For example, I used

  • EN: English
  • NL: Dutch
  • DE: German
  • FR: French

Then, you need to define the default languages you will use for the first node created. You have to set it from the administration page too. We chose English language.

You have to know each translated nodes will be linked to others by referencing the parent and default language, here: English.

Let’s create your nodes :

You have successfully created four nodes linked together by the English node.

Now if you want to get all translated nodes from Drupal, you can use translation_node_get_translations function that takes a parent translated nid in parameter and send back translated nodes array:

 

 

5 Thoughts on “How to deal with translated nodes programmatically

  1. Nander on December 6, 2013 at 16:30 said:

    For Drupal localization projects I recommend https://poeditor.com as a very useful crowd translation tool tool. It has a plugin that connects the platform to your Drupal website, making import and export easier.

  2. GTL Dev on January 22, 2014 at 09:45 said:

    Thanks! Nice article and good solution.
    I got what I needed.

  3. Not easy to find tutorial on multilingual Drupal.
    This great article

  4. Great article. Import translated nodes is a big problem in drupal 6. You`ve saved me a lot of work.

  5. Thanks on January 12, 2015 at 23:33 said:

    Thanks for sharing!

Leave a Reply

Your email address will not be published. Required fields are marked *

Post Navigation