Fix dates not following configured locale. Resolve #3559 (#3880)

This commit is contained in:
Tom Najdek 2024-05-31 12:58:14 +02:00 committed by GitHub
parent 5c1f6d065d
commit d6d9979f19
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 2 deletions

View file

@ -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);
};

View file

@ -221,6 +221,8 @@ XPCOMUtils.defineLazyModuleGetters(ZoteroContext.prototype, {
* components may not have yet been initialized. * components may not have yet been initialized.
*/ */
function makeZoteroContext() { function makeZoteroContext() {
var subscriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].getService(Ci.mozIJSSubScriptLoader);
if(zContext) { if(zContext) {
// Swap out old zContext // Swap out old zContext
var oldzContext = zContext; var oldzContext = zContext;
@ -232,10 +234,11 @@ function makeZoteroContext() {
} else { } else {
zContext = new ZoteroContext(); zContext = new ZoteroContext();
zContext.Zotero = function() {}; 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 // Load zotero.js first
subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFilesAll[0] + ".js", zContext, 'utf-8'); subscriptLoader.loadSubScript("chrome://zotero/content/xpcom/" + xpcomFilesAll[0] + ".js", zContext, 'utf-8');