Code coverage report for ./index.js

Statements: 95% (19 / 20)      Branches: 76.47% (13 / 17)      Functions: 100% (3 / 3)      Lines: 100% (19 / 19)      Ignored: none     

All files » ./ » index.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40              1 8 8 8   8 9 9 9 7 7 14 14 1 1   13       9     8     7   7        
/**
 * Expose internationalization plugin
 *
 * @param {Object} Vue
 * @param {Object} opts
 */
 
module.exports = function (Vue, opts) {
  opts = opts || {}
  var lang = opts.lang || 'en'
  var locales = opts.locales || opts.resources || {}
 
  Vue.t = function (key) {
    var ret = key || ''
    var locale = locales[lang]
    if (key && locale) {
      var namespaces = key.split('.')
      for (var i = 0; i < namespaces.length; i++) {
        locale = locale[namespaces[i]]
        if (!locale) {
          ret = key
          break
        } else {
          ret = locale
        }
      }
    }
    return ret
  }
 
  Vue.directive('t', {
    isLiteral: true,
    bind: function () {
      Iif (this.el.nodeType !== 1) { return }
 
      this.el.textContent = Vue.t(this.expression)
    }
  })
}