started language locale-isation
This commit is contained in:
@@ -2,6 +2,7 @@ const Logger = require('./src/logger.js');
|
||||
const Server = require('./src/webserver.js');
|
||||
const Router = require('./src/router.js');
|
||||
const Socket = require('./src/socketserver.js');
|
||||
const Locale = require('./src/locale.js');
|
||||
|
||||
require('dotenv').config()
|
||||
|
||||
@@ -10,6 +11,7 @@ async function main()
|
||||
Logger.SetLevel(Logger.VERBOSE_LOGS);
|
||||
Logger.init();
|
||||
|
||||
await Locale.init();
|
||||
await Server.init();
|
||||
await Socket.init();
|
||||
await Router.init();
|
||||
|
||||
24
server/src/locale.js
Normal file
24
server/src/locale.js
Normal file
@@ -0,0 +1,24 @@
|
||||
const FS = require('fs');
|
||||
|
||||
let locales = {};
|
||||
|
||||
function init()
|
||||
{
|
||||
locales = JSON.parse(FS.readFileSync('src/locale.json'));
|
||||
}
|
||||
|
||||
function GetLocaleListJSON()
|
||||
{
|
||||
return JSON.stringify(locales);
|
||||
}
|
||||
|
||||
function GetLocaleList()
|
||||
{
|
||||
return locales;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
init: init,
|
||||
GetLocaleListJSON: GetLocaleListJSON,
|
||||
GetLocaleList: GetLocaleList
|
||||
}
|
||||
60
server/src/locale.json
Normal file
60
server/src/locale.json
Normal file
@@ -0,0 +1,60 @@
|
||||
{
|
||||
"scrabble-name": {
|
||||
"en": "Scrabble",
|
||||
"es": "Scrabble",
|
||||
"pt": "Scrabble"
|
||||
},
|
||||
"username": {
|
||||
"en": "Username",
|
||||
"es": "Nombre de usuario",
|
||||
"pt": "Nome de usuàrio"
|
||||
},
|
||||
"button-singleplayer": {
|
||||
"en": "Play singleplayer",
|
||||
"es": "Jugar a un(a) jugador(a)",
|
||||
"pt": "Jogar singleplayer"
|
||||
},
|
||||
"button-submit": {
|
||||
"en": "Submit",
|
||||
"es": "Enviar",
|
||||
"pt": "Enviar"
|
||||
},
|
||||
"status-connected": {
|
||||
"en": "Connected",
|
||||
"es": "",
|
||||
"pt": ""
|
||||
},
|
||||
|
||||
|
||||
"error-bold": {
|
||||
"en": "ERROR",
|
||||
"es": "ERRO",
|
||||
"pt": "ERROR"
|
||||
},
|
||||
"error-no-username": {
|
||||
"en": "Username not present",
|
||||
"es": "",
|
||||
"pt": ""
|
||||
},
|
||||
"error-invalid-username": {
|
||||
"en": "Invalid username",
|
||||
"es": "",
|
||||
"pt": ""
|
||||
},
|
||||
"error-taken-username": {
|
||||
"en": "Username taken",
|
||||
"es": "",
|
||||
"pt": ""
|
||||
},
|
||||
"error-too-many-clients": {
|
||||
"en": "Too many clients",
|
||||
"es": "",
|
||||
"pt": ""
|
||||
},
|
||||
|
||||
|
||||
|
||||
"en": "",
|
||||
"es": "",
|
||||
"pt": ""
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
const Logger = require('./logger.js');
|
||||
const Server = require('./webserver.js');
|
||||
const Game = require('./game.js')
|
||||
const locale = require('./locale.js');
|
||||
const Error = require('./error.js')
|
||||
|
||||
const Express = require('express');
|
||||
@@ -16,6 +17,7 @@ async function init()
|
||||
Server.App.use(Express.static('../client/public'));
|
||||
|
||||
Server.App.post('/login', HandleLogin);
|
||||
Server.App.get('/locales', HandleGetLocales);
|
||||
|
||||
Logger.info('ROTUER SETUP');
|
||||
}
|
||||
@@ -49,7 +51,7 @@ function HandleLogin(req, res, next)
|
||||
|
||||
if (!req.body.username)
|
||||
{
|
||||
err.addError(400, 'Bad Request', 'Username not present');
|
||||
err.addError(400, 'Bad Request', 'error-no-username');
|
||||
err.end(res);
|
||||
return;
|
||||
}
|
||||
@@ -58,14 +60,14 @@ function HandleLogin(req, res, next)
|
||||
|
||||
if (!Game.Registrar.ValidUsername(username))
|
||||
{
|
||||
err.addError(403, 'Forbidden', 'Invalid username');
|
||||
err.addError(403, 'Forbidden', 'error-invalid-username');
|
||||
err.end(res);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Game.Registrar.CheckUsernameAvailability(username))
|
||||
{
|
||||
err.addError(403, 'Forbidden', 'Username taken');
|
||||
err.addError(403, 'Forbidden', 'error-taken-username');
|
||||
err.end(res);
|
||||
return;
|
||||
}
|
||||
@@ -78,7 +80,7 @@ function HandleLogin(req, res, next)
|
||||
// remote network
|
||||
if (Game.Registrar.CountIPs(ip) > 10)
|
||||
{
|
||||
err.addError(429, 'Too Many Requests', 'Too many clients');
|
||||
err.addError(429, 'Too Many Requests', 'error-too-many-clients');
|
||||
err.end(res);
|
||||
return;
|
||||
}
|
||||
@@ -87,7 +89,7 @@ function HandleLogin(req, res, next)
|
||||
|
||||
if (!user)
|
||||
{
|
||||
err.addError(500, 'Internal Server Error', 'User Connected');
|
||||
err.addError(500, 'Internal Server Error', 'status-connected');
|
||||
err.end(res);
|
||||
return;
|
||||
}
|
||||
@@ -104,3 +106,9 @@ function HandleLogin(req, res, next)
|
||||
// Continue to later middleware
|
||||
next();
|
||||
}
|
||||
|
||||
async function HandleGetLocales(req, res, next)
|
||||
{
|
||||
const err = new Error;
|
||||
res.end(locale.GetLocaleListJSON());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user