/*
PHP
$language = $this->load->language('product/product');

$this->data['languageForJS'] = array(
  'product/product' => $language
);

JS
language.add(<?php echo json_encode($languageForJS) ?>);

language.load('produtc/product');
language.get('my_text')
*/

(function(window) {
  function Language() {
    this.languages = {};
    this.languageLoaded = {};
  };

  Language.prototype.get = function(key) {
    return this.languageLoaded[key];
  };

  Language.prototype.load = function(name) {
    if (typeof this.languages[name] != 'undefined') {
      this.languageLoaded = this.languages[name];
    }
  };

  Language.prototype.add = function(languageObjectFromPHP) {
    for (var key in languageObjectFromPHP) {
      if (languageObjectFromPHP.hasOwnProperty(key)) {
        this.languages[key] = languageObjectFromPHP[key];
      }
    }
  };

  window.language = new Language();
})(window);