mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-10 23:36:14 -05:00
Do not log error if i18n.doesTranslationKeyExist
is called
no issue - when calling `doesTranslationKeyExist`, we want to know if a key exists, we don't want to log if the key was not found - this can mess up the server log
This commit is contained in:
parent
76689ecbee
commit
c4044aa498
1 changed files with 11 additions and 7 deletions
|
@ -50,8 +50,10 @@ I18n = {
|
||||||
* @param {string} msgPath Path with in the JSON language file to desired string (ie: "errors.init.jsNotBuilt")
|
* @param {string} msgPath Path with in the JSON language file to desired string (ie: "errors.init.jsNotBuilt")
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
findString: function findString(msgPath) {
|
findString: function findString(msgPath, opts) {
|
||||||
var matchingString, path;
|
var options = _.merge({log: true}, opts || {}),
|
||||||
|
matchingString, path;
|
||||||
|
|
||||||
// no path? no string
|
// no path? no string
|
||||||
if (_.isEmpty(msgPath) || !_.isString(msgPath)) {
|
if (_.isEmpty(msgPath) || !_.isString(msgPath)) {
|
||||||
chalk.yellow('i18n:t() - received an empty path.');
|
chalk.yellow('i18n:t() - received an empty path.');
|
||||||
|
@ -69,11 +71,13 @@ I18n = {
|
||||||
// reassign matching object, or set to an empty string if there is no match
|
// reassign matching object, or set to an empty string if there is no match
|
||||||
matchingString = matchingString[key] || {};
|
matchingString = matchingString[key] || {};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (_.isObject(matchingString) || _.isEqual(matchingString, {})) {
|
if (_.isObject(matchingString) || _.isEqual(matchingString, {})) {
|
||||||
|
if (options.log) {
|
||||||
logging.error(new errors.IncorrectUsageError({
|
logging.error(new errors.IncorrectUsageError({
|
||||||
message: `i18n error: path "${msgPath}" was not found`
|
message: `i18n error: path "${msgPath}" was not found`
|
||||||
}));
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
matchingString = blos.errors.errors.anErrorOccurred;
|
matchingString = blos.errors.errors.anErrorOccurred;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,7 +85,7 @@ I18n = {
|
||||||
},
|
},
|
||||||
|
|
||||||
doesTranslationKeyExist: function doesTranslationKeyExist(msgPath) {
|
doesTranslationKeyExist: function doesTranslationKeyExist(msgPath) {
|
||||||
var translation = I18n.findString(msgPath);
|
var translation = I18n.findString(msgPath, {log: false});
|
||||||
return translation !== blos.errors.errors.anErrorOccurred;
|
return translation !== blos.errors.errors.anErrorOccurred;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue