Skip to content

Commit

Permalink
only serve if at least one translation json exists
Browse files Browse the repository at this point in the history
  • Loading branch information
Mario Balibrera committed Jul 24, 2013
1 parent cb01153 commit 990195d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/serve/plugins/i18n/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,24 @@ function serveProject (project) {
var langPath = path.join(project.paths.root, 'resources', 'lang');

if (_trans[id] || !fs.existsSync(langPath)) { return false; }

var trans = _trans[id] = {};
var langs = fs.readdirSync(langPath);
var shouldServe = false;

for (var i = 0; i < langs.length; i++) {
var fname = langs[i];
var lparts = fname.split('.');
if (lparts[0] != 'all' && lparts[1] == 'json') {
var lang = lparts[0];
trans[lang] = JSON.parse(fs.readFileSync(path.join(langPath, fname)));
shouldServe = true;
trans[lparts[0]] = JSON.parse(fs.readFileSync(path.join(langPath, fname)));
}
}

fs.writeFileSync(path.join(langPath, 'all.json'), JSON.stringify(trans));
_app.use('/simulate/' + id + '/lang/', etag.static(langPath));
if (shouldServe) {
fs.writeFileSync(path.join(langPath, 'all.json'), JSON.stringify(trans));
_app.use('/simulate/' + id + '/lang/', etag.static(langPath));
}
}

exports.load = function (app) {
Expand Down

0 comments on commit 990195d

Please sign in to comment.