diff --git a/generate/Dialog.js b/generate/Dialog.js index d801434..8c895d7 100644 --- a/generate/Dialog.js +++ b/generate/Dialog.js @@ -32,14 +32,18 @@ module.exports = class Dialog { return this; } - getText(key, params = {}) { + getText(key, params = {}, errorOnMissingKey = true) { const value = this.i18n.t(key, { ...params, returnObjects: true }); // i18next returns the key if the value isn't available in the locale, or // fallback translation. // TODO: Discuss how to verify that each function will return a valid dialog text if (value === key) { - throw new Error('No translation key available for key [' + key + '].'); + if (errorOnMissingKey) { + throw new Error('No translation key available for key [' + key + '].'); + } + + return '' } if (Array.isArray(value)) { diff --git a/utils/craftResponse.js b/utils/craftResponse.js index 8f1bbcf..0d6f299 100644 --- a/utils/craftResponse.js +++ b/utils/craftResponse.js @@ -18,7 +18,7 @@ module.exports = ({ return '' } - const response = dialogMap[state] ? dialogMap[state](context, dialog) : dialog(`${conversationType}.${state}`, context) + const response = dialogMap[state] ? dialogMap[state](context, dialog) : dialog(`${conversationType}.${state}`, context, false) return context.resuming && !overrideResume && dialogMap.resume(context) ? `${dialogMap.resume(context)} ${response}` : response