Calling web translators from other translators

51 views
Skip to first unread message

Avram Lyon

unread,
Oct 11, 2011, 1:01:48 AM10/11/11
to zotero-dev
Zotero folks,

I just rewrote the BioMedCentral (et al.) translator to work mainly
with the embedded RDF in the header, with some extra logic to handle
search results and metadata oddities:
https://github.com/ajlyon/translators/blob/dd3c956584d87cda226941f7a956a57af0d1f748/BioMed%20Central%20and%20More.js

I did this by loading the Embedded RDF translator with loadTranslator
and calling getTranslatorObject() on it, then just running the doWeb
of Embedded RDF.js. It works, but I don't know if what I did was
actually kosher-- can I do that?

I could have replicated the Embedded RDF logic in the BMC translator,
but this was a cleaner solution-- one of the shortest translators I've
written. But it felt so much like cheating that I feel like there must
be something wrong.

If this is OK, then I'm going to go ahead and take this approach to a
good many translators that have decent metadata, but still need some
tweaking to get a quality Zotero experience (particularly for search
results and fulltext).

Avram

Simon

unread,
Oct 12, 2011, 1:15:16 AM10/12/11
to zotero-dev
If that works, it's fine for now. The preferred approach would be:

var translator = Zotero.loadTranslator("web");
translator.setTranslator("951c027d-74ac-47d4-a107-9c3069ab7b48");
translator.setDocument(doc);
translator.setHandler("itemDone", function(obj, item) {
item.abstractNote = item.extra;
item.extra = '';
item.complete();
});
translator.translate();

However, I haven't tested this, and it may be broken at present.

Simon

On Oct 11, 1:01 am, Avram Lyon <ajl...@gmail.com> wrote:
> Zotero folks,
>
> I just rewrote the BioMedCentral (et al.) translator to work mainly
> with the embedded RDF in the header, with some extra logic to handle
> search results and metadata oddities:https://github.com/ajlyon/translators/blob/dd3c956584d87cda226941f7a9...

Avram Lyon

unread,
Oct 12, 2011, 1:18:35 AM10/12/11
to zoter...@googlegroups.com
On Tue, Oct 11, 2011 at 10:15 PM, Simon <si...@simonster.com> wrote:
> If that works, it's fine for now. The preferred approach would be:
>
> var translator = Zotero.loadTranslator("web");
> translator.setTranslator("951c027d-74ac-47d4-a107-9c3069ab7b48");
> translator.setDocument(doc);
> translator.setHandler("itemDone", function(obj, item) {
>    item.abstractNote = item.extra;
>    item.extra = '';
>    item.complete();
> });
> translator.translate();
>
> However, I haven't tested this, and it may be broken at present.

I did try loadTranslator("web"), which failed. I didn't try
setDocument, which is obviously a cleaner approach than requesting the
translator object, and I'll see about that shortly.

- Avram

Avram Lyon

unread,
Oct 13, 2011, 12:06:51 AM10/13/11
to zoter...@googlegroups.com
On Tue, Oct 11, 2011 at 10:18 PM, Avram Lyon <ajl...@gmail.com> wrote:
> I did try loadTranslator("web"), which failed. I didn't try
> setDocument, which is obviously a cleaner approach than requesting the
> translator object, and I'll see about that shortly.

setDocument doesn't work either-- it looks like the web translator
functions aren't exposed to the sandbox as much as we might like.

Avram

Reply all
Reply to author
Forward
0 new messages