0

On my multilingual site, I have a content type that is going to be user created. I want to keep it language neutral ('und').

But there already are a couple thousand nodes of that content type and they have English set as their language.

To make them language neutral, I want to write one time update function (hook_update_N) to change the language of the nodes and all their fields from 'en' to 'und'.

I am doing this by making changes directly to database (using db_update) to the language column of node & related field tables. But I am afraid that I may miss something. Can I do this some other way to not miss anything.

I read somewhere that I can user hook_node_presave & node_save to do this but I am not sure how.

Also, how can I make any future nodes' language to be set default as 'und'?

2

If this is just a one-time conversion, you should be able to do it with Views Bulk Operations (VBO).

Here's one way to do this that doesn't involve writing any code.

  1. Install the VBO module.
  2. Create a new view showing Content of whatever content types you need to convert. Use the Fields display method.
  3. Add a field Bulk operations: content.
  4. Check Modify entity values and select Language.
  5. Choose Apply.
  6. Save the view (add any other filters if necessary to limit the selection) and go to the created view page.
  7. From the view page, choose the option to select all items on all pages and execute the Modify entity values action.
  8. Choose the language and click next.

If you have an extremely large number of nodes, you may need to play around with the queuing settings so that not everything is executed at once, but I would try doing it in one pass first because hey, if it works, you're done (note: always test on a backup first!)

Source: How can I set the language of nodes in bulk to existing content when making a site multilingual? - please upvote that one if you liked the solution above.

To force the default language to be undefined, in the setting.php file used by your site, add the following lines:

$conf['language_default'] = (object) array(
  'language' => 'und', 'name' => '', 'native' => '',
  'direction' => 0, 'enabled' => 1, 'plurals' => 0, 'formula' => '',
  'domain' => '', 'prefix' => '', 'weight' => 0, 'javascript' => ''
);

This will force Drupal to use 'und' as the default language for all new content.

2

you can also use a SQL statement

UPDATE node SET language = 'en' WHERE language = 'und';
  • You also need to change field language UPDATE field_data_body SET language = 'en' WHERE language = 'und'; – Alen Simonyan May 2 at 14:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.