diff --git a/chrome/content/zotero/dateOverrides.js b/chrome/content/zotero/dateOverrides.js new file mode 100644 index 0000000000..54e6ad6cdf --- /dev/null +++ b/chrome/content/zotero/dateOverrides.js @@ -0,0 +1,18 @@ +/* eslint-disable no-extend-native */ +const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); + +let originalToLocaleString = Date.prototype.toLocaleString; +Date.prototype.toLocaleString = function (locales, options) { + if (locales === undefined || (Array.isArray(locales) && !locales.length)) { + locales = Services.locale.requestedLocales; + } + return originalToLocaleString.call(this, locales, options); +}; + +let originalToLocaleDateString = Date.prototype.toLocaleDateString; +Date.prototype.toLocaleDateString = function (locales, options) { + if (locales === undefined || (Array.isArray(locales) && !locales.length)) { + locales = Services.locale.requestedLocales; + } + return originalToLocaleDateString.call(this, locales, options); +}; diff --git a/chrome/content/zotero/zotero.mjs b/chrome/content/zotero/zotero.mjs index 43063d9657..bc547cc7fe 100644 --- a/chrome/content/zotero/zotero.mjs +++ b/chrome/content/zotero/zotero.mjs @@ -221,6 +221,8 @@ XPCOMUtils.defineLazyModuleGetters(ZoteroContext.prototype, { * components may not have yet been initialized. */ function makeZoteroContext() { + var subscriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); + if(zContext) { // Swap out old zContext var oldzContext = zContext; @@ -232,10 +234,11 @@ function makeZoteroContext() { } else { zContext = new ZoteroContext(); zContext.Zotero = function() {}; + + // Override Date prototype to follow Zotero configured locale #3880 + subscriptLoader.loadSubScript("chrome://zotero/content/dateOverrides.js"); } - var subscriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader); - // Load zotero.js first subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFilesAll[0] + ".js", zContext, 'utf-8');