Skip to content

Commit

Permalink
⚡ improvement(translation): warning outputing when cannot translate w…
Browse files Browse the repository at this point in the history
…ith keypath

Closes #22
  • Loading branch information
kazupon committed May 8, 2016
1 parent d0a415f commit b4c7c0e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/extend.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { warn } from './util'
import format from './format'
import { getValue } from './path'

Expand Down Expand Up @@ -41,6 +42,14 @@ export default function (Vue) {
return args ? format(val, args) : val
}

function warnDefault (key) {
if (process.env.NODE_ENV !== 'production') {
warn('Cannot translate the value of keypath "' + key + '". '
+ 'Use the value of keypath as default')
}
return key
}


/**
* Vue.t
Expand All @@ -54,7 +63,7 @@ export default function (Vue) {
if (!key) { return '' }

const { lang, params } = parseArgs(...args)
return translate(Vue.locale(lang), key, params) || key
return translate(Vue.locale(lang), key, params) || warnDefault(key)
}


Expand All @@ -72,7 +81,7 @@ export default function (Vue) {
const { lang, params } = parseArgs(...args)
return translate(this.$options.locales && this.$options.locales[lang], key, params)
|| translate(Vue.locale(lang), key, params)
|| key
|| warnDefault(key)
}

return Vue
Expand Down

0 comments on commit b4c7c0e

Please sign in to comment.