Added more locale stuff

Added more entries to the US_en locale. Also added a default "ERROR" locale if the requested one cannot be found. Also changed some internals to fit semantics better and made views use some new locale entries.
This commit is contained in:
RedDucks 2018-11-23 22:58:55 -05:00
parent 705a52a641
commit 4c0f6d4290
18 changed files with 2743 additions and 477 deletions

View File

@ -5,6 +5,8 @@ small commonly used utilities
*/
const fs = require('fs-extra');
// shows 404 template. takes express response object
function send404(res) {
res.status(404).send('404');
@ -20,12 +22,44 @@ function templateReadyUser(req) {
};
}
// Returns a list of possible locales:
/*
* [
* {
* region: 'US',
* language: 'en',
* display: 'American English',
* flag_id: 1 // I dunno maybe we display a local list that also displays flags?
* }
* ]
*
*/
function getLocales() {
return require('../locales/US_en.json');
return [];
}
// Returns a locale
function getLocale(region, language) {
const path = `${__dirname}/../locales/${region}_${language}.json`;
if (fs.pathExistsSync(path)) {
return require(path);
}
console.warn(`Could not find locale ${region}_${language}! Loading default`);
return getDefaultLocale();
}
// Returns the default locale
function getDefaultLocale(locale='default') {
return require(`${__dirname}/../locales/${locale}.json`);
}
module.exports = {
send404,
templateReadyUser,
getLocales
getLocales,
getLocale,
getDefaultLocale
};

View File

@ -10,12 +10,23 @@
"logout": "Logout"
}
},
"about": {
"title": "About",
"text": "Pretendo is an open source Nintendo Network replacement that aims to build custom servers for the WiiU and 3DS family of consoles. Our goal is to preserve the online functionality of these consoles, to allow players to continue to play their favorite WiiU and 3DS family of console games to their fullest capacity."
"home": {
"header": {
"title": "Pretendo",
"text": "An open source Nintendo Network replacement service"
}
},
"credits": {
"title": "Credits"
"progress": {
"summary": {
"title": "Progress Summary",
"text": "We should probably pull this from a database ngl"
},
"compatability": {
"title": "Game Compatability"
},
"misc": {
"title": "Other"
}
},
"contact": {
"title": "Contact Us",
@ -24,23 +35,34 @@
"subject_placeholder": "Subject",
"message_placeholder": "Message"
},
"login_card": {
"title": "Login",
"email_text": "Username or Email",
"password_text": "Password",
"email_placeholder": "email@provider.com",
"password_placeholder": "••••••••",
"button_text": "Sign In"
"login": {
"card": {
"title": "Login",
"email_text": "Username or Email",
"password_text": "Password",
"email_placeholder": "email@provider.com",
"password_placeholder": "••••••••",
"button_text": "Sign In"
}
},
"register_card": {
"title": "Register",
"email_text": "Email Address",
"username_text": "Username",
"password_text": "Password",
"password_confirm_text": "Confirm Password",
"email_placeholder": "email@provider.com",
"password_placeholder": "••••••••",
"caption": "Sign Up"
"register": {
"card": {
"title": "Register",
"email_text": "Email Address",
"username_text": "Username",
"password_text": "Password",
"password_confirm_text": "Confirm Password",
"email_placeholder": "email@provider.com",
"password_placeholder": "••••••••",
"caption": "Sign Up"
}
},
"about": {
"title": "About",
"text": "Pretendo is an open source Nintendo Network replacement that aims to build custom servers for the WiiU and 3DS/2DS family of consoles. Our goal is to preserve the online functionality of these consoles, to allow players to continue to play their favorite WiiU and 3DS/2DS games to their fullest capacity."
},
"credits": {
"title": "Credits"
},
"errors": {
"invalid_login": "Invalid username/password combination",

74
locales/default.json Normal file
View File

@ -0,0 +1,74 @@
{
"nav": {
"brand": "ERROR",
"links": {
"news": "ERROR",
"progress": "ERROR",
"contact": "ERROR",
"login": "ERROR",
"register": "ERROR",
"logout": "ERROR"
}
},
"home": {
"header": {
"title": "ERROR",
"text": "ERROR"
}
},
"progress": {
"summary": {
"title": "ERROR",
"text": "ERROR"
},
"compatability": {
"title": "ERROR"
},
"misc": {
"title": "ERROR"
}
},
"contact": {
"title": "ERROR",
"button_text": "ERROR",
"email_placeholder": "ERROR",
"subject_placeholder": "ERROR",
"message_placeholder": "ERROR"
},
"login": {
"card": {
"title": "ERROR",
"email_text": "ERROR",
"password_text": "ERROR",
"email_placeholder": "ERROR",
"password_placeholder": "ERROR",
"button_text": "Sign In"
}
},
"register": {
"card": {
"title": "ERROR",
"email_text": "ERROR",
"username_text": "ERROR",
"password_text": "ERROR",
"password_confirm_text": "ERROR",
"email_placeholder": "ERROR",
"password_placeholder": "ERROR",
"caption": "ERROR"
}
},
"about": {
"title": "ERROR",
"text": "ERROR"
},
"credits": {
"title": "ERROR"
},
"errors": {
"invalid_login": "ERROR",
"account_exists": "ERROR"
},
"footer": {
"text": "ERROR"
}
}

2944
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -23,6 +23,7 @@
"express-handlebars": "^3.0.0",
"express-recaptcha": "^4.0.3",
"express-session": "^1.15.6",
"fs-extra": "^7.0.1",
"moment": "^2.22.2",
"mongoose": "^5.3.2",
"mongoose-unique-validator": "^2.0.2",
@ -32,6 +33,7 @@
"showdown": "^1.8.6"
},
"devDependencies": {
"eslint": "^5.6.1"
"eslint": "^5.6.1",
"nodemon": "^1.18.6"
}
}

View File

@ -10,7 +10,6 @@ const router = require('express').Router();
const passport = require('passport');
const moment = require('moment');
const apiHelper = require('../helpers/api');
const utilHelper = require('../helpers/util');
const userMiddleware = require('../middleware/authentication');
// database models
@ -21,7 +20,9 @@ const progressList = require('../models/progress-list');
// renders admin.hbs
router.get('/admin', (req, res) => {
res.render('admin');
res.render('admin', {
title: 'Pretendo | Admin',
});
});
/*
@ -44,10 +45,11 @@ router.get('/admin', (req, res) => {
// TODO make login somehow display errors in correct format.
// middleware does the authentication work. this just returns a success
router.post('/admin/api/v1/login', passport.authenticate('adminUserStrategy'), function (req, res) {
const user = req.user;
apiHelper.sendReturn(res, {
username: req.user.username,
locales: utilHelper.getLocales(),
role: req.user.role ? req.user.role : undefined
username: user.username,
locale: user.getLocale(), // calls 'utilHelper.getLocale(user.region, user.language)' maybe?
role: user.role ? user.role : undefined
});
});

View File

@ -29,9 +29,10 @@ router.get('/news/:date/:title', (req, res) => {
post.postTemplate((err, postTemplate) => {
if (err) return utilHelper.send404(res);
res.render('post', {
title: req.params.title,
post: postTemplate,
user: utilHelper.templateReadyUser(req),
locales: utilHelper.getLocales()
locale: utilHelper.getLocale('US', 'en')
});
});
});
@ -56,9 +57,10 @@ router.get('/news', (req, res) => {
}
res.render('post-collection', {
title: 'Pretendo | News',
posts: postCollection,
user: utilHelper.templateReadyUser(req),
locales: utilHelper.getLocales(),
locale: utilHelper.getLocale('US', 'en'),
page: 'news'
});
});

View File

@ -15,8 +15,9 @@ const https = require('https');
// display contact page
router.get('/contact', (req, res) => {
res.render('contact', {
title: 'Pretendo | Contact',
user: utilHelper.templateReadyUser(req),
locales: utilHelper.getLocales(),
locale: utilHelper.getLocale('US', 'en'),
page: 'contact'
});
});

View File

@ -16,8 +16,9 @@ router.get('/', (req, res) => {
// needs callback because mongoose is inconsistent
blogPostModel.latestPostsShortTemlate(2, (err, result) => {
res.render('home', {
title: 'Pretendo | Home',
user: utilHelper.templateReadyUser(req),
locales: utilHelper.getLocales(),
locale: utilHelper.getLocale('US', 'en'),
posts: result,
page: 'home'
});

View File

@ -21,14 +21,16 @@ const PNID = require('../models/pnid');
// renders register page
router.get('/pnid/register', recaptcha.middleware.render, (req, res) => {
res.render('register', {
title: 'Pretendo | Register',
captcha: res.recaptcha,
locales: utilHelper.getLocales()
locale: utilHelper.getLocale('US', 'en')
});
});
// renders login page
router.get('/pnid/login', (req, res) => {
res.render('login', {
locales: utilHelper.getLocales()
title: 'Pretendo | Login',
locale: utilHelper.getLocale('US', 'en')
});
});
// logout
@ -39,7 +41,8 @@ router.get('/pnid/logout', userMiddleware.pnidAuthNeeded, (req, res) => {
// renders pnid dashboard
router.get('/pnid/dashboard', userMiddleware.pnidAuthNeeded, (req, res) => {
res.render('dashboard', {
locales: utilHelper.getLocales(),
title: 'Pretendo | Dash',
locale: utilHelper.getLocale('US', 'en'),
user: utilHelper.templateReadyUser(req)
});
});

View File

@ -22,10 +22,11 @@ router.get('/progress', (req, res) => {
const backends = progress.filter(i => !i.isGame);
res.render('progress', {
title: 'Pretendo | Progress',
games,
backends,
user: utilHelper.templateReadyUser(req),
locales: utilHelper.getLocales(),
locale: utilHelper.getLocale('US', 'en'),
page: 'progress'
});
});

View File

@ -12,15 +12,15 @@
<section class="bigCardWrapper">
<div class="bigCard">
<p class="txt-highlight">ERROR</p>
<h1 class="txt-title">{{ locales.contact.title }}</h1>
<h1 class="txt-title">{{ locale.contact.title }}</h1>
<form action="/api/v1/sendmessage" method="POST">
<div class="input-container">
<input type="text" name="email" placeholder="{{ locales.contact.email_placeholder }}">
<input type="text" name="subject" placeholder="{{ locales.contact.subject_placeholder }}">
<input type="text" name="email" placeholder="{{ locale.contact.email_placeholder }}">
<input type="text" name="subject" placeholder="{{ locale.contact.subject_placeholder }}">
</div>
<textarea name="message" placeholder="{{ locales.contact.message_placeholder }}"></textarea>
<textarea name="message" placeholder="{{ locale.contact.message_placeholder }}"></textarea>
<div class="txt-center">
<button class="btn">{{ locales.contact.button_text }}</button>
<button class="btn">{{ locale.contact.button_text }}</button>
</div>
</form>
</div>

View File

@ -9,9 +9,9 @@
{{> nav-default }}
<div class="contentWrapper">
<header>
<h1>ERROR</h1>
<h1>{{ locale.home.header.title }}</h1>
<hr>
<h3>ERROR</h3>
<h3>{{ locale.home.header.text }}</h3>
</header>
</div>
<div class="contentWrapper bgLines">
@ -19,15 +19,15 @@
<section class="bigCardWrapper">
<div class="bigCard">
<p class="txt-highlight">ERROR</p>
<h1 class="txt-title">{{ locales.about.title }}</h1>
<p>{{ locales.about.text }}</p>
<h1 class="txt-title">{{ locale.about.title }}</h1>
<p>{{ locale.about.text }}</p>
</div>
</section>
<section class="bigCardWrapper">
<div class="bigCard">
<p class="txt-highlight">ERROR</p>
<h1 class="txt-title">{{ locales.credits.title }}</h1>
<h1 class="txt-title">{{ locale.credits.title }}</h1>
<div class="cardProfiles">
<!-- profile -->
<div class="profile">

View File

@ -8,17 +8,17 @@
</head>
<body class="flex center">
<div class="card">
<h2 class="head">{{ locales.nav.brand }}</h2>
<h2 class="head">{{ locale.nav.brand }}</h2>
<div class="content">
<p class="txt-highlight">ERROR</p>
<h1 class="txt-title small">{{ locales.login_card.title }}</h1>
<h1 class="txt-title small">{{ locale.login.card.title }}</h1>
<form action="/api/v1/sendmessage" method="POST">
<label for="email">{{ locales.login_card.email_text }}</label>
<label for="email">{{ locale.login.card.email_text }}</label>
<input type="text" class="hasLabel" id="email_input" name="email">
<label for="email">{{ locales.login_card.password_text }}</label>
<label for="email">{{ locale.login.card.password_text }}</label>
<input type="password" class="hasLabel" id="password_input" name="password">
</form>
<button class="btn btnMargin" onclick="login()">{{ locales.login_card.button_text }}</button>
<button class="btn btnMargin" onclick="login()">{{ locale.login.card.button_text }}</button>
<p class="lowText">ERROR <a href="#">ERROR</a></p>
</div>
</div>

View File

@ -1,5 +1,5 @@
<footer>
<div class="content">
<p>{{ locales.footer.text }}</p>
<p>{{ locale.footer.text }}</p>
</div>
</footer>

View File

@ -1,5 +1,5 @@
{{> metatags }}
<title>ERROR</title>
<title>{{ title }}</title>
<!-- css files -->
<link rel="stylesheet" href="/assets/css/pretendo-common.css">
<!-- scripts -->

View File

@ -1,8 +1,8 @@
<nav class="navWrapper" id="nav">
<a class="navItem brand{{#if_eq page 'home'}} active{{/if_eq}}" {{#if_neq page 'home'}}href="/"{{/if_neq}}>{{ locales.nav.brand }}</a>
<a class="navItem{{#if_eq page 'news'}} active{{/if_eq}}" {{#if_neq page 'news'}}href="/news"{{/if_neq}}>{{ locales.nav.links.news }}</a>
<a class="navItem{{#if_eq page 'progress'}} active{{/if_eq}}" {{#if_neq page 'progress'}}href="/progress"{{/if_neq}}>{{ locales.nav.links.progress }}</a>
<a class="navItem{{#if_eq page 'contact'}} active{{/if_eq}}" {{#if_neq page 'contact'}}href="/contact"{{/if_neq}}>{{ locales.nav.links.contact }}</a>
<a class="navItem brand{{#if_eq page 'home'}} active{{/if_eq}}" {{#if_neq page 'home'}}href="/"{{/if_neq}}>{{ locale.nav.brand }}</a>
<a class="navItem{{#if_eq page 'news'}} active{{/if_eq}}" {{#if_neq page 'news'}}href="/news"{{/if_neq}}>{{ locale.nav.links.news }}</a>
<a class="navItem{{#if_eq page 'progress'}} active{{/if_eq}}" {{#if_neq page 'progress'}}href="/progress"{{/if_neq}}>{{ locale.nav.links.progress }}</a>
<a class="navItem{{#if_eq page 'contact'}} active{{/if_eq}}" {{#if_neq page 'contact'}}href="/contact"{{/if_neq}}>{{ locale.nav.links.contact }}</a>
<div class="navSpread"></div>
{{#if user.isLoggedIn }}
<a class="navItem navProfile" href="/pnid/dashboard">
@ -11,8 +11,8 @@
</a>
<a class="navItem navBtn" href="/pnid/logout">logout</a>
{{else}}
<a class="navItem navBtnAlt" href="/pnid/login">{{ locales.nav.links.login }}</a>
<a class="navItem navBtn" href="/pnid/register">{{ locales.nav.links.register }}</a>
<a class="navItem navBtnAlt" href="/pnid/login">{{ locale.nav.links.login }}</a>
<a class="navItem navBtn" href="/pnid/register">{{ locale.nav.links.register }}</a>
{{/if}}
<a class="navItem hamburger" id="navToggle">ICON</a>
</nav>

View File

@ -8,18 +8,18 @@
</head>
<body class="flex center">
<div class="card">
<h2 class="head">{{ locales.nav.brand }}</h2>
<h2 class="head">{{ locale.nav.brand }}</h2>
<div class="content">
<p class="txt-highlight">{{ locales.register_card.caption }}</p>
<h1 class="txt-title small">{{ locales.register_card.title }}</h1>
<p class="txt-highlight">{{ locale.register.card.caption }}</p>
<h1 class="txt-title small">{{ locale.register.card.title }}</h1>
<form action="/api/v1/sendmessage" method="POST">
<label for="email">{{ locales.register_card.email_text }}</label>
<label for="email">{{ locale.register.card.email_text }}</label>
<input type="text" class="hasLabel" id="email_input" name="email">
<label for="email">{{ locales.register_card.username_text }}</label>
<label for="email">{{ locale.register.card.username_text }}</label>
<input type="text" class="hasLabel" id="username_input" name="username">
<label for="email">{{ locales.register_card.password_text }}</label>
<label for="email">{{ locale.register.card.password_text }}</label>
<input type="password" class="hasLabel" id="password_input" name="password">
<label for="email">{{ locales.register_card.password_confirm_text }}</label>
<label for="email">{{ locale.register.card.password_confirm_text }}</label>
<input type="password" class="hasLabel" id="password_confirm_input" name="confirm_password">
</form>
<button class="btn btnMargin" onclick="register()">ERROR</button>