It may be obvious but I cannot find any example... I have a destination text field (attached to a node) that is translatable with Entity Translation. My source data is coming from CSV, each language having its column. I'm trying to import each translation in the right place.
Sample CSV row:
"id","name_en","name_fr"
1234,"Peter","Pierre"
I want to insert this in a Field API field as follows:
$node->field_name['en'][0]['value'] = 'Peter';
$node->field_name['fr'][0]['value'] = 'Pierre';
I tried the next mapping:
$this->addFieldMapping('field_name', 'name_en')->arguments(array('language' => 'en'));
$this->addFieldMapping('field_name', 'name_fr')->arguments(array('language' => 'fr'));
It's not working... What is wrong here?
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | migrate-handle_language_subfield_value_by_value_basis-1537076-16.patch | 836 bytes | villette |
| #13 | patch_commit_c4f68ad4f4fd.patch | 1.04 KB | bachbach |
| #10 | null-format.jpg | 37.78 KB | claudiu.cristea |
| #8 | db.jpg | 26.95 KB | claudiu.cristea |
| #8 | devel.jpg | 48.97 KB | claudiu.cristea |
Comments
Comment #1
mikeryanFirst off, you can't have multiple mappings to the same destination field - the second one will override the first (you should be seeing warnings about it).
Secondly, using the arguments() method you can only set one value per field.
Fortunately, just recently #1279778: Improve argument passing to fields was committed, providing a subfield syntax for mappings that is much cleaner and more flexible. If you have a -dev release since April 5, you should be able to do:
I haven't tested the subfield stuff in a multi-language scenario, so please let me know if this approach works for you.
Comment #2
claudiu.cristeaI have to show the real case (the above one was simplified for readability). Tried your approach and I got error:
My code (a little different from above...):
Inspecting the offset in sites/all/modules/migrate/plugins/destinations/fields.inc, line 266:
I found that
$languageis an array rather than a string with value:Is this helpful?
Comment #3
claudiu.cristeaComment #4
mikeryanOK, I should've looked at the code first - since language was previously treated like a field option (one language per field), the subfield changes continued to treat it that way, so it isn't being assigned per value. That's a bug for me to fix...
Thanks.
Comment #5
mikeryanCan you try the attached patch and see if it gives you the multi-language support you need?
Thanks.
Comment #6
jgreidy commentedA workaround for multilingual entity translation migrate, probably not the best thing, but it works.
Do the migrate as normal in the default language ('en' for me), don't map the other language fields (eg. title_deu),
then use the prepare() method to set up the other language version:
Comment #7
mikeryanCommitted the patch in #5.
Comment #8
claudiu.cristeaI patched with #5 and defined mappings as follows:
Here's what I got...
node/%node/devel), translations are OK. See http://drupal.org/files/devel_0.jpg.field_data_title_fieldbut with incremental deltas. Delta should be "0" for all translations. See http://drupal.org/files/db.jpg.Overall is working. Not sure if the UI issue is related to Migrate or Entity Translation. Anyway, the "delta" issue still remain. Switching to "needs work".
Comment #9
mikeryanOK, I've changed it to not use the explicit delta, each language should increment independently.
Thanks.
Comment #10
claudiu.cristeaThank you... I tested the latest patch and works. Not sure that this is necessarily related to this issue but now I see that the "format" of first row, of default language, of the translated field is set to
NULL.See the attached screenshot.
Comment #11
mikeryanAnd you're not mapping title_field:format, or passing a format option to MigrateDestinationNode()? It should be defaulting to filter_fallback_format(), I don't see why that would be missed the first time through...
Comment #13
bachbach commentedHi,
i ran through the same issue with file field, and this improvement works for me, here is a patch against 7.x-2.5+32-dev (2013-Jan-22)
Comment #14
mikeryanPlease don't reopen long-closed issues, open a new issue.
Also, when submitting patches please be sure to set the status to "needs review".
Comment #15
joseph.olstadWorks fine with the body and custom fields, but not for the entity title
I've added some notes/documentation here:
#2091029: Entity translations are not migrated when using *:language subfields
Comment #16
villette commentedI made a reroll of the patch in #13
It should work with both dev and 2.6-rc1 versions
Comment #17
villette commentedComment #20
mikeryanAgain - please don't reopen long-closed issues, open a new issue.