Improved the usage of missing translation keys (#9081)

closes #9079

- log error if missing key was used
- send client generic error message (they can look at logs to get a
better understanding)
This commit is contained in:
Vikas 2017-10-03 02:47:48 -05:00 committed by Katharina Irrgang
parent fe0dc95c49
commit b7e82f3b00

View File

@ -5,6 +5,8 @@ var supportedLocales = ['en'],
fs = require('fs'),
chalk = require('chalk'),
MessageFormat = require('intl-messageformat'),
logging = require('./logging'),
errors = require('./errors'),
// TODO: fetch this dynamically based on overall blog settings (`key = "default_locale"`) in the `settings` table
currentLocale = 'en',
@ -65,12 +67,14 @@ I18n = {
path = msgPath.split('.');
path.forEach(function (key) {
// reassign matching object, or set to an empty string if there is no match
matchingString = matchingString[key] || null;
matchingString = matchingString[key] || {};
});
if (_.isNull(matchingString)) {
console.error('Unable to find matching path [' + msgPath + '] in locale file.\n');
matchingString = 'i18n error: path "' + msgPath + '" was not found.';
if (_.isObject(matchingString) || _.isEqual(matchingString, {})) {
logging.error(new errors.IncorrectUsageError({
message: `i18n error: path "${msgPath}" was not found`
}));
matchingString = blos.errors.errors.anErrorOccurred;
}
return matchingString;