6

I've already imported a data set of about 1500 articles, all in English. I have another set of the data with matching node ids but in different languages. Can I import a second file into Drupal 7 and have the localized content mesh up with the existing data?

Currently when I try to import the data it overwrites the existing content, I need them to co-exist with the only difference being a language code.

1

2 Answers 2

7
+50

Import from two xml files (on for each language), my empiric solution :

  1. I created two feed imports.
  2. I forced the language field for each one.
  3. Two separated nodes were created for each content (one in each language) but it didn't links the translations.
  4. So I used a SQL query to finish the job, it's based on the feeds uuid

Note: In order for this to work your GUID must match between the two sources. If you have set that to the node title it is important that you turn off the option to replace content as it will update the previous import :/

UPDATE
    node n,
    feeds_item lng1,
    feeds_item lng2
SET
    n.tnid = lng1.entity_id
WHERE
    (
        n.nid = lng1.entity_id
        OR
        n.nid = lng2.entity_id
    )
    AND lng1.id='feeds_importname_for_lng1'
    AND lng2.guid=lng1.guid
    AND lng2.id='feeds_importname_for_lng2'
3
  • 1
    Hmm... I really like your approach but actually I found the GUID matching doesn't work. When I create two separate imports and set say the title to the same GUID it replaces the other one b/c that's what I had it to setup to do.... Actually even if I turn that off it assumes that my GUID (title) is the same name in both languages :/ Jan 28, 2015 at 18:34
  • I worked it out finally and have modified the tip to help out May 1, 2015 at 1:27
  • This is the only option for node-based translation, because feeds does not support that in 2020: drupal.org/project/feeds/issues/840142 (it only supports entity-based translation)
    – cweiske
    Dec 4, 2020 at 7:27
1

It is possible to achieve this with needing SQL queries.

Also if you want to do anything with field translation in feeds, make sure you have a current version. Newer than a year ago, because of https://www.drupal.org/node/1183440 This version supports entity translation, which you'll need of course. It allows for fields to be translated. So you'll have 1 entity which several fields. These fields can be translated independently.

You will have to set a Unique identifier setting on both feeds importers to be imported and these should of course be the same (ypur matching node ids). You can then set in the processors' mapping settings that an input record should a into a particular fields' translation.

So,

  1. create two importers, one for each language.
  2. in both, set your 'matching node ids' as 'Used as Unique' In the feeds processor mapping settings.
  3. set the language setting in the mapping.

If you can see the language setting, doublecheck the Entity Translations and field settings.

2
  • This only works if you are using field-based translation with module entity_translation, but not with using the Drupal 7-standard node-based translation.
    – cweiske
    Dec 4, 2020 at 7:26
  • I thought that was quite clear in my answer, should I make it clearer?
    – firfin
    Mar 23, 2021 at 16:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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