How to change entity language in bulk?
I have a site in drupal which is Spanish by default. Now I want to add an English translation. It has many undefined ('und') "producto" objects. I want them to assign the 'es' language to them. Before posting this question, I checked this other question How do I change node languages in batches? but I cannot accomplish what I want. Let me explain:
a) I tried Language Assignement, but the last commit was 1 year ago and it has a critical bug that could lead to data loss (I reproduced the bug too). I also tried using a patch from user barami but data loss persists.
b) View Bulk Operations: I've tried but it only updates the field in the database table "node". Not others.
c) So, I checked how the drupal database works and created a sql script that also results in data loss:
-- Step 1 Node lang
update node set language='es' where type='producto';
-- Step 2 body field
update field_data_body set language='es' where bundle='producto';
-- Step 3 Field comment vody
update field_data_comment_body set language='es' where bundle='comment_node_producto';
-- Step 4 For each field of producto, update language
update field_data_field_precio set language='es' where bundle='producto';
update field_revision_field_precio set language='es' where bundle='producto';
(...)
I have the following translation modules activated: Internationalization, Block languages, Field translation, Menu translation, Multilingual content, Multilingual selection, Translation synchronization, Taxonomy translation, Translation redirection, Translation sets
What am I doing wrong with my sql script? Are there other plugins to accomplish what I want to do? Any suggestion would be appreciated Thanks!
This is how I set the language in bulk on my site:
-
Using Optimize Arrays of Images, select all the nodes you want to change, use the Change Value option, and then change the value to your desired language.
-
After you do that, the field values won't show up when editing nodes, so you need to run a script for example.
UPDATE database.field_data_body SET language='en' WHERE bundle='page'
(use your database name, field name and package if needed).
IMPORTANT: if you have any custom url aliases, they will be rewritten with this approach due to pathauto issue, but there is a workaround: first go to / admin / config / search / path / settings and change the setting " Update Action to Do Nothing. Leave the old alias intact. ', And then change this value as soon as you run the Bulk View Action.
Assuming you can make a view that lists your entities, you can use the Views Bulk Operations module to do this. I just explained how to do this the other day for nodes at Drupal Answers.
Another solution would be to just execute the first SQL, because I found that the field language should remain "und".
update node set language='es' where type='producto';