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:
parent
fda5df9a82
commit
f5d544bc15
3 changed files with 18 additions and 10 deletions
|
@ -442,7 +442,12 @@ Zotero.ItemTypes = new function() {
|
||||||
return _customLabels[id];
|
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) {
|
this.getImageSrc = function (itemType) {
|
||||||
|
|
|
@ -77,15 +77,12 @@ Zotero.ItemFields = new function() {
|
||||||
|
|
||||||
for (let field of fields) {
|
for (let field of fields) {
|
||||||
let isBaseField = baseFields.includes(field.fieldID);
|
let isBaseField = baseFields.includes(field.fieldID);
|
||||||
let label;
|
let label = field.label || Zotero.Schema.globalSchemaLocale.fields[field.fieldName];
|
||||||
try {
|
// If string not available, use the field name, except for some base fields that aren't
|
||||||
label = field.label || Zotero.Schema.globalSchemaLocale.fields[field.fieldName];
|
// used in the UI and therefore aren't localized
|
||||||
}
|
if (!label && !['number', 'type', 'medium'].includes(field.fieldName)) {
|
||||||
// Some base fields aren't localized
|
Zotero.logError(`Localized string not available for field '${field.fieldName}'`);
|
||||||
catch (e) {
|
label = Zotero.Utilities.Internal.camelToTitleCase(field.fieldName);
|
||||||
if (!isBaseField) {
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_fields[field.fieldID] = {
|
_fields[field.fieldID] = {
|
||||||
|
|
|
@ -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) {
|
resolveLocale: function (locale, locales) {
|
||||||
// If the locale exists as-is, use it
|
// If the locale exists as-is, use it
|
||||||
if (locales.includes(locale)) {
|
if (locales.includes(locale)) {
|
||||||
|
|
Loading…
Reference in a new issue