Add Zotero.File.getResource for local resources
Use `getResource` in Zotero.Date.init (this turns it into a synchronous function). Zotero.File.getResource makes it easier to load local files on platforms that do not support the `resource://` URLs.
This commit is contained in:
parent
06cb9aff98
commit
53522c2cbe
4 changed files with 46 additions and 44 deletions
|
@ -47,11 +47,7 @@ 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 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')
|
||||
|
@ -86,7 +82,6 @@ Zotero.Date = new function(){
|
|||
_monthsWithEnglish[key] = _months[key].concat(json['en-US'][key]);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -340,6 +340,13 @@ Zotero.File = new function(){
|
|||
return xmlhttp.responseText;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the contents of the given local resource.
|
||||
*/
|
||||
this.getResource = function (res) {
|
||||
return getContentsFromURL(`resource://zotero/${res}`);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Return a promise for the contents of a URL as a string
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue