Generate label if type/field name isn't available in global schema

E.g., show "Foo Bar" for field fooBar if not available

This could happen after downgrading if the global schema couldn't be
read from the DB for some reason.
This commit is contained in:
Dan Stillman 2019-12-11 03:08:33 -07:00
parent fda5df9a82
commit f5d544bc15
3 changed files with 18 additions and 10 deletions

View file

@ -442,7 +442,12 @@ Zotero.ItemTypes = new function() {
return _customLabels[id];
}
return Zotero.Schema.globalSchemaLocale.itemTypes[typeName];
var label = Zotero.Schema.globalSchemaLocale.itemTypes[typeName];
if (!label) {
Zotero.logError(`Localized string not available for item type '${typeName}'`);
label = Zotero.Utilities.Internal.camelToTitleCase(typeName);
}
return label;
}
this.getImageSrc = function (itemType) {

View file

@ -77,15 +77,12 @@ Zotero.ItemFields = new function() {
for (let field of fields) {
let isBaseField = baseFields.includes(field.fieldID);
let label;
try {
label = field.label || Zotero.Schema.globalSchemaLocale.fields[field.fieldName];
}
// Some base fields aren't localized
catch (e) {
if (!isBaseField) {
throw e;
}
let label = field.label || Zotero.Schema.globalSchemaLocale.fields[field.fieldName];
// If string not available, use the field name, except for some base fields that aren't
// used in the UI and therefore aren't localized
if (!label && !['number', 'type', 'medium'].includes(field.fieldName)) {
Zotero.logError(`Localized string not available for field '${field.fieldName}'`);
label = Zotero.Utilities.Internal.camelToTitleCase(field.fieldName);
}
_fields[field.fieldID] = {

View file

@ -1375,6 +1375,12 @@ Zotero.Utilities.Internal = {
},
camelToTitleCase: function (str) {
str = str.replace(/([A-Z])/g, " $1");
return str.charAt(0).toUpperCase() + str.slice(1);
},
resolveLocale: function (locale, locales) {
// If the locale exists as-is, use it
if (locales.includes(locale)) {