diff --git a/chrome/content/zotero/bibliography.js b/chrome/content/zotero/bibliography.js index c61be77be..aaf7713eb 100644 --- a/chrome/content/zotero/bibliography.js +++ b/chrome/content/zotero/bibliography.js @@ -34,16 +34,13 @@ var Zotero_File_Interface_Bibliography = new function() { var _io, _saveStyle; - - this.init = init; - this.styleChanged = styleChanged; - this.acceptSelection = acceptSelection; + var lastSelectedLocale; // Only changes when explicitly selected /* * Initialize some variables and prepare event listeners for when chrome is done * loading */ - function init() { + this.init = function () { // Set font size from pref // Affects bibliography.xul and integrationDocPrefs.xul var bibContainer = document.getElementById("zotero-bibliography-container"); @@ -59,18 +56,18 @@ var Zotero_File_Interface_Bibliography = new function() { } var listbox = document.getElementById("style-listbox"); - var styles = Zotero.Styles.getVisible(); - // if no style is set, get the last style used + // if no style is requested, get the last style used if(!_io.style) { _io.style = Zotero.Prefs.get("export.lastStyle"); _saveStyle = true; } // add styles to list + var styles = Zotero.Styles.getVisible(); var index = 0; var nStyles = styles.length; - var selectIndex = -1; + var selectIndex = null; for(var i=0; i + + + + + + diff --git a/chrome/content/zotero/fileInterface.js b/chrome/content/zotero/fileInterface.js index 67dd69056..ba3ac11a7 100644 --- a/chrome/content/zotero/fileInterface.js +++ b/chrome/content/zotero/fileInterface.js @@ -420,15 +420,15 @@ var Zotero_File_Interface = new function() { * * Does not check that items are actual references (and not notes or attachments) */ - function copyItemsToClipboard(items, style, asHTML, asCitations) { + function copyItemsToClipboard(items, style, locale, asHTML, asCitations) { // copy to clipboard var transferable = Components.classes["@mozilla.org/widget/transferable;1"]. createInstance(Components.interfaces.nsITransferable); var clipboardService = Components.classes["@mozilla.org/widget/clipboard;1"]. getService(Components.interfaces.nsIClipboard); var style = Zotero.Styles.get(style); - var cslEngine = style.getCiteProc(); - + var cslEngine = style.getCiteProc(locale); + // add HTML var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, "html", asCitations); var str = Components.classes["@mozilla.org/supports-string;1"]. @@ -458,14 +458,14 @@ var Zotero_File_Interface = new function() { * * if |asHTML| is true, copy HTML source as text */ - function copyCitationToClipboard(items, style, asHTML) { + function copyCitationToClipboard(items, style, locale, asHTML) { // copy to clipboard var transferable = Components.classes["@mozilla.org/widget/transferable;1"]. createInstance(Components.interfaces.nsITransferable); var clipboardService = Components.classes["@mozilla.org/widget/clipboard;1"]. getService(Components.interfaces.nsIClipboard); - var style = Zotero.Styles.get(style).getCiteProc(); + var style = Zotero.Styles.get(style).getCiteProc(locale); var citation = {"citationItems":[{id:item.id} for each(item in items)], properties:{}}; // add HTML @@ -518,14 +518,17 @@ var Zotero_File_Interface = new function() { format = "rtf"; } + // determine locale preference + var locale = io.locale; + // generate bibliography try { if(io.method == 'copy-to-clipboard') { - copyItemsToClipboard(items, io.style, false, io.mode === "citations"); + Zotero_File_Interface.copyItemsToClipboard(items, io.style, locale, false, io.mode === "citations"); } else { var style = Zotero.Styles.get(io.style); - var cslEngine = style.getCiteProc(); + var cslEngine = style.getCiteProc(locale); var bibliography = Zotero.Cite.makeFormattedBibliographyOrCitationList(cslEngine, items, format, io.mode === "citations"); } diff --git a/chrome/content/zotero/integration/integrationDocPrefs.xul b/chrome/content/zotero/integration/integrationDocPrefs.xul index 8ac6bdbc3..e2a3a8ab3 100644 --- a/chrome/content/zotero/integration/integrationDocPrefs.xul +++ b/chrome/content/zotero/integration/integrationDocPrefs.xul @@ -48,6 +48,13 @@ + + + + + + + diff --git a/chrome/content/zotero/locale/csl b/chrome/content/zotero/locale/csl index d2b612f8a..c1679e2d7 160000 --- a/chrome/content/zotero/locale/csl +++ b/chrome/content/zotero/locale/csl @@ -1 +1 @@ -Subproject commit d2b612f8a6f764cbd66e67238636fac3888a7736 +Subproject commit c1679e2d7ec0819f73a486507c0c2d2a29cef3ed diff --git a/chrome/content/zotero/preferences/preferences_export.js b/chrome/content/zotero/preferences/preferences_export.js index 1f134e88d..7dfc1fa0a 100644 --- a/chrome/content/zotero/preferences/preferences_export.js +++ b/chrome/content/zotero/preferences/preferences_export.js @@ -44,10 +44,18 @@ Zotero_Preferences.Export = { populateQuickCopyList: function () { // Initialize default format drop-down var format = Zotero.Prefs.get("export.quickCopy.setting"); + format = Zotero.QuickCopy.unserializeSetting(format); var menulist = document.getElementById("zotero-quickCopy-menu"); - this.buildQuickCopyFormatDropDown(menulist, Zotero.QuickCopy.getContentType(format), format); + this.buildQuickCopyFormatDropDown(menulist, format.contentType, format); menulist.setAttribute('preference', "pref-quickCopy-setting"); - this.updateQuickCopyHTMLCheckbox(); + + // Initialize locale drop-down + var localeMenulist = document.getElementById("zotero-quickCopy-locale-menu"); + Zotero.Styles.populateLocaleList(localeMenulist); + localeMenulist.setAttribute('preference', "pref-quickCopy-locale"); + + this._lastSelectedLocale = Zotero.Prefs.get("export.quickCopy.locale"); + this.updateQuickCopyUI(); if (!Zotero.isStandalone) { this.refreshQuickCopySiteList(); @@ -58,12 +66,12 @@ Zotero_Preferences.Export = { /* * Builds a Quick Copy drop-down */ - buildQuickCopyFormatDropDown: function (menulist, contentType, currentFormat) { - if (!currentFormat) { - currentFormat = menulist.value; + buildQuickCopyFormatDropDown: function (menulist, contentType, format) { + if (!format) { + format = menulist.value; } - // Strip contentType from mode - currentFormat = Zotero.QuickCopy.stripContentType(currentFormat); + + format = Zotero.QuickCopy.unserializeSetting(format); menulist.selectedItem = null; menulist.removeAllItems(); @@ -86,15 +94,14 @@ Zotero_Preferences.Export = { // add styles to list var styles = Zotero.Styles.getVisible(); for each(var style in styles) { - var baseVal = 'bibliography=' + style.styleID; var val = 'bibliography' + (contentType == 'html' ? '/html' : '') + '=' + style.styleID; var itemNode = document.createElement("menuitem"); itemNode.setAttribute("value", val); itemNode.setAttribute("label", style.title); - itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyHTMLCheckbox()'); + itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyUI()'); popup.appendChild(itemNode); - if (baseVal == currentFormat) { + if (format.mode == 'bibliography' && format.id == style.styleID) { menulist.selectedItem = itemNode; } } @@ -115,14 +122,14 @@ Zotero_Preferences.Export = { case '14763d24-8ba0-45df-8f52-b8d1108e7ac9': continue; } - var val = 'export=' + translators[i].translatorID; + var val = 'export=' + translators[i].translatorID; var itemNode = document.createElement("menuitem"); itemNode.setAttribute("value", val); itemNode.setAttribute("label", translators[i].label); - itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyHTMLCheckbox()'); + itemNode.setAttribute("oncommand", 'Zotero_Preferences.Export.updateQuickCopyUI()'); popup.appendChild(itemNode); - if (val == currentFormat) { + if (format.mode == 'export' && format.id == translators[i].translatorID) { menulist.selectedItem = itemNode; } } @@ -133,16 +140,23 @@ Zotero_Preferences.Export = { }, - updateQuickCopyHTMLCheckbox: function () { + updateQuickCopyUI: function () { var format = document.getElementById('zotero-quickCopy-menu').value; + var mode, contentType; - var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML'); [mode, format] = format.split('='); [mode, contentType] = mode.split('/'); + var checkbox = document.getElementById('zotero-quickCopy-copyAsHTML'); checkbox.checked = contentType == 'html'; checkbox.disabled = mode != 'bibliography'; + + Zotero.Styles.updateLocaleList( + document.getElementById('zotero-quickCopy-locale-menu'), + mode == 'bibliography' ? Zotero.Styles.get(format) : null, + this._lastSelectedLocale + ); }, /** @@ -164,19 +178,24 @@ Zotero_Preferences.Export = { showQuickCopySiteEditor: function (index) { var treechildren = document.getElementById('quickCopy-siteSettings-rows'); - if (index != undefined && index > -1 && index < treechildren.childNodes.length) { + var formattedName = document.getElementById('zotero-quickCopy-menu').label; + var locale = this._lastSelectedLocale; + var asHTML = document.getElementById('zotero-quickCopy-copyAsHTML').checked; + + if (index !== undefined && index > -1 && index < treechildren.childNodes.length) { var treerow = treechildren.childNodes[index].firstChild; var domain = treerow.childNodes[0].getAttribute('label'); - var format = treerow.childNodes[1].getAttribute('label'); - var asHTML = treerow.childNodes[2].getAttribute('label') != ''; + formattedName = treerow.childNodes[1].getAttribute('label'); + locale = treerow.childNodes[2].getAttribute('label'); + asHTML = treerow.childNodes[3].getAttribute('label') !== ''; } - var format = Zotero.QuickCopy.getSettingFromFormattedName(format); + var format = Zotero.QuickCopy.getSettingFromFormattedName(formattedName); if (asHTML) { format = format.replace('bibliography=', 'bibliography/html='); } - var io = {domain: domain, format: format, ok: false}; + var io = {domain: domain, format: format, locale: locale, asHTML: asHTML, ok: false}; window.openDialog('chrome://zotero/content/preferences/quickCopySiteEditor.xul', "zotero-preferences-quickCopySiteEditor", "chrome,modal,centerscreen", io); @@ -188,7 +207,10 @@ Zotero_Preferences.Export = { Zotero.DB.query("DELETE FROM settings WHERE setting='quickCopySite' AND key=?", [domain]); } - Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, io.format]); + var quickCopysetting = Zotero.QuickCopy.unserializeSetting(io.format); + quickCopysetting.locale = io.locale; + + Zotero.DB.query("REPLACE INTO settings VALUES ('quickCopySite', ?, ?)", [io.domain, JSON.stringify(quickCopysetting)]); this.refreshQuickCopySiteList(); }, @@ -213,18 +235,22 @@ Zotero_Preferences.Export = { var treerow = document.createElement('treerow'); var domainCell = document.createElement('treecell'); var formatCell = document.createElement('treecell'); - var HTMLCell = document.createElement('treecell'); + var localeCell = document.createElement('treecell'); + var htmlCell = document.createElement('treecell'); domainCell.setAttribute('label', siteData[i].domainPath); - var formatted = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format); - formatCell.setAttribute('label', formatted); - var copyAsHTML = Zotero.QuickCopy.getContentType(siteData[i].format) == 'html'; - HTMLCell.setAttribute('label', copyAsHTML ? ' ✓ ' : ''); + var formattedName = Zotero.QuickCopy.getFormattedNameFromSetting(siteData[i].format); + formatCell.setAttribute('label', formattedName); + + var format = Zotero.QuickCopy.unserializeSetting(siteData[i].format); + localeCell.setAttribute('label', format.locale); + htmlCell.setAttribute('label', format.contentType == 'html' ? ' ✓ ' : ''); treerow.appendChild(domainCell); treerow.appendChild(formatCell); - treerow.appendChild(HTMLCell); + treerow.appendChild(localeCell); + treerow.appendChild(htmlCell); treeitem.appendChild(treerow); treechildren.appendChild(treeitem); } @@ -253,9 +279,9 @@ Zotero_Preferences.Export = { } instr.appendChild(document.createTextNode(str)); - var key = Zotero.Prefs.get('keys.copySelectedItemCitationsToClipboard'); - var str = Zotero.getString('zotero.preferences.export.quickCopy.citationInstructions', prefix + key); - var instr = document.getElementById('quickCopy-citationInstructions'); + key = Zotero.Prefs.get('keys.copySelectedItemCitationsToClipboard'); + str = Zotero.getString('zotero.preferences.export.quickCopy.citationInstructions', prefix + key); + instr = document.getElementById('quickCopy-citationInstructions'); while (instr.hasChildNodes()) { instr.removeChild(instr.firstChild); } diff --git a/chrome/content/zotero/preferences/preferences_export.xul b/chrome/content/zotero/preferences/preferences_export.xul index 378533509..f2b57a1c3 100644 --- a/chrome/content/zotero/preferences/preferences_export.xul +++ b/chrome/content/zotero/preferences/preferences_export.xul @@ -23,7 +23,12 @@ ***** END LICENSE BLOCK ***** --> - + + %prefWindow; + + %common; +]> + @@ -49,10 +55,15 @@ - + + + + + + diff --git a/chrome/content/zotero/tools/csledit.js b/chrome/content/zotero/tools/csledit.js index 1bcbc6a91..5234ec5aa 100644 --- a/chrome/content/zotero/tools/csledit.js +++ b/chrome/content/zotero/tools/csledit.js @@ -27,39 +27,32 @@ var Zotero_CSL_Editor = new function() { this.init = init; this.handleKeyPress = handleKeyPress; this.loadCSL = loadCSL; - this.generateBibliography = generateBibliography; - this.refresh = refresh; function init() { - var cslList = document.getElementById('zotero-csl-list'); - if (cslList.getAttribute('initialized') == 'true') { - if (currentStyle) { - loadCSL(currentStyle); - refresh(); - } - return; - } + Zotero.Styles.populateLocaleList(document.getElementById("locale-menu")); - var rawDefaultStyle = Zotero.Prefs.get('export.quickCopy.setting'); - var defaultStyle = Zotero.QuickCopy.stripContentType(rawDefaultStyle); + var cslList = document.getElementById('zotero-csl-list'); + cslList.removeAllItems(); + + var lastStyle = Zotero.Prefs.get('export.lastStyle'); var styles = Zotero.Styles.getAll(); var currentStyle = null; - var listPos = 0; for each(var style in styles) { if (style.source) { continue; } var item = cslList.appendItem(style.title, style.styleID); - if (!currentStyle || defaultStyle == ('bibliography=' + style.styleID)) { - currentStyle = style.styleID; - cslList.selectedIndex = listPos; + if (!currentStyle && lastStyle == style.styleID) { + currentStyle = style; + cslList.selectedItem = item; } - listPos += 1; } + if (currentStyle) { - loadCSL(currentStyle); - refresh(); + // Call asynchronously, see note in Zotero.Styles + window.setTimeout(this.onStyleSelected.bind(this, currentStyle.styleID), 1); } + var pageList = document.getElementById('zotero-csl-page-type'); var locators = Zotero.Cite.labels; for each(var type in locators) { @@ -69,13 +62,25 @@ var Zotero_CSL_Editor = new function() { } pageList.selectedIndex = 0; - cslList.setAttribute('initialized', true); } - function refresh() { - var editor = document.getElementById('zotero-csl-editor'); - generateBibliography(editor.value); - + + this.onStyleSelected = function(styleID) { + Zotero.Prefs.set('export.lastStyle', styleID); + let style = Zotero.Styles.get(styleID); + Zotero.Styles.updateLocaleList( + document.getElementById("locale-menu"), + style, + Zotero.Prefs.get('export.lastLocale') + ); + + loadCSL(style.styleID); + this.refresh(); } + + this.refresh = function() { + this.generateBibliography(this.loadStyleFromEditor()); + } + this.save = function() { var editor = document.getElementById('zotero-csl-editor'); var style = editor.value; @@ -120,20 +125,52 @@ var Zotero_CSL_Editor = new function() { document.getElementById('zotero-csl-list').value = cslID; } + this.loadStyleFromEditor = function() { + var styleObject; + try { + styleObject = new Zotero.Style( + document.getElementById('zotero-csl-editor').value + ); + } catch(e) { + document.getElementById('zotero-csl-preview-box') + .contentDocument.documentElement.innerHTML = '
' + + Zotero.getString('styles.editor.warning.parseError') + + '
' + e + '
'; + throw e; + } + + return styleObject; + } - function generateBibliography(str) { - var editor = document.getElementById('zotero-csl-editor') + this.onStyleModified = function(str) { + document.getElementById('zotero-csl-list').selectedIndex = -1; + + let styleObject = this.loadStyleFromEditor(); + + Zotero.Styles.updateLocaleList( + document.getElementById("locale-menu"), + styleObject, + Zotero.Prefs.get('export.lastLocale') + ); + Zotero_CSL_Editor.generateBibliography(styleObject); + } + + this.generateBibliography = function(style) { var iframe = document.getElementById('zotero-csl-preview-box'); var items = Zotero.getActiveZoteroPane().getSelectedItems(); if (items.length == 0) { - iframe.contentDocument.documentElement.innerHTML = '

' + Zotero.getString('styles.editor.warning.noItems') + '

'; + iframe.contentDocument.documentElement.innerHTML = + '

' + + Zotero.getString('styles.editor.warning.noItems') + + '

'; return; } - var styleObject, styleEngine; + + var selectedLocale = document.getElementById("locale-menu").value; + var styleEngine; try { - styleObject = new Zotero.Style(str); - styleEngine = styleObject.getCiteProc(); + styleEngine = style.getCiteProc(style.locale || selectedLocale); } catch(e) { iframe.contentDocument.documentElement.innerHTML = '
' + Zotero.getString('styles.editor.warning.parseError') + '
'+e+'
'; throw e; diff --git a/chrome/content/zotero/tools/csledit.xul b/chrome/content/zotero/tools/csledit.xul index f646d266f..a46192ac9 100644 --- a/chrome/content/zotero/tools/csledit.xul +++ b/chrome/content/zotero/tools/csledit.xul @@ -58,12 +58,13 @@ - + + + oncommand="Zotero_CSL_Editor.onStyleModified()"/> diff --git a/chrome/content/zotero/tools/cslpreview.js b/chrome/content/zotero/tools/cslpreview.js index fcc9828af..8ff06009d 100644 --- a/chrome/content/zotero/tools/cslpreview.js +++ b/chrome/content/zotero/tools/cslpreview.js @@ -30,7 +30,10 @@ var Zotero_CSL_Preview = new function() { this.generateBibliography = generateBibliography; function init() { - //refresh(); + var menulist = document.getElementById("locale-menu"); + + Zotero.Styles.populateLocaleList(menulist); + menulist.value = Zotero.Prefs.get('export.lastLocale');; var iframe = document.getElementById('zotero-csl-preview-box'); iframe.contentDocument.documentElement.innerHTML = '

' + Zotero.getString('styles.preview.instructions') + '

'; @@ -86,7 +89,9 @@ var Zotero_CSL_Preview = new function() { Zotero.debug("CSL IGNORE: citation format is " + style.categories); return ''; } - var styleEngine = style.getCiteProc(); + + var locale = document.getElementById("locale-menu").value; + var styleEngine = style.getCiteProc(locale); // Generate multiple citations var citations = styleEngine.previewCitationCluster( diff --git a/chrome/content/zotero/tools/cslpreview.xul b/chrome/content/zotero/tools/cslpreview.xul index 0b984577a..3f60c1f04 100644 --- a/chrome/content/zotero/tools/cslpreview.xul +++ b/chrome/content/zotero/tools/cslpreview.xul @@ -56,6 +56,8 @@
+ +