translator
Version:
[ABANDONED] Translator for node and also for browser
61 lines (47 loc) • 1.8 kB
JavaScript
// Generated by CoffeeScript 1.6.3
(function() {
var Json, Loader, callsite, fs, isBrowser, path,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
Loader = require('./Loader');
path = require('../node/path');
isBrowser = typeof window !== 'undefined';
if (!isBrowser) {
callsite = require('callsite');
fs = require('fs');
}
Json = (function(_super) {
__extends(Json, _super);
Json.prototype.directory = '/app/lang';
function Json(directory) {
var stack;
this.directory = directory != null ? directory : this.directory;
if (this.directory.charAt(0) === '.' && isBrowser) {
throw new Error('Relative paths to dictionaries is not supported in browser.');
}
if (this.directory.charAt(0) === '.') {
stack = callsite();
this.directory = path.dirname(stack[1].getFileName());
}
if (!isBrowser) {
this.directory = path.normalize(this.directory);
}
}
Json.prototype.load = function(parent, name, language) {
var data, e, _path;
_path = this.getFileSystemPath(parent, name, language);
try {
data = require(_path);
} catch (_error) {
e = _error;
data = {};
}
return data;
};
Json.prototype.getFileSystemPath = function(parent, name, language) {
return this.directory + (parent !== '' ? '/' + parent : '') + ("/" + language + "." + name + ".json");
};
return Json;
})(Loader);
module.exports = Json;
}).call(this);