diff --git a/app.js b/app.js index 362d6604dc..1e46c3c667 100644 --- a/app.js +++ b/app.js @@ -86,20 +86,18 @@ global.templates = {}; - translator.loadAll(function () { - // todo: replace below with read directory code, derp. - templates.init([ - 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', - 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', - 'emails/header', 'emails/footer', + translator.loadServer(); - 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic' - ]); - - templates.ready(webserver.init); - }); + // todo: replace below with read directory code, derp. + templates.init([ + 'header', 'footer', 'logout', 'outgoing', 'admin/header', 'admin/footer', 'admin/index', + 'emails/reset', 'emails/reset_plaintext', 'emails/email_confirm', 'emails/email_confirm_plaintext', + 'emails/header', 'emails/footer', + 'noscript/header', 'noscript/home', 'noscript/category', 'noscript/topic' + ]); + templates.ready(webserver.init); }); } else if (nconf.get('upgrade')) { diff --git a/public/language/en/login.json b/public/language/en/login.json index f63e708750..947395a46d 100644 --- a/public/language/en/login.json +++ b/public/language/en/login.json @@ -4,5 +4,7 @@ "password": "Password", "remember_me": "Remember Me?", "forgot_password": "Forgot Password?", - "alternative_logins": "Alternative Logins" + "alternative_logins": "Alternative Logins", + "failed_login_attempt": "Failed login attempt, please try again.", + "login_successful": "You have successfully logged in!" } \ No newline at end of file diff --git a/public/language/en/topic.json b/public/language/en/topic.json new file mode 100644 index 0000000000..d83049ef5c --- /dev/null +++ b/public/language/en/topic.json @@ -0,0 +1,4 @@ +{ + "favourites.not_logged_in.title": "Not Logged In", + "favourites.not_logged_in.message": "Please log in in order to favourite this post" +} \ No newline at end of file diff --git a/public/src/translator.js b/public/src/translator.js index ea2709e95d..645faa378d 100644 --- a/public/src/translator.js +++ b/public/src/translator.js @@ -3,7 +3,10 @@ /*global RELATIVE_PATH*/ /* - * TODO: language en is hardcoded while system is developed. + * TODO: + * + * 1. language en is hardcoded while system is developed. + * 2. recursion needed when parsing language keys (ex. topics:modal.delete.title), right now json is all one level deep */ var translator = {}, @@ -11,11 +14,20 @@ loaded: {}, loading: {}, callbacks: {} - }; + }, + isServer = false; module.exports = translator; translator.load = function (filename, callback) { + if (isServer === true) { + if (callback) { + callback(files.loaded[filename]); + } + + return files.loaded[filename]; + } + if (files.loaded[filename] && !files.loading[filename]) { if (callback) { callback(files.loaded[filename]); @@ -46,7 +58,9 @@ } }; - translator.loadAll = function (callback) { + translator.loadServer = function () { + isServer = true; + var utils = require('./utils.js'), path = require('path'), fs = require('fs'); @@ -56,16 +70,7 @@ for (var d in data) { if (data.hasOwnProperty(d)) { - (function (file) { - fs.readFile(file, function (err, json) { - files.loaded[path.basename(file).replace('json', '')] = json; - - loaded--; - if (loaded === 0) { - callback(); - } - }); - }(data[d])); + files.loaded[path.basename(data[d]).replace('.json', '')] = require(data[d]); } } }); @@ -74,13 +79,22 @@ /* * TODO: DRY, see translator.translate. The hard part is to make sure both work node.js / js side */ - translator.get = function (key) { + translator.get = function (key, callback) { + //console.log(files.loaded); var parsedKey = key.split(':'), languageFile = parsedKey[0]; parsedKey = parsedKey[1]; + console.log(parsedKey); + translator.load(languageFile, function (languageData) { + console.log(languageData[parsedKey]); + if (callback) { + console.log('herped'); + callback(languageData[parsedKey]); + } - return files.loaded[languageFile][parsedKey]; + return languageData[parsedKey]; + }); }; diff --git a/src/favourites.js b/src/favourites.js index 1691e20f13..2ceedeb637 100644 --- a/src/favourites.js +++ b/src/favourites.js @@ -1,16 +1,22 @@ var RDB = require('./redis.js'), posts = require('./posts.js'), - user = require('./user.js'); + user = require('./user.js'), + translator = require('./../public/src/translator.js'); (function (Favourites) { "use strict"; Favourites.favourite = function (pid, room_id, uid, socket) { if (uid === 0) { + var not_logged_in = { + message: translator.get('topic:favourites.not_logged_in.message'), + title: translator.get('topic:favourites.not_logged_in.title') + }; + socket.emit('event:alert', { alert_id: 'post_favourite', - title: 'Not Logged In', - message: 'Please log in in order to favourite this post', + title: not_logged_in.title, + message: not_logged_in.message, type: 'danger', timeout: 5000 });