diff --git a/chrome/content/zotero/xpcom/date.js b/chrome/content/zotero/xpcom/date.js index db31cd1d1d..33381eedda 100644 --- a/chrome/content/zotero/xpcom/date.js +++ b/chrome/content/zotero/xpcom/date.js @@ -47,46 +47,41 @@ Zotero.Date = new function(){ throw new Error("Unimplemented"); } - return Zotero.HTTP.request( - 'GET', 'resource://zotero/schema/dateFormats.json', { responseType: 'json' } - ).then(function(xmlhttp) { - var json = xmlhttp.response; - - var locale = Zotero.locale; - var english = locale.startsWith('en'); - // If no exact match, try first two characters ('de') - if (!json[locale]) { - locale = locale.substr(0, 2); + var json = JSON.parse(Zotero.File.getResource('schema/dateFormats.json')); + var locale = Zotero.locale; + var english = locale.startsWith('en'); + // If no exact match, try first two characters ('de') + if (!json[locale]) { + locale = locale.substr(0, 2); + } + // Try first two characters repeated ('de-DE') + if (!json[locale]) { + locale = locale + "-" + locale.toUpperCase(); + } + // Look for another locale with same first two characters + if (!json[locale]) { + let sameLang = Object.keys(json).filter(l => l.startsWith(locale.substr(0, 2))); + if (sameLang.length) { + locale = sameLang[0]; } - // Try first two characters repeated ('de-DE') - if (!json[locale]) { - locale = locale + "-" + locale.toUpperCase(); - } - // Look for another locale with same first two characters - if (!json[locale]) { - let sameLang = Object.keys(json).filter(l => l.startsWith(locale.substr(0, 2))); - if (sameLang.length) { - locale = sameLang[0]; - } - } - // If all else fails, use English - if (!json[locale]) { - locale = 'en-US'; - english = true; - } - _months = json[locale]; + } + // If all else fails, use English + if (!json[locale]) { + locale = 'en-US'; + english = true; + } + _months = json[locale]; - // Add English versions if not already added - if (english) { - _monthsWithEnglish = _months; + // Add English versions if not already added + if (english) { + _monthsWithEnglish = _months; + } + else { + _monthsWithEnglish = {}; + for (let key in _months) { + _monthsWithEnglish[key] = _months[key].concat(json['en-US'][key]); } - else { - _monthsWithEnglish = {}; - for (let key in _months) { - _monthsWithEnglish[key] = _months[key].concat(json['en-US'][key]); - } - } - }); + } }; diff --git a/chrome/content/zotero/xpcom/file.js b/chrome/content/zotero/xpcom/file.js index 59dc2e9850..83940dcf10 100644 --- a/chrome/content/zotero/xpcom/file.js +++ b/chrome/content/zotero/xpcom/file.js @@ -339,6 +339,13 @@ Zotero.File = new function(){ xmlhttp.send(null); return xmlhttp.responseText; } + + /* + * Returns the contents of the given local resource. + */ + this.getResource = function (res) { + return getContentsFromURL(`resource://zotero/${res}`); + } /* diff --git a/chrome/content/zotero/xpcom/zotero.js b/chrome/content/zotero/xpcom/zotero.js index 509aa73b89..3c57f75e65 100644 --- a/chrome/content/zotero/xpcom/zotero.js +++ b/chrome/content/zotero/xpcom/zotero.js @@ -824,7 +824,7 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js"); // Initialize keyboard shortcuts Zotero.Keys.init(); - yield Zotero.Date.init(); + Zotero.Date.init(); Zotero.LocateManager.init(); yield Zotero.ID.init(); yield Zotero.Collections.init(); diff --git a/test/tests/dateTest.js b/test/tests/dateTest.js index 9c416bc4c1..4330f94f10 100644 --- a/test/tests/dateTest.js +++ b/test/tests/dateTest.js @@ -28,7 +28,7 @@ describe("Zotero.Date", function() { beforeEach(function* () { if (Zotero.locale != 'en-US') { Zotero.locale = 'en-US'; - yield Zotero.Date.init(); + Zotero.Date.init(); } }); @@ -52,7 +52,7 @@ describe("Zotero.Date", function() { it("should resolve to English from unknown locale", function* () { Zotero.locale = 'zz'; - yield Zotero.Date.init(); + Zotero.Date.init(); let months = Zotero.Date.getMonths().short; assert.lengthOf(months, 12); assert.sameMembers(months, englishShort); @@ -60,7 +60,7 @@ describe("Zotero.Date", function() { it("shouldn't repeat English with unknown locale", function* () { Zotero.locale = 'zz'; - yield Zotero.Date.init(); + Zotero.Date.init(); let months = Zotero.Date.getMonths(true).short; assert.lengthOf(months, 12); assert.sameMembers(months, englishShort); @@ -71,7 +71,7 @@ describe("Zotero.Date", function() { beforeEach(function* () { if (Zotero.locale != 'fr-FR') { Zotero.locale = 'fr-FR'; - yield Zotero.Date.init(); + Zotero.Date.init(); } }); @@ -101,7 +101,7 @@ describe("Zotero.Date", function() { it("should resolve from two-letter locale", function* () { Zotero.locale = 'fr'; - yield Zotero.Date.init(); + Zotero.Date.init(); let months = Zotero.Date.getMonths().short; assert.lengthOf(months, 12); assert.sameMembers(months, frenchShort); @@ -109,7 +109,7 @@ describe("Zotero.Date", function() { it("should resolve from unknown four-letter locale with common prefix", function* () { Zotero.locale = 'fr-ZZ'; - yield Zotero.Date.init(); + Zotero.Date.init(); let months = Zotero.Date.getMonths().short; assert.lengthOf(months, 12); assert.sameMembers(months, frenchShort);