Reformatting Author names

9 views
Skip to first unread message

Gracile

unread,
Nov 14, 2009, 2:07:29 PM11/14/09
to zotero-dev
Hello,

I'm a newbie in javascript and I'm using the Adam Crymble's tutorial
to write a translator for "Doctrinal" (http://www.doctrinal.fr/
doctrinal/ - password needed unfortunately, I can access it only from
my University)

I need to reformat author names: I have to check if there is one
author and to reverse the order last name/first name.
My script is ok for single author. However I don't find the solution
for multiple author.
The syntax seems ok but I might been mistaken on the regexp...
Authors are separated by a <br> and first name/last name by a comma
and a white space (", ").

Thank you so much if you can have a look on my code: it is so
frustrating after hours.

if (itemTypes["Auteur(s)"]) {
var author = itemTypes["Auteur(s)"];
if (author.match(/\s{2}/)) {
var authors = author.split(/\s{2}/);
for (j = authors.length-1; j>-1; j--) {
var words = new Array();
words[j] = authors[j].split(", ");
var authorFixed = '';
for (i = words[j].length-1; i > -1; i--) {
authorFixed = authorFixed + words[i] + ' ';
}
for (var i in authors) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(authorFixed
[i], 'author'));
}

}
} else {
var authorName = itemTypes["Auteur(s)"];
var words = authorName.split(", ");
var authorFixed = '';
for (i = words.length-1; i > -1; i--) {
authorFixed = authorFixed + words[i] + ' ';
}
newItem.creators.push(Zotero.Utilities.cleanAuthor(authorFixed,
'author'));
}

Gracile

unread,
Nov 15, 2009, 2:04:04 PM11/15/09
to zotero-dev
I've found the solution: I should use the param useComma of the
cleanAuthor function (see: http://www.zotero.org/support/dev/translators_reference_guide
which I should have read before - sorry!).

The code is much simpler as you can see:

if (itemTypes["Auteur(s)"]) {

var author = itemTypes["Auteur(s)"];
if (author.match(/\s{2,2}/)) {

var authors = author.split(/\s{2,2}/);
for (j = authors.length-1; j > -1; j--) {
newItem.creators.push(Zotero.Utilities.cleanAuthor(authors[j],
'author', true));
}
} else {
var authorName = itemTypes["Auteur(s)"];
newItem.creators.push(Zotero.Utilities.cleanAuthor(authorName,
'author', true));
Reply all
Reply to author
Forward
0 new messages