- Update to citeproc-js 1.0.81
- Fix "myxml.localName() is null" when using dates on non-base locales Thanks to Frank for dealing with my pestering regarding locale behavior. From citeproc-js 1.0.78: Enable the proper parsing and rendering of seasons in ranged dates, in the internal dates parser. From citeproc-js 1.0.79: Correct fault in locale fallback behavior. Had been ignoring optional default argument set in the processor. From citeproc-js 1.0.80: More fixes to locale selection behavior. Provide a toggle to override the locale of a style with the locale set on the processor at runtime. From citeproc-js 1.0.81: Yet more fixes to locale selection logic. Now uses en-US as ultimate fallback, for any missing terms or missing locales.
This commit is contained in:
parent
93ffca6833
commit
c6f3e0b844
4 changed files with 105 additions and 52 deletions
|
@ -374,18 +374,6 @@ Zotero.Cite.getMonthStrings = function(form, locale) {
|
||||||
var cslLocale = Zotero.CiteProc.CSL.localeResolve(Zotero.locale);
|
var cslLocale = Zotero.CiteProc.CSL.localeResolve(Zotero.locale);
|
||||||
if(!Zotero.CiteProc.CSL.locale[cslLocale.best]) {
|
if(!Zotero.CiteProc.CSL.locale[cslLocale.best]) {
|
||||||
let localexml = sys.xml.makeXml(Zotero.Cite.System.retrieveLocale(cslLocale.best));
|
let localexml = sys.xml.makeXml(Zotero.Cite.System.retrieveLocale(cslLocale.best));
|
||||||
if(!localexml) {
|
|
||||||
if(localexml == "en-US") {
|
|
||||||
throw "No locales.xml file could be found for the preferred locale or for en-US. "+
|
|
||||||
"Please ensure that the locales directory exists and is properly populated";
|
|
||||||
} else {
|
|
||||||
let localexml = sys.xml.makeXml(Zotero.Cite.System.retrieveLocale(cslLocale.bare));
|
|
||||||
if(!localexml) {
|
|
||||||
Zotero.log("No locale "+cslLocale.best+"; using en-US", "warning");
|
|
||||||
return Zotero.Cite.getMonthStrings(form, "en-US");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Zotero.CiteProc.CSL.localeSet.call(Zotero.CiteProc.CSL, sys, localexml, cslLocale.best, cslLocale.best);
|
Zotero.CiteProc.CSL.localeSet.call(Zotero.CiteProc.CSL, sys, localexml, cslLocale.best, cslLocale.best);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -286,12 +286,6 @@ var CSL = {
|
||||||
};
|
};
|
||||||
CSL.TERMINAL_PUNCTUATION_REGEXP = new RegExp("^([" + CSL.TERMINAL_PUNCTUATION.slice(0, -1).join("") + "])(.*)");
|
CSL.TERMINAL_PUNCTUATION_REGEXP = new RegExp("^([" + CSL.TERMINAL_PUNCTUATION.slice(0, -1).join("") + "])(.*)");
|
||||||
CSL.CLOSURES = new RegExp(".*[\\]\\)]");
|
CSL.CLOSURES = new RegExp(".*[\\]\\)]");
|
||||||
CSL.debug = function (str) {
|
|
||||||
Zotero.debug("CSL: " + str);
|
|
||||||
};
|
|
||||||
CSL.error = function (str) {
|
|
||||||
throw "CSL error: " + str;
|
|
||||||
};
|
|
||||||
var CSL_E4X = function () {};
|
var CSL_E4X = function () {};
|
||||||
CSL_E4X.prototype.clean = function (xml) {
|
CSL_E4X.prototype.clean = function (xml) {
|
||||||
xml = xml.replace(/<\?[^?]+\?>/g, "");
|
xml = xml.replace(/<\?[^?]+\?>/g, "");
|
||||||
|
@ -439,7 +433,12 @@ CSL_E4X.prototype.addInstitutionNodes = function(myxml) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
CSL.error = Zotero.debug;
|
CSL.error = function (str) {
|
||||||
|
Zotero.log("CSL: " + str, "error");
|
||||||
|
};
|
||||||
|
CSL.debug = function (str) {
|
||||||
|
Zotero.debug("CSL: " + str);
|
||||||
|
};
|
||||||
CSL.Output = {};
|
CSL.Output = {};
|
||||||
CSL.Output.Queue = function (state) {
|
CSL.Output.Queue = function (state) {
|
||||||
this.levelname = ["top"];
|
this.levelname = ["top"];
|
||||||
|
@ -1054,19 +1053,18 @@ CSL.Output.Queue.adjustPunctuation = function (state, myblobs, stk, finish) {
|
||||||
CSL.localeResolve = function (langstr) {
|
CSL.localeResolve = function (langstr) {
|
||||||
var ret, langlst;
|
var ret, langlst;
|
||||||
ret = {};
|
ret = {};
|
||||||
if ("undefined" === typeof langstr) {
|
|
||||||
langstr = "en_US";
|
|
||||||
}
|
|
||||||
langlst = langstr.split(/[\-_]/);
|
langlst = langstr.split(/[\-_]/);
|
||||||
ret.base = CSL.LANG_BASES[langlst[0]];
|
ret.base = CSL.LANG_BASES[langlst[0]];
|
||||||
if ("undefined" === typeof ret.base) {
|
if ("undefined" === typeof ret.base) {
|
||||||
throw "Locale not found \"" + langlst[0] + "\"";
|
CSL.error("unknown locale "+langstr+", setting to en-US");
|
||||||
|
return {base:"en-US", best:"en-US", bare:"en"};
|
||||||
}
|
}
|
||||||
if (langlst.length === 1 || langlst[1] === "x") {
|
if (langlst.length === 1 || langlst[1] === "x") {
|
||||||
ret.best = ret.base.replace("_", "-");
|
ret.best = ret.base.replace("_", "-");
|
||||||
} else {
|
} else {
|
||||||
ret.best = langlst.slice(0, 2).join("-");
|
ret.best = langlst.slice(0, 2).join("-");
|
||||||
}
|
}
|
||||||
|
ret.base = ret.base.replace("_", "-");
|
||||||
ret.bare = langlst[0];
|
ret.bare = langlst[0];
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
@ -1086,7 +1084,6 @@ CSL.localeSet = function (sys, myxml, lang_in, lang_out) {
|
||||||
} else {
|
} else {
|
||||||
nodes = sys.xml.getNodesByName(myxml, "locale");
|
nodes = sys.xml.getNodesByName(myxml, "locale");
|
||||||
for (pos = 0, len = sys.xml.numberofnodes(nodes); pos < len; pos += 1) {
|
for (pos = 0, len = sys.xml.numberofnodes(nodes); pos < len; pos += 1) {
|
||||||
if (true) {
|
|
||||||
blob = nodes[pos];
|
blob = nodes[pos];
|
||||||
if (sys.xml.getAttributeValue(blob, 'lang', 'xml') === lang_in) {
|
if (sys.xml.getAttributeValue(blob, 'lang', 'xml') === lang_in) {
|
||||||
locale = blob;
|
locale = blob;
|
||||||
|
@ -1094,7 +1091,6 @@ CSL.localeSet = function (sys, myxml, lang_in, lang_out) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
nodes = sys.xml.getNodesByName(locale, 'term');
|
nodes = sys.xml.getNodesByName(locale, 'term');
|
||||||
for (pos = 0, len = sys.xml.numberofnodes(nodes); pos < len; pos += 1) {
|
for (pos = 0, len = sys.xml.numberofnodes(nodes); pos < len; pos += 1) {
|
||||||
term = nodes[pos];
|
term = nodes[pos];
|
||||||
|
@ -1435,14 +1431,14 @@ CSL.dateParser = function (txt) {
|
||||||
rexdash = new RegExp(rex.replace(/%%NUMD%%/g, "-").replace(/%%DATED%%/g, "-"));
|
rexdash = new RegExp(rex.replace(/%%NUMD%%/g, "-").replace(/%%DATED%%/g, "-"));
|
||||||
rexdashslash = new RegExp(rex.replace(/%%NUMD%%/g, "-").replace(/%%DATED%%/g, "\/"));
|
rexdashslash = new RegExp(rex.replace(/%%NUMD%%/g, "-").replace(/%%DATED%%/g, "\/"));
|
||||||
rexslashdash = new RegExp(rex.replace(/%%NUMD%%/g, "\/").replace(/%%DATED%%/g, "-"));
|
rexslashdash = new RegExp(rex.replace(/%%NUMD%%/g, "\/").replace(/%%DATED%%/g, "-"));
|
||||||
seasonstrs = ["spr", "sum", "fal", "win"];
|
seasonstrs = [];
|
||||||
seasonrexes = [];
|
seasonrexes = [];
|
||||||
len = seasonstrs.length;
|
len = seasonstrs.length;
|
||||||
for (pos = 0; pos < len; pos += 1) {
|
for (pos = 0; pos < len; pos += 1) {
|
||||||
seasonrex = new RegExp(seasonstrs[pos] + ".*");
|
seasonrex = new RegExp(seasonstrs[pos] + ".*");
|
||||||
seasonrexes.push(seasonrex);
|
seasonrexes.push(seasonrex);
|
||||||
}
|
}
|
||||||
monthstrs = "jan feb mar apr may jun jul aug sep oct nov dec";
|
monthstrs = "jan feb mar apr may jun jul aug sep oct nov dec spr sum fal win spr sum";
|
||||||
monthstrs = monthstrs.split(" ");
|
monthstrs = monthstrs.split(" ");
|
||||||
monthrexes = [];
|
monthrexes = [];
|
||||||
len = monthstrs.length;
|
len = monthstrs.length;
|
||||||
|
@ -1651,9 +1647,9 @@ CSL.dateParser = function (txt) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
CSL.Engine = function (sys, style, lang, xmlmode) {
|
CSL.Engine = function (sys, style, lang, forceLang) {
|
||||||
var attrs, langspec, localexml, locale;
|
var attrs, langspec, localexml, locale;
|
||||||
this.processor_version = "1.0.76";
|
this.processor_version = "1.0.81";
|
||||||
this.csl_version = "1.0";
|
this.csl_version = "1.0";
|
||||||
this.sys = sys;
|
this.sys = sys;
|
||||||
this.sys.xml = new CSL.System.Xml.Parsing();
|
this.sys.xml = new CSL.System.Xml.Parsing();
|
||||||
|
@ -1692,16 +1688,46 @@ CSL.Engine = function (sys, style, lang, xmlmode) {
|
||||||
this.setStyleAttributes();
|
this.setStyleAttributes();
|
||||||
CSL.Util.Names.initNameSlices(this);
|
CSL.Util.Names.initNameSlices(this);
|
||||||
this.opt.xclass = sys.xml.getAttributeValue(this.cslXml, "class");
|
this.opt.xclass = sys.xml.getAttributeValue(this.cslXml, "class");
|
||||||
|
if (lang) {
|
||||||
|
lang = lang.replace("_", "-");
|
||||||
|
}
|
||||||
|
if (this.opt["default-locale"][0]) {
|
||||||
|
this.opt["default-locale"][0] = this.opt["default-locale"][0].replace("_", "-");
|
||||||
|
}
|
||||||
|
if (lang && forceLang) {
|
||||||
|
this.opt["default-locale"] = [lang];
|
||||||
|
}
|
||||||
|
if (lang && !forceLang && this.opt["default-locale"][0]) {
|
||||||
lang = this.opt["default-locale"][0];
|
lang = this.opt["default-locale"][0];
|
||||||
|
}
|
||||||
|
if (this.opt["default-locale"].length === 0) {
|
||||||
|
if (!lang) {
|
||||||
|
lang = "en-US";
|
||||||
|
}
|
||||||
|
this.opt["default-locale"].push("en-US");
|
||||||
|
}
|
||||||
|
if (!lang) {
|
||||||
|
lang = this.opt["default-locale"][0];
|
||||||
|
}
|
||||||
langspec = CSL.localeResolve(lang);
|
langspec = CSL.localeResolve(lang);
|
||||||
this.opt.lang = langspec.best;
|
this.opt.lang = langspec.best;
|
||||||
|
this.opt["default-locale"][0] = langspec.best;
|
||||||
this.locale = {};
|
this.locale = {};
|
||||||
if (!this.locale[langspec.best]) {
|
localexml = sys.xml.makeXml(sys.retrieveLocale("en-US"));
|
||||||
|
CSL.localeSet.call(this, sys, localexml, "en-US", langspec.best);
|
||||||
|
if (langspec.best !== "en-US") {
|
||||||
|
if (langspec.base !== langspec.best) {
|
||||||
|
localexml = sys.xml.makeXml(sys.retrieveLocale(langspec.base));
|
||||||
|
CSL.localeSet.call(this, sys, localexml, langspec.base, langspec.best);
|
||||||
|
}
|
||||||
localexml = sys.xml.makeXml(sys.retrieveLocale(langspec.best));
|
localexml = sys.xml.makeXml(sys.retrieveLocale(langspec.best));
|
||||||
CSL.localeSet.call(this, sys, localexml, langspec.best, langspec.best);
|
CSL.localeSet.call(this, sys, localexml, langspec.best, langspec.best);
|
||||||
}
|
}
|
||||||
CSL.localeSet.call(this, sys, this.cslXml, "", langspec.best);
|
CSL.localeSet.call(this, sys, this.cslXml, "", langspec.best);
|
||||||
CSL.localeSet.call(this, sys, this.cslXml, langspec.bare, langspec.best);
|
CSL.localeSet.call(this, sys, this.cslXml, langspec.bare, langspec.best);
|
||||||
|
if (langspec.base !== langspec.best) {
|
||||||
|
CSL.localeSet.call(this, sys, this.cslXml, langspec.base, langspec.best);
|
||||||
|
}
|
||||||
CSL.localeSet.call(this, sys, this.cslXml, langspec.best, langspec.best);
|
CSL.localeSet.call(this, sys, this.cslXml, langspec.best, langspec.best);
|
||||||
this.buildTokenLists("citation");
|
this.buildTokenLists("citation");
|
||||||
this.buildTokenLists("bibliography");
|
this.buildTokenLists("bibliography");
|
||||||
|
@ -2126,7 +2152,7 @@ CSL.Engine.Opt = function () {
|
||||||
this["locale-pri"] = [];
|
this["locale-pri"] = [];
|
||||||
this["locale-sec"] = [];
|
this["locale-sec"] = [];
|
||||||
this["locale-name"] = [];
|
this["locale-name"] = [];
|
||||||
this["default-locale"] = ["en"];
|
this["default-locale"] = [];
|
||||||
this["noun-genders"] = {};
|
this["noun-genders"] = {};
|
||||||
this.update_mode = CSL.NONE;
|
this.update_mode = CSL.NONE;
|
||||||
this.bib_mode = CSL.NONE;
|
this.bib_mode = CSL.NONE;
|
||||||
|
@ -3441,7 +3467,7 @@ CSL.Node["date-part"] = {
|
||||||
};
|
};
|
||||||
this.execs.push(func);
|
this.execs.push(func);
|
||||||
if ("undefined" === typeof this.strings["range-delimiter"]) {
|
if ("undefined" === typeof this.strings["range-delimiter"]) {
|
||||||
this.strings["range-delimiter"] = "-";
|
this.strings["range-delimiter"] = "\u2013";
|
||||||
}
|
}
|
||||||
target.push(this);
|
target.push(this);
|
||||||
}
|
}
|
||||||
|
@ -5793,7 +5819,7 @@ CSL.Transform = function (state) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
function getTextSubField(value, locale_type, use_default) {
|
function getTextSubField(value, locale_type, use_default) {
|
||||||
var m, lst, opt, o, pos, key, ret, len, myret;
|
var m, lst, opt, o, oo, pos, key, ret, len, myret;
|
||||||
if (!value) {
|
if (!value) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -5817,8 +5843,12 @@ CSL.Transform = function (state) {
|
||||||
}
|
}
|
||||||
for (key in opt) {
|
for (key in opt) {
|
||||||
if (opt.hasOwnProperty(key)) {
|
if (opt.hasOwnProperty(key)) {
|
||||||
o = opt[key];
|
oo = opt[key];
|
||||||
if (o && lst.indexOf(o) > -1 && lst.indexOf(o) % 2) {
|
o = oo.split(/[-_]/)[0];
|
||||||
|
if (oo && lst.indexOf(oo) > -1 && lst.indexOf(oo) % 2) {
|
||||||
|
ret = lst[(lst.indexOf(oo) + 1)];
|
||||||
|
break;
|
||||||
|
} else if (o && lst.indexOf(o) > -1 && lst.indexOf(o) % 2) {
|
||||||
ret = lst[(lst.indexOf(o) + 1)];
|
ret = lst[(lst.indexOf(o) + 1)];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -6828,29 +6858,59 @@ CSL.Util.Dates.year.numeric = function (state, num) {
|
||||||
};
|
};
|
||||||
CSL.Util.Dates.month = {};
|
CSL.Util.Dates.month = {};
|
||||||
CSL.Util.Dates.month.numeric = function (state, num) {
|
CSL.Util.Dates.month.numeric = function (state, num) {
|
||||||
var ret = num.toString();
|
if (num) {
|
||||||
|
num = parseInt(num, 10);
|
||||||
|
if (num > 12) {
|
||||||
|
num = "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
var ret = "" + num;
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
CSL.Util.Dates.month["numeric-leading-zeros"] = function (state, num) {
|
CSL.Util.Dates.month["numeric-leading-zeros"] = function (state, num) {
|
||||||
if (!num) {
|
if (!num) {
|
||||||
num = 0;
|
num = 0;
|
||||||
}
|
}
|
||||||
num = num.toString();
|
num = parseInt(num, 10);
|
||||||
|
if (num > 12) {
|
||||||
|
num = 0;
|
||||||
|
}
|
||||||
|
num = "" + num;
|
||||||
while (num.length < 2) {
|
while (num.length < 2) {
|
||||||
num = "0" + num;
|
num = "0" + num;
|
||||||
}
|
}
|
||||||
return num.toString();
|
return num.toString();
|
||||||
};
|
};
|
||||||
CSL.Util.Dates.month["long"] = function (state, num) {
|
CSL.Util.Dates.month["long"] = function (state, num) {
|
||||||
num = num.toString();
|
var stub = "month-";
|
||||||
|
num = parseInt(num, 10);
|
||||||
|
if (num > 12) {
|
||||||
|
stub = "season-";
|
||||||
|
if (num > 16) {
|
||||||
|
num = num - 16;
|
||||||
|
} else {
|
||||||
|
num = num - 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num = "" + num;
|
||||||
while (num.length < 2) {
|
while (num.length < 2) {
|
||||||
num = "0" + num;
|
num = "0" + num;
|
||||||
}
|
}
|
||||||
num = "month-" + num;
|
num = stub + num;
|
||||||
return state.getTerm(num, "long", 0);
|
return state.getTerm(num, "long", 0);
|
||||||
};
|
};
|
||||||
CSL.Util.Dates.month["short"] = function (state, num) {
|
CSL.Util.Dates.month["short"] = function (state, num) {
|
||||||
num = num.toString();
|
var stub = "month-";
|
||||||
|
num = parseInt(num, 10);
|
||||||
|
if (num > 12) {
|
||||||
|
stub = "season-";
|
||||||
|
if (num > 16) {
|
||||||
|
num = num - 16;
|
||||||
|
} else {
|
||||||
|
num = num - 12;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
num = "" + num;
|
||||||
while (num.length < 2) {
|
while (num.length < 2) {
|
||||||
num = "0" + num;
|
num = "0" + num;
|
||||||
}
|
}
|
||||||
|
|
|
@ -422,7 +422,12 @@ function() {
|
||||||
var xml = this.getXML();
|
var xml = this.getXML();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Zotero.CiteProc.CSL.Engine(Zotero.Cite.System, xml, Zotero.locale);
|
try {
|
||||||
|
return new Zotero.CiteProc.CSL.Engine(Zotero.Cite.System, xml, locale);
|
||||||
|
} catch(e) {
|
||||||
|
Zotero.logError(e);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Zotero.Style.prototype.__defineGetter__("class",
|
Zotero.Style.prototype.__defineGetter__("class",
|
||||||
|
|
|
@ -874,7 +874,7 @@ var Zotero = new function(){
|
||||||
* @param {Exception} err
|
* @param {Exception} err
|
||||||
*/
|
*/
|
||||||
function logError(err) {
|
function logError(err) {
|
||||||
log(err.message ? err.message : err.toString, "error",
|
log(err.message ? err.message : err.toString(), "error",
|
||||||
err.fileName ? err.fileName : null, null,
|
err.fileName ? err.fileName : null, null,
|
||||||
err.lineNumber ? err.lineNumber : null, null);
|
err.lineNumber ? err.lineNumber : null, null);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue