load date strings from Fx dateFormat bundle instead of using citeproc-js
This commit is contained in:
parent
ac9d524a9f
commit
83d34a9f77
2 changed files with 33 additions and 40 deletions
|
@ -372,39 +372,4 @@ Zotero.Cite.makeFormattedBibliography = function(cslEngine, format) {
|
||||||
|
|
||||||
Zotero.Cite.labels = ["page", "book", "chapter", "column", "figure", "folio",
|
Zotero.Cite.labels = ["page", "book", "chapter", "column", "figure", "folio",
|
||||||
"issue", "line", "note", "opus", "paragraph", "part", "section", "sub verbo",
|
"issue", "line", "note", "opus", "paragraph", "part", "section", "sub verbo",
|
||||||
"volume", "verse"];
|
"volume", "verse"];
|
||||||
|
|
||||||
Zotero.Cite._monthStrings = false;
|
|
||||||
Zotero.Cite.getMonthStrings = function(form, locale) {
|
|
||||||
if(Zotero.Cite._monthStrings){
|
|
||||||
return Zotero.Cite._monthStrings[form];
|
|
||||||
} else {
|
|
||||||
Zotero.Cite._monthStrings = {"long":[], "short":[]};
|
|
||||||
|
|
||||||
var sys = {'xml':new Zotero.CiteProc.CSL.System.Xml.Parsing()};
|
|
||||||
if(!locale) locale = Zotero.locale;
|
|
||||||
|
|
||||||
var cslLocale = Zotero.CiteProc.CSL.localeResolve(Zotero.locale);
|
|
||||||
if(!Zotero.CiteProc.CSL.locale[cslLocale.best]) {
|
|
||||||
let localexml = sys.xml.makeXml(Zotero.Cite.System.retrieveLocale(cslLocale.best));
|
|
||||||
Zotero.CiteProc.CSL.localeSet.call(Zotero.CiteProc.CSL, sys, localexml, cslLocale.best, cslLocale.best);
|
|
||||||
}
|
|
||||||
|
|
||||||
var locale = Zotero.CiteProc.CSL.locale[cslLocale.best];
|
|
||||||
if(!locale) {
|
|
||||||
Zotero.log("No locale "+cslLocale.best+"; using en-US", "warning");
|
|
||||||
return Zotero.Cite.getMonthStrings(form, "en-US");
|
|
||||||
}
|
|
||||||
|
|
||||||
for(let i=1; i<=12; i++) {
|
|
||||||
let term = locale.terms["month-"+(i<10 ? "0" : "")+i];
|
|
||||||
if(term) {
|
|
||||||
Zotero.Cite._monthStrings["long"][i-1] = term["long"];
|
|
||||||
Zotero.Cite._monthStrings["short"][i-1] = (term["short"] ? term["short"].replace(".", "", "g") : term["long"]);
|
|
||||||
} else {
|
|
||||||
Zotero.log("No month "+i+" specified for locale "+cslLocale.best, "warning");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Zotero.Cite._monthStrings[form];
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -45,7 +45,35 @@ Zotero.Date = new function(){
|
||||||
this.getLocaleDateOrder = getLocaleDateOrder;
|
this.getLocaleDateOrder = getLocaleDateOrder;
|
||||||
|
|
||||||
var _localeDateOrder = null;
|
var _localeDateOrder = null;
|
||||||
|
var _months = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load dateFormat bundle into _dateFormatsBundle
|
||||||
|
*/
|
||||||
|
function _loadDateFormatsBundle() {
|
||||||
|
var src = 'chrome://global/locale/dateFormat.properties';
|
||||||
|
var localeService = Components.classes['@mozilla.org/intl/nslocaleservice;1'].
|
||||||
|
getService(Components.interfaces.nsILocaleService);
|
||||||
|
var appLocale = localeService.getApplicationLocale();
|
||||||
|
|
||||||
|
var bundle =
|
||||||
|
Components.classes["@mozilla.org/intl/stringbundle;1"]
|
||||||
|
.getService(Components.interfaces.nsIStringBundleService).createBundle(src, appLocale);
|
||||||
|
|
||||||
|
_months = {"short":[], "long":[]};
|
||||||
|
for(let i=1; i<=12; i++) {
|
||||||
|
_months.short.push(bundle.GetStringFromName("month."+i+".Mmm"));
|
||||||
|
_months.long.push(bundle.GetStringFromName("month."+i+".name"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Lazy getter for reading month strings from dateFormat.properties
|
||||||
|
*/
|
||||||
|
this.__defineGetter__("months", function() {
|
||||||
|
if(!_months) _loadDateFormatsBundle();
|
||||||
|
return _months;
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an SQL date in the form '2006-06-13 11:03:05' into a JS Date object
|
* Convert an SQL date in the form '2006-06-13 11:03:05' into a JS Date object
|
||||||
|
@ -305,9 +333,9 @@ Zotero.Date = new function(){
|
||||||
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
|
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul',
|
||||||
'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
|
||||||
// If using a non-English bibliography locale, try those too
|
// If using a non-English bibliography locale, try those too
|
||||||
if (Zotero.locale != 'en-US') {
|
//if (Zotero.locale != 'en-US') {
|
||||||
months = months.concat(Zotero.Cite.getMonthStrings("short"));
|
months = months.concat(Zotero.Date.months.short);
|
||||||
}
|
//}
|
||||||
if(!_monthRe) {
|
if(!_monthRe) {
|
||||||
_monthRe = new RegExp("^(.*)\\b("+months.join("|")+")[^ ]*(?: (.*)$|$)", "i");
|
_monthRe = new RegExp("^(.*)\\b("+months.join("|")+")[^ ]*(?: (.*)$|$)", "i");
|
||||||
}
|
}
|
||||||
|
@ -383,7 +411,7 @@ Zotero.Date = new function(){
|
||||||
string += date.part+" ";
|
string += date.part+" ";
|
||||||
}
|
}
|
||||||
|
|
||||||
var months = Zotero.Cite.getMonthStrings("long");
|
var months = Zotero.Date.months.long;
|
||||||
if(date.month != undefined && months[date.month]) {
|
if(date.month != undefined && months[date.month]) {
|
||||||
// get short month strings from CSL interpreter
|
// get short month strings from CSL interpreter
|
||||||
string += months[date.month];
|
string += months[date.month];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue