From 9fbe467e6ed9458e9f1af49c64c814791da707ea Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 13 Mar 2018 14:58:18 +0300 Subject: [PATCH] :zap: improvement(index): support retunable missing handler (#256) by @houd1ni Missing() can produce some dynamic results, using it's own fallback algorythm and make something like 'header.nav.toHome' -> 'To Home' transformation e.g. It's would be interesting to make it async, but it seems that it's a little bit deeper change. --- src/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/index.js b/src/index.js index aa00879e0..9134e0419 100644 --- a/src/index.js +++ b/src/index.js @@ -171,8 +171,11 @@ export default class VueI18n { _warnDefault (locale: Locale, key: Path, result: ?any, vm: ?any, values: any): ?string { if (!isNull(result)) { return result } - if (this._missing) { - this._missing.apply(null, [locale, key, vm, values]) + if (this.missing) { + const missingResult = this.missing.call(null, locale, key, vm) + if (typeof missingResult === 'string') { + return missingResult + } } else { if (process.env.NODE_ENV !== 'production' && !this._silentTranslationWarn) { warn(