Closed (duplicate)
Project:
Feeds
Version:
6.x-1.0-beta11
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
14 Dec 2010 at 12:48 UTC
Updated:
27 Sep 2012 at 01:19 UTC
Jump to comment: Most recent
Comments
Comment #1
marcvangendSubscribe. I'm looking at a similar situation: an XML feed with bi-lingual records, so each imported record should result in two nodes.
Comment #2
uwe_a commentedMy case is a little different marcvangend, i have two feeds with something in common, i want to mark this as unique per language or something similar, for example:
feedA:
<entry>
<lang>en</lang>
<link> XXXYYYZZZ </link>
<id> 123 </id>
<description> something</description>
<title> something else </title>
</entry>
feedB:
<entry>
<lang>de</lang>
<link> AAABBBCCC </link>
<id> 123 </id>
<description> something in different language</description>
<title> something else in different language </title>
</entry>
as you can see , id is common , so i want it to be the key for relating translations.
but we both want feed to handle translation relation
Comment #3
micheleannj commentedsubscribing
Comment #4
marcvangendcross-referencing #840142: How can the created nodes be assigned their correct language? (and other "core" fields...), where work is being done on supporting content translation.
Comment #5
marcvangendI don't know if there is a better way to solve this, but for now, I tackled my problem with a hook_feeds_after_import implementation.
As far as I can see, there is no way the parser can know the future ID of the node that is being created. As a result, the parser cannot set the tnid value for that node - at least in my case, because both the source language and its translation are imported simultaneously.
My importer created nodes of type 'object' and every object has an ID (stored in field_object_number) that is identical across its translations. The code below runs after finishing the import, because that's when the node id's are available.
I hope that helps anyone.
Comment #6
uwe_a commented@marcvangend
How does your feed look like? i'm thinking maybe we could construct a more general case, but it needs to have one node there at least. maybe it can be worked around, can you put a snippet of the feed here ?
Comment #7
marcvangendMy feed is huge, and I cannot quote from it publicly, but I'll give you a simplified example:
The example above results in 4 nodes: 2 English (en) and 2 Dutch (nl). The code from comment #5 makes sure that every English node is marked as translation of the Dutch node with the same object_number.
Comment #8
uwe_a commentedOk, well, it should be doable to import the feed "twice", i mean using two importers, one for every language, right ? this would allow to use the same usecase i have... right ?
something like :
en:
context : //record
title: title[@lang=en]
image: image
nl:
context : //record
title: title[@lang=nl]
image: image/value
or something similar, no ? i mean to get a general solution ...
Comment #9
marcvangendI think you're right about that. If you use hook_feeds_after_import to set the translations, it doesn't matter how and when the nodes got into the database. It would even be fine if one language is imported on one day and the translation arrives three days later. All you need is a way to identify which nodes are translations of each other (like the object_number in my case).
In fact, the code in #5 is not really dependent on Feeds module at all. It doesn't use any of the parameters passed to hook_feeds_after_import. It would run just as well in a hook_cron implementation, but in this case, hook_feeds_after_import just makes more sense.
Comment #10
uwe_a commentedok, would having a property like "unique per language" in the feeds setting that looks up nodes with same field value but different language and uses translation methods/api to associate it with other nodes ?
i'm not even slightly familiar with drupal api/hooks ... sorry
Comment #11
marcvangendThat seems like the way to go, yes. Just like there is a 'unique target' flag right now when you configure the mapping for your feed, there could be a second checkbox called 'unique per language' or something like that. I assume that a hook_fields_after_import implementation can access that property and act accordingly.
As far as I know, there is no API function to tell Drupal "node x is a translation of node y". That's why my code updates the node table directly.
I would be interested to know if the Feeds maintainer will accept a patch that works like this...
Comment #12
micheleannj commentedI was just going to post a suggested solution like this. I realized I would have to use a different field for the unique ID if it has to be unique even for translations. But it would be perfect if you could just check any field to be used as translation mapping -- it could be the GUID or something else.
I'm more than happy to test/review/contribute to a patch as I need this ASAP... I'll start by trying to implement the code snippet and take it from there.
It would be great to see more multilingual support in Feeds!
m
Comment #13
micheleannj commentedI just came across this thread & patch for nodeferences with feeds - http://drupal.org/node/724536 - maybe that code could be adjusted to work for creating translations? It would just be a few tweaks (ie match on a given field instead of node title).
I'm also trying to adjust the code in #5 to only update the items imported (instead of everything) using $source->batch->items
Anyway, just some leads I thought I'd share as I'd love to see this move ahead quickly and it's a little beyond me...
Comment #14
uwe_a commentedI'm rethinking this ... if we had node translation exposed to "mapping" if translation is enabled, would it be possible to use feeds_tamper with a customized plugin to compute the other node ? i think yes ...
i'm already using feeds_tamper to compute a node reference based on a cck field value ! so this approach might reduce the changes to feeds to "expose node translation nid/reference" and write a simple plugin to feeds_tamper to do the job !
EDIT: maybe even find a way to use views to do the math in feeds_tamper plugin !
another motivation for this approach is that a general solution for feeds would be adding something like "unique combination" which needs a lot more coding that the specific case of language+field value uniqueness ! no ?
EDIT: if it is agreed that this approach is fine, lets put a feature request for it and start from there...
Comment #15
marcvangendI didn't know feeds_tamper yet, but it seems like a nice little framework to plug into (even though alpha 4 may not be too stable yet). However I'm not too sure about using Views to do the query; maybe I'm wrong but it sounds like a lot of overhead for a simple query.
It's hard for me to judge if plugging into feeds_tamper is in any way faster, easier, more maintainable or SimplyBetterTM, but I would love hear the what the feeds_tamper maintainer thinks about this approach.
Comment #16
uwe_a commentedWell, as i said there is a dependency of exposing node translation in feeds... i am willing to do the part of the plugin to feeds_tamper, also frankly i have no clue how to draw the attention of feeds_tamper developers/maintainer to this thread :) !
Comment #17
twistor commentedI have done something similar for feeds_tamper that handles node references when the feed items reference each other instead of existing nodes. I'll have to think on this a bit, just wanting to subscribe.
Comment #18
marcvangendThanks twistor, I'd be interested to hear your opinion on the best approach. I'm still not 100% sure about the best place to hook into the import process.
Comment #19
micheleannj commentedWell, here's how I ended up doing it. There are a couple of caveats : you need to import the base-language (in my case French) first, and you need to not mind if the GUIDs change (for me they are only used during import).
Issues:
*Even though I can set that the tnid is set in the node table, it isn't recognizing that there is a translation -- am I missing something?
*If I could use hook_feeds_after_import, both languages could be loaded at the same time, but it doesn't seem to have access to $source->batch, suggestions?
If feeds_tamper ends up being the way to go, I'm happy to jump on that bandwagon, I just need something that works for me ASAP and have not worked with that before...
Comment #20
marcvangendDid you also set the tnid value for the base node? Your code looks as if you're only setting the tnid value on translation nodes.
Comment #21
micheleannj commentedAwesome! That's probably it.
I'll test a fix tomorrow and post new code in case it's of help to anyone else.
Thanks again for the quick reply. I'm sort of feeling my way around in the dark here... I couldn't find a good example how to do this.
Comment #22
micheleannj commentedThat did the trick.
Just need to add this line:
after setting the $item['tid']
Let me know if anyone thinks it's worth generalizing this...
thanks again.
Comment #23
Anonymous (not verified) commentedThe $base variable in #19 could just as easily be set to the default language of the site. As I work with majnoona I want to chime in with my 2¢ that the site in this example is set to default to English to work around other issues with translations but this code targeting French still works. I think that makes the code a little more generalized for widespread use. N'est pas?
Comment #24
twistor commentedA quick example to show you what a plugin might look like. Put this in set_tnid.inc in the plugins folder of feeds_tamper.
This gives you configuration and exportability(Features) for relatively cheap.
I haven't tested this, I'm not set up here to. I'm also not very familiar with translations in general.
This could be generalized more. The GUID field could any unique field. This requires #840142: How can the created nodes be assigned their correct language? (and other "core" fields...) correct?
Comment #25
hosais commentedsubscribe
Comment #27
dgastudio commentedany update on this? can the plugin from #24 be applied to d7 ?
Comment #28
mvci've spent some time thinking about this today for a client and have a short-term fix plus a suggestion for further work.
feeds_tamper is a fine module but it runs when a single field is being imported and doesn't have enough context to figure this out. we have to set node->tnid for both source and translation but that can't happen until later in the process after at least the first has been created.
i think solving this correctly would require adding a new mapper to feeds/mappers/, like the nodereference patch does in #724536: Mapper for nodereference field in Drupal 6. we would also need to store information about the source language node in the feeds_node_item table which we can reference later when importing the translation. i think this is reasonable since translation is a core module. but, the module maintainers should probably give their opinion on that, so i'm not going to start that work now since they might disagree with my approach.
so, in the mean time, i've solved this for my use case with the hook_feeds_after_import() approach. my code is below, and i've documented the assumptions it makes (ie, what you would need to do before you can use it).
@kervi: this thread is discussing the problem for D6; as i imagine the solution would be different for D7, perhaps you could search for or start a new thread for that conversation, and reference it here?
Comment #29
twistor commentedClosing this as a dupe of #1183440: Multilingual Feeds - Make field import language-aware. Any work done in that issue will have to be ported back to 6.x