From 303a32dce65b24f8f827426df0b6435403ffc158 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 30 Jan 2014 13:30:49 -0500 Subject: [PATCH 1/3] closes #855 - app.alert strings are now passed through translator so we can finally start getting rid of the remainder of hardcoded strings --- public/language/en/global.json | 11 ++++++++++- public/src/app.js | 13 ++++++++----- public/src/forum/account.js | 4 ++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/public/language/en/global.json b/public/language/en/global.json index 210486f0a9..3cdef1742c 100644 --- a/public/language/en/global.json +++ b/public/language/en/global.json @@ -38,5 +38,14 @@ "motd.follow": "Follow", "previouspage": "Previous Page", - "nextpage": "Next Page" + "nextpage": "Next Page", + + "alert.success": "Success", + "alert.error": "Error", + + "alert.banned": "Banned", + "alert.banned.message": "You are banned you will be logged out!", + + "alert.unfollow": "You are no longer following %1!", + "alert.follow": "You are now following %1!" } diff --git a/public/src/app.js b/public/src/app.js index 8659ed3c00..9e41fb3a47 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -113,8 +113,8 @@ var socket, socket.on('event:banned', function() { app.alert({ - title: 'Banned', - message: 'You are banned you will be logged out!', + title: '[[global:alert.banned]]', + message: '[[global:alert.banned.message]]', type: 'warning', timeout: 1000 }); @@ -190,7 +190,10 @@ var socket, if (params.location == null) params.location = 'alert_window'; - $('#' + params.location).prepend(div.fadeIn('100')); + translator.translate(div.html(), function(translatedHTML) { + div.html(translatedHTML); + $('#' + params.location).prepend(div.fadeIn('100')); + }); if (params.timeout) { startTimeout(div, params.timeout); @@ -212,7 +215,7 @@ var socket, timeout = 2000; app.alert({ - title: 'Success', + title: '[[global:alert.success]]', message: message, type: 'success', timeout: timeout @@ -224,7 +227,7 @@ var socket, timeout = 2000; app.alert({ - title: 'Error', + title: '[[global:alert.error]]', message: message, type: 'danger', timeout: timeout diff --git a/public/src/forum/account.js b/public/src/forum/account.js index e3c3ec7fe5..b15613810a 100644 --- a/public/src/forum/account.js +++ b/public/src/forum/account.js @@ -44,7 +44,7 @@ define(['forum/accountheader'], function(header) { followBtn.addClass('hide'); unfollowBtn.removeClass('hide'); - app.alertSuccess('You are now following ' + username + '!'); + app.alertSuccess('[[global:alert.follow, ' + username + ']]'); }); return false; }); @@ -59,7 +59,7 @@ define(['forum/accountheader'], function(header) { followBtn.removeClass('hide'); unfollowBtn.addClass('hide'); - app.alertSuccess('You are no longer following ' + username + '!'); + app.alertSuccess('[[global:alert.unfollow, ' + username + ']]'); }); return false; }); From 68105c62892390e103806c0e1d0cf9293c654a65 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 30 Jan 2014 13:37:30 -0500 Subject: [PATCH 2/3] send environment state to client --- src/routes/api.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/routes/api.js b/src/routes/api.js index 32c38363f7..571f2c0eb9 100644 --- a/src/routes/api.js +++ b/src/routes/api.js @@ -50,6 +50,7 @@ var path = require('path'), config.postsPerPage = meta.config.postsPerPage || 20; config.maximumFileSize = meta.config.maximumFileSize; config.defaultLang = meta.config.defaultLang || 'en'; + config.environment = process.env.NODE_ENV res.json(200, config); }); From 112a9cb532d2e86c58a6ca6870251c17e02c7656 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Thu, 30 Jan 2014 13:51:28 -0500 Subject: [PATCH 3/3] closes #689 --- public/src/app.js | 8 ++++++++ src/socket.io/tools.js | 9 +++++++++ 2 files changed, 17 insertions(+) create mode 100644 src/socket.io/tools.js diff --git a/public/src/app.js b/public/src/app.js index 9e41fb3a47..868e6af112 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -125,6 +125,14 @@ var socket, socket.on('meta.updateHeader', app.updateHeader); app.enterRoom('global'); + + if (config.environment === 'development' && console && console.log) { + var log = console.log; + console.log = function() { + log.apply(this, arguments); + socket.emit('tools.log', arguments); + } + } } }, async: false diff --git a/src/socket.io/tools.js b/src/socket.io/tools.js new file mode 100644 index 0000000000..27aa6f071e --- /dev/null +++ b/src/socket.io/tools.js @@ -0,0 +1,9 @@ +var winston = require('winston'); + +var SocketTools = {}; + +SocketTools.log = function(socket, data, callback) { + winston.info("captured console.log:", data) +}; + +module.exports = SocketTools; \ No newline at end of file