Ticket #1278: 05-day-suffixes.patch

File 05-day-suffixes.patch, 6.0 KB (added by fbennett, 8 years ago)
  • chrome/content/zotero/xpcom/csl.js

    Only in zotero-trunk/chrome/content/zotero: addCitationDialog.js.orig
    Only in zotero-trunk/chrome/content/zotero: addCitationDialog.js.rej
    diff -r -u zotero-trunk.orig/chrome/content/zotero/xpcom/csl.js zotero-trunk/chrome/content/zotero/xpcom/csl.js
    old new  
    4848        Zotero.debug("CSL: style class is "+this.class); 
    4949         
    5050        this.hasBibliography = (this._csl.bibliography.length() ? 1 : 0); 
     51        this.daySuffixes = Zotero.getString("date.daySuffixes").replace(/, ?/g, "|").split("|"); 
     52        for each (i in [0,1,2,3]) { 
     53                if (suffix = this._getTerm("ordinal-0"+(i+1), false, false, false, true)) { 
     54                    this.daySuffixes[i] = suffix; 
     55                } 
     56            } 
     57 
    5158} 
    5259 
    5360/* 
     
    491498/* 
    492499 * gets a term, in singular or plural form 
    493500 */ 
    494 Zotero.CSL.prototype._getTerm = function(term, plural, form, includePeriod) { 
     501Zotero.CSL.prototype._getTerm = function(term, plural, form, includePeriod, quiet) { 
    495502        if(!form) { 
    496503                form = "long"; 
    497504        } 
     
    504511                } else if(form != "long") { 
    505512                        return this._getTerm(term, plural, "long"); 
    506513                } else { 
     514                    if (!quiet) { 
    507515                        Zotero.debug("CSL: WARNING: could not find term \""+term+'"'); 
     516                    } 
    508517                        return ""; 
    509518                } 
    510519        } 
     
    809818                                for(var j=0; j<variables.length; j++) { 
    810819                                        if(ignore[0][variables[j]]) continue; 
    811820                                         
    812                                         var text = item.getNumericVariable(variables[j], form); 
     821                                        var text = item.getNumericVariable(variables[j], citationItem, form, this.daySuffixes); 
    813822                                        if(text) { 
    814823                                                newString.append(text); 
    815824                                                success = true; 
     
    925934                        for(var j=0; j<variables.length; j++) { 
    926935                                if(ignore[0][variables[j]]) continue; 
    927936                                 
    928                                 var date = item.getDate(variables[j]); 
     937                                var date = item.getDate(variables[j], citationItem); 
    929938                                if(!date) continue; 
    930939                                 
    931940                                var variableString = formattedString.clone(); 
     
    10571066                                                                        } 
    10581067                                                                        else if(Zotero.CSL._dateVariables[variables[j]]) { 
    10591068                                                                                // getDate not false/undefined 
    1060                                                                                 exists = !!item.getDate(variables[j]); 
     1069                                                                                exists = !!item.getDate(variables[j], citationItem); 
    10611070                                                                        } else if(Zotero.CSL._namesVariables[variables[j]]) { 
    10621071                                                                                // getNames not false/undefined, not empty 
    10631072                                                                                exists = item.getNames(variables[j]); 
     
    10671076                                                                                if (exists) exists = !!exists.length; 
    10681077                                                                        } 
    10691078                                                                } else if (attribute == "is-numeric") { 
    1070                                                                         exists = item.getNumericVariable(variables[j]); 
     1079                                                                    exists = item.getNumericVariable(variables[j], citationItem); 
    10711080                                                                } else if (attribute == "is-date") { // XXX - this needs improving 
    10721081                                                                        if (Zotero.CSL._dateVariables[variables[j]]) { 
    1073                                                                                 exists = !!item.getDate(variables[j]); 
     1082                                                                            exists = !!item.getDate(variables[j], citationItem); 
    10741083                                                                        } 
    10751084                                                                } else if(attribute == "is-plural") { 
    10761085                                                                        if(Zotero.CSL._namesVariables[variables[j]]) { 
     
    17571766/* 
    17581767 * Gets an Item.Date object for a specific type. 
    17591768 */ 
    1760 Zotero.CSL.Item.prototype.getDate = function(variable) { 
     1769Zotero.CSL.Item.prototype.getDate = function(variable, citationItem) { 
    17611770        // ignore accessed date 
    17621771        if(this._ignoreURL && variable == "accessed") return false; 
    17631772         
    17641773        // load date variable if possible 
    17651774        this._refreshItem(); 
    1766         if(this._dates[variable] == undefined) { 
    1767                 this._createDate(variable); 
     1775        if(this._dates[variable] == undefined || citationItem) { 
     1776                this._createDate(variable, citationItem); 
    17681777        } 
    17691778         
    17701779        if(this._dates[variable]) return this._dates[variable]; 
     
    18551864/* 
    18561865 * convert a number into a ordinal number 1st, 2nd, 3rd etc. 
    18571866 */ 
    1858 Zotero.CSL.Item.prototype.makeOrdinal = function(value) { 
     1867Zotero.CSL.Item.prototype.makeOrdinal = function(value, daySuffixes) { 
    18591868        var ind = parseInt(value); 
    1860         var daySuffixes = Zotero.getString("date.daySuffixes").replace(/, ?/g, "|").split("|"); 
    18611869        value += (parseInt(ind/10)%10) == 1 ? daySuffixes[3] : (ind % 10 == 1) ? daySuffixes[0] : (ind % 10 == 2) ? daySuffixes[1] : (ind % 10 == 3) ? daySuffixes[2] : daySuffixes[3]; 
    18621870        return value; 
    18631871} 
     
    19171925 * Gets a numeric object for a specific type. <number variable="edition" form="roman"/> 
    19181926 */ 
    19191927// citationItem argument to function gets access to locator field 
    1920 Zotero.CSL.Item.prototype.getNumericVariable = function(variable, citationItem, form) { 
     1928// daySuffixes argument provides array for building localized ordinals 
     1929Zotero.CSL.Item.prototype.getNumericVariable = function(variable, citationItem, form, daySuffixes) { 
    19211930 
    19221931        if(!Zotero.CSL.Item._zoteroNumberFieldMap[variable]) return ""; 
    19231932         
     
    19441953                if(value != "" && (matches = value.match(Zotero.CSL._numberRegexp)) ) { 
    19451954                        value = matches[0]; 
    19461955                        if (form == "ordinal") { 
    1947                                 return this.makeOrdinal(value); 
     1956                            return this.makeOrdinal(value, daySuffixes); 
    19481957                        } 
    19491958                        else if (form == "roman") {  
    19501959                                return this.makeRoman(value); 
     
    20802089 * Generates an date object for a given variable (currently supported: issued 
    20812090 * and accessed) 
    20822091 */ 
    2083 Zotero.CSL.Item.prototype._createDate = function(variable) { 
     2092Zotero.CSL.Item.prototype._createDate = function(variable, citationItem) { 
    20842093        // first, figure out what date variable to use. 
    20852094        if(variable == "issued") { 
     2095            if (citationItem && citationItem.issued) { 
     2096                var date = citationItem.issued 
     2097            } else { 
    20862098                var date = this.zoteroItem.getField("date", false, true); 
    2087                 var sort = this.zoteroItem.getField("date", true, true); 
     2099            } 
     2100            var sort = this.zoteroItem.getField("date", true, true); 
    20882101        } else if(variable == "accessed") { 
    20892102                var date = this.zoteroItem.getField("accessDate", false, true); 
    20902103                var sort = this.zoteroItem.getField("accessDate", true, true);