Export translator: Add identical information to all exported items

Dear all,

I'm currently writing a translator that exports a bibliography into a MARCXML file adapted to the needs of our institution. My aim is to start from a list produce the final file without invoking another script afterwards. As several items contain the same information internal to our institution (which need to remain local), I was wondering if there is a way to include it directly in the translator. In this case, Zotero serves to complete and harmonise the metadata of the entries and the bibliography in question is not synced with the server (just adding this bit for completeness' sake).

A brief description of how I've solved the problem so far:
- Before exporting, I create an additional entry which can be easily intercepted during runtime (e. g., something which would never show up in our bibliographies and has a distinct title) that holds the common metadata.
- My translator runs through all entries with a "while ((item = Zotero.nextItem()))" loop and intercepts the common-metadata item from which the information can be extracted. Since it is impossile to know nor influence when that special item is found, dummy entries are placed in the MARC fields corresponding with the common metadata.
- Once the while loop has run through all items, the translator replaces the dummies with their corresponding common metadata. If a MARCXML subfield needs to be added, e. g. to the author data, replace the existing author name subfield with a string composed of this subfield plus a linebreak (and tabs) and a subfield containing the new information.
- Write the output file.

Since the last step is rather messy to program, I was wondering if there is a possibility to prompt the user for information using a popup window similar to Z.alert() (that would be SO easy!!). In this way, the user could fill in a list of items, which would settle the whole thing. I haven't found anything in the documentation, but since it's not complete, I was wondering if someone knows more than the website. Alternatively, is it possible to search an item in a bibliography with the export translator I'm passing the bibliography to? I tried playing around with Z.search() to identify the special entry beforehand, but that doesn't seem to work in the translator and I'm getting the error message "Z.search is not a function" (it seems to be limited to playing around in scaffold/the console).

Am I missing something or is my solution really the only possibility to achieve what I want? I'd like to state again that my goal is to avoid having to use another script on the exported MARCXML file.

Thanks in advance for some leads :)
  • Probably better to take this to the dev list, but in short, within the translator framework, the answer to both your questions is no -- there's no option for user input during the import or export process and you can't combine a search operation with an export operation.

    But what would be possible -- and I may be missing something in your description which is still a bit confusing to me -- would be to just hardcode value for certain MARC fields.
  • Thanks for you quick reply! The dev list might have been a suitable option as well, but I don't think it's necessary to go into the technical details.

    re hardcoding: I was a bit unspecific in order to keep my post sufficiently short, but realise I should have added that the common metadata are the same for one export but are very likely to change between several exports. Since I want to give the script to other users of our group, I'd like to avoid obliging them to edit the translator before using it :)
  • I already provide a MARC21XML export translator at https://github.com/UB-Mannheim/zotkat and happy to collaborate on that, if that suits your use case. For yes/no decisions I used some uncommon displayOptions.

    You can also use the (hidden) Zotero preferences and create some customized fields there, or it should be possible to read a JSON file which can be placed besides the translator file.

    It is also possible to look up data within Zotero, e.g. for author data from a authority file, and append this information to the entries. However, at some point I guess that making a Zotero cataloguing plugin would be the way to go.
  • Export translators can't do this though. While it's technically possible to reach into zotero using a companion plugin, reading anything from the db is going to require async code, and export translators in the current zotero are strictly sync.

    This discussion going to keep veering back into the more technical. What translators can and cannot do is inescapably technical.
  • @emilianoeheyns To which "this" are you referring here:

    > Export translators can't do this though.

    I have used my suggested approaches like displayOptions and hidden preferences before, run the linked script, and I am quite sure that reading a local JSON should work as well in the Zotero translators.
  • edited February 5, 2020
    "this" being access to the Zotero database. You can add options and hidden preferences, true, but even with a plugin, you can't access the database. BBT does reach into Zotero from the translators, but as long as the export translators are strictly async, even if you can get to the database through the plugin, you can't wait for the result.

    edit: Zotero.File.getContentsFromURL seems to be sync. Zotero.File.getContents should also be able to read data from disk through a plugin, so you could read a json from disk. You can bridge methods into the translator through a plugin. But database methods are not sync, so that's still not possible.
Sign In or Register to comment.