Fix: i18n error message
This commit is contained in:
parent
f305719db3
commit
381ee88e94
|
@ -673,6 +673,37 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"styleMetaErrorCheckbox": {
|
||||||
|
"message": "Invalid @var checkbox: value must be 0 or 1",
|
||||||
|
"description": "Error displayed when the value of @var checkbox is invalid"
|
||||||
|
},
|
||||||
|
"styleMetaErrorColor": {
|
||||||
|
"message": "$COLOR$ is not a valid color",
|
||||||
|
"description": "Error displayed when the value of @var color is invalid",
|
||||||
|
"placeholders": {
|
||||||
|
"color": {
|
||||||
|
"content": "$1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"styleMetaErrorSelectMissingKey": {
|
||||||
|
"message": "Invalid @var select: missing key '$KEY$'",
|
||||||
|
"description": "Error displayed when the value of @var select is not a valid key",
|
||||||
|
"placeholders": {
|
||||||
|
"key": {
|
||||||
|
"content": "$1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"styleMetaErrorSelect": {
|
||||||
|
"message": "Invalid @var select: $ERROR$",
|
||||||
|
"description": "Error displayed when the value of @var select is invalid",
|
||||||
|
"placeholders": {
|
||||||
|
"error": {
|
||||||
|
"content": "$1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"styleMissingMeta": {
|
"styleMissingMeta": {
|
||||||
"message": "Missing medata @$KEY$",
|
"message": "Missing medata @$KEY$",
|
||||||
"description": "Error displayed when a mandatory metadata is missing",
|
"description": "Error displayed when a mandatory metadata is missing",
|
||||||
|
|
|
@ -59,7 +59,7 @@ var usercss = (function () {
|
||||||
function parse(color) {
|
function parse(color) {
|
||||||
el.style.color = color;
|
el.style.color = color;
|
||||||
if (el.style.color === '') {
|
if (el.style.color === '') {
|
||||||
throw new Error(`"${color}" is not a valid color`);
|
throw new Error(chrome.i18n.getMessage('styleMetaErrorColor', color));
|
||||||
}
|
}
|
||||||
color = getComputedStyle(el).color;
|
color = getComputedStyle(el).color;
|
||||||
el.style.color = '';
|
el.style.color = '';
|
||||||
|
@ -158,7 +158,11 @@ var usercss = (function () {
|
||||||
// select type has an additional field
|
// select type has an additional field
|
||||||
if (result.type === 'select') {
|
if (result.type === 'select') {
|
||||||
const match = matchString(source);
|
const match = matchString(source);
|
||||||
result.select = JSON.parse(match.follow);
|
try {
|
||||||
|
result.select = JSON.parse(match.follow);
|
||||||
|
} catch (err) {
|
||||||
|
throw new Error(chrome.i18n.getMessage('styleMetaErrorSelect', err.message));
|
||||||
|
}
|
||||||
source = match.value;
|
source = match.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,11 +270,10 @@ var usercss = (function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function validVar(va, value = 'default') {
|
function validVar(va, value = 'default') {
|
||||||
// FIXME: i18n
|
|
||||||
if (va.type === 'select' && !va.select[va[value]]) {
|
if (va.type === 'select' && !va.select[va[value]]) {
|
||||||
throw new Error(`Invalid @var select: missing key '${va[value]}'`);
|
throw new Error(chrome.i18n.getMessage('styleMetaErrorSelectMissingKey', va[value]));
|
||||||
} else if (va.type === 'checkbox' && !/^[01]$/.test(va[value])) {
|
} else if (va.type === 'checkbox' && !/^[01]$/.test(va[value])) {
|
||||||
throw new Error('Invalid @var checkbox: value must be 0 or 1');
|
throw new Error(chrome.i18n.getMessage('styleMetaErrorCheckbox'));
|
||||||
} else if (va.type === 'color') {
|
} else if (va.type === 'color') {
|
||||||
va[value] = colorParser.format(colorParser.parse(va[value]));
|
va[value] = colorParser.format(colorParser.parse(va[value]));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user