Fall back to en-US sorting if we can't parse the locale

This commit is contained in:
Dan Stillman 2017-10-26 00:54:05 -04:00
parent 56289b6693
commit 1deba232fa

View File

@ -1536,7 +1536,12 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
}
// Extract a valid language tag
try {
locale = locale.match(/^[a-z]{2}(\-[A-Z]{2})?/)[0];
}
catch (e) {
throw new Error(`Error parsing locale ${locale}`);
}
locales = [locale];
}
@ -1549,13 +1554,26 @@ Services.scriptloader.loadSubScript("resource://zotero/polyfill.js");
catch (e) {
Zotero.logError(e);
// If there's an error, just skip sorting
// Fall back to en-US sorting
try {
Zotero.logError("Falling back to en-US sorting");
collator = new Intl.Collator(['en-US'], {
ignorePunctuation: true,
numeric: true,
sensitivity: 'base'
});
}
catch (e) {
Zotero.logError(e);
// If there's still an error, just skip sorting
collator = {
compare: function (a, b) {
return 0;
}
};
}
}
// Grab all ASCII punctuation and space at the begining of string
var initPunctuationRE = /^[\x20-\x2F\x3A-\x40\x5B-\x60\x7B-\x7E]+/;