i18n = {}

i18n.db = new Mongo.Collection('halunka:i18n')
i18n.state = new ReactiveDict('i18nValues')
i18n._trns = new ReactiveDict('i18nTrns')
i18n._acts = {}

i18n.add = function i18nAdd (defTrns, trnsObj) {
  _.extend(trnsObj, this.state.get('langs'))
  trnsObj[this.state.get('default')] = defTrns
  return this.db.upsert(trnsObj, { $set: trnsObj })
}

i18n.get = function i18nget (key, lang) {
  lang = typeof lang == 'string' ? lang : this.get()
  var query = {}
  var act
  var trns
  query[this.state.get('default')] = key
  act = this.db.findOne.bind(this.db, query)
  this._acts[key + lang] = act
  this._trns.set(key + lang, act())
  trns = this._trns.get(key + lang)
  return (trns && trns[lang])
}

i18n.defaultLang = function i18nDefault (newValue) {
  return this.state.set('default', newValue)
}

i18n.addLang = function i18nAddLang (key, str) {
  var langs = this.state.get('langs') || {}
  langs[key] = str
  this.state.set('langs', langs)
}

i18n.setLang = function i18nSet (lang) {
  return this.state.set('currLang', lang)
}

i18n.getLang = function i18nGet () {
  return this.state.get('currLang') ||
    this.state.get('default') ||
    _.keys(this.state.get('langs'))[0]
}

i18n.listLang = function i18nList () {
  return _.map(this.state.get('langs'), function (val, key) {
    return {
      key: key,
      name: val
    }
  })
}

i18n.updateTrns = function i18nUpdateTrns () {
  var self = this
  _.each(this._acts, function (act, key) {
    self._trns.set(key, act())
  })
}

if(Meteor.isServer) {
  Meteor.publish('AllTranslations', function () {
    return i18n.db.find()
  })
}

if(Meteor.isClient) {
  i18n.sub = Meteor.subscribe('AllTranslations', function () {
    i18n.updateTrns()
  })
  Template.registerHelper('i18nget', i18n.get.bind(i18n))
  Template.registerHelper('i18nlist', i18n.listLang.bind(i18n))
}

@@ -223,20 +223,20 @@
 rnsObj, 
-this
+i18n
 .state.g
@@ -258,20 +258,20 @@
 trnsObj%5B
-this
+i18n
 .state.g
@@ -304,20 +304,20 @@
  return 
-this
+i18n
 .db.upse
@@ -434,20 +434,20 @@
  lang : 
-this
+i18n
 .get()%0A 
@@ -491,20 +491,20 @@
   query%5B
-this
+i18n
 .state.g
@@ -532,20 +532,20 @@
   act = 
-this
+i18n
 .db.find
@@ -553,20 +553,20 @@
 ne.bind(
-this
+i18n
 .db, que
@@ -571,20 +571,20 @@
 uery)%0A  
-this
+i18n
 ._acts%5Bk
@@ -602,20 +602,20 @@
 = act%0A  
-this
+i18n
 ._trns.s
@@ -645,20 +645,20 @@
  trns = 
-this
+i18n
 ._trns.g
@@ -759,36 +759,36 @@
 lue) %7B%0A  return 
-this
+i18n
 .state.set('defa
@@ -869,20 +869,20 @@
 langs = 
-this
+i18n
 .state.g
@@ -920,20 +920,20 @@
 = str%0A  
-this
+i18n
 .state.s
@@ -1000,28 +1000,28 @@
  %7B%0A  return 
-this
+i18n
 .state.set('
@@ -1086,20 +1086,20 @@
  return 
-this
+i18n
 .state.g
@@ -1120,20 +1120,20 @@
  %7C%7C%0A    
-this
+i18n
 .state.g
@@ -1160,20 +1160,20 @@
  _.keys(
-this
+i18n
 .state.g
@@ -1245,20 +1245,20 @@
 n _.map(
-this
+i18n
 .state.g
@@ -1411,20 +1411,20 @@
  self = 
-this
+i18n
 %0A  _.eac
@@ -1429,12 +1429,12 @@
 ach(
-this
+i18n
 ._ac
@@ -1761,27 +1761,16 @@
 i18n.get
-.bind(i18n)
 )%0A  Temp
@@ -1818,19 +1818,8 @@
 Lang
-.bind(i18n)
 )%0A%7D%0A

Make all function independent of their context