Adapting the csv translator with parsed dates

I would like to adapt the CSV.js translator to include the parsed version of the publication date, but I do not know how to retrieve the list of available field. Any help warmly appreciated !
Andreas
  • The list of all available fields can be found over the API:

    https://api.zotero.org/itemFields

    However, not all fields are present in all item types.

    But I don't know exactly what field you are missing at the moment in the CSV translator. Maybe, you can give an example?
  • aurimasv.github.io/z2csl/typeMap.xml
    also has a complete list afaik.
  • Thanks a lot zuphilip and adamsmith ! I will try with that information.
    The CSV translator provides the (publication) date as it has been entered, I can see that zotero is able to parse heterogenous formats and extract Y M D, my aim is to retrieve this structured information so that I do not have to replicate zotero's algorythm later.
  • Thanks again Philipp,

    (I just saw that you are the author of the csv translator, so I am getting it straight from the horse's mouth !)
    Looking at the list your linked to, it seems that the parsed DMY information Zotero displays is not natively available in the field list.
    Is there a piece of code I could use to include in your translator so that heterogeneous data values such as "05.02.2016", "5 february 2016", "05/02/2016" and "february 5, 2016" all get rendered as something like "05-02-2016" ?

    Best regards from the Swiss Alps
    Andreas
  • I haven't looked at the translator, but I'd say the first step would be to get a proper date object usingZotero.Utilities.strToDate(item.date)
  • edited February 6, 2016
    There is a function strToDate, which I think is exactly what you are looking for. Greetings to my home country!

    Update: Actually, strToISO is even better for this porpuse.
  • Actually, we should consider to export the normalized date in the official CSV translator either instead or additionally. @adamsmith What do you think?
  • I'd be very much in favor of that, but how'd you normalize it? Probably to ISO, right, because it's a table format?
  • Here is an example of what we have currently (only some columns shown):

    PY Date Date Added Date Modified Access Date
    2016 05.02.2016 2016-02-05 20:48:17 2016-02-05 20:48:31
    2016 Januar 1, 2016 2016-01-21 22:10:48 2016-01-21 22:10:48 2016-01-21 22:10:48

    And AFAIK "Date" is just purily "item.date". If we replace the date with by "ZU.strToDate(item.date)" we should have

    PY Date Date Added Date Modified Access Date
    2016 2016-02-05 2016-02-05 20:48:17 2016-02-05 20:48:31
    2016 2016-01-01 2016-01-21 22:10:48 2016-01-21 22:10:48 2016-01-21 22:10:48

    Does this sound good? Or is there any use case to have also the not-normalized date as well?
  • edited February 5, 2016
    I'd say no to a use case for non-normalized date, but maybe leave commented-out code in there that'd add a column with that?

    edit: and yes, that does sound good.
  • Okay, a translator fix is now up. Your version of Zotero will automatically update within 24hs, or you can update manually using the "Update Now" button in the "General" tab of the Zotero preferences. If you're using Standalone, restart Zotero and your browser after updating. Any further problems let us know & thanks for reporting.
  • Hey, this is great !

    My management wanted an additional argument for switching to Zotero.
    I think you just gave the final word.

    Thanks a lot to both of you.
  • Dear all,
    I am using the csv translator to export a list of authors for specific articles (in a style close to chicago).
    Around the line 160 of the js file, the value "i" uses item.creator.lengh, but it uses all creators, I only want authors. Is there a way to adapt the counter so that it only refers to "autors" ?
    Any hint warmly welcome...
    Best
    Andreas
  • The CSV translator should already put authors and for example editors in different columns (by default authors land in column D and editors in column AP). In the translator code the getValue function will be called once with field="creators/author" and later with field="creators/editor". The creators which don't match for the current function call will be filtered out with the lines https://github.com/zotero/translators/blob/master/CSV.js#L165-167 .
  • Thanks Philip,
    The CSV translator works well indeed, I am using it as a base to do something else, which requires me to count the number of authors, I was hoping to be able to do it with the item.creator.length, but this counts also the editors (although editors are filetered out later, as you mentioned), so that comparing "i" value and item.creator.lenght to flag the last author doesn't work. Would you have any suggestion ?
    Best
    Andreas
  • Ah, I see you are adapting this translator for another purpose. I think you have to use another variable and increment accordingly, i.e.

    In the beginning of the for loop add
    var count = 0;
    and in the end of the for loop add
    count++;

    Then just output the variable j for the function call with field="creators/author".
  • Thanks Phillp, will try
  • It worked wonderfully.
    Thanks again, without you we couldn't have solved our local problem (and I wouldn't have spent those days learning basic javascript with as much success).
    Enjoy the summer.
    Andreas
Sign In or Register to comment.