diff --git a/locales/en.json b/locales/en.json
new file mode 100644
index 0000000..5583d7f
--- /dev/null
+++ b/locales/en.json
@@ -0,0 +1,38 @@
+{
+ "password": "Password",
+ "username": "Username",
+ "prettyname": "Prettyname",
+ "description": "Description (social links, what you write about etc), supports markdown",
+ "title": "Title",
+ "post_content": "Post Content, supports markdown",
+ "tags": "Tags (comma seperated)",
+ "delete_account_confirmation": "Delete my account - (I agree that my account and all of my posts will be permanently deleted instantly)",
+ "signup_agreement": "I agree to not post illegal or hateful content",
+ "comment": "Comment",
+ "submit": "Sumbit",
+
+ "signups_unavailable": "Sorry, this server does not allow signups",
+ "user_exists": "Sorry, this user already exists, try a different username",
+ "user_doesnt_exist": "Sorry, this user does not exist",
+ "comment_doesnt_exist": "This comment doesn't exist, this could be because the post it was attached to was deleted",
+ "post_doesnt_exist": "This post doesn't exist or was deleted",
+ "incorrect_password": "Incorrect Password",
+ "rss_disabled": "Sorry, RSS is disabled",
+ "atom_disabled": "Sorry, ATOM is disabled",
+
+ "rss_feed": "RSS Feed",
+ "atom_feed": "ATOM Feed",
+ "new_post": "New Post",
+ "edit_post": "Edit Post",
+ "sign_up": "Sign Up",
+ "edit_account": "Edit Account",
+ "permalink": "Permalink",
+ "written_by": "Written by",
+ "published": "Published",
+ "last_modified": "Last Modified",
+ "hitcount": "Hitcount",
+ "posts_tagged": "Posts Tagged",
+ "home_page": "Home Page",
+ "site_index": "Site Index",
+ "attribution": "Powered by blogger-nodejs: Source Code, license (WTFPL)"
+}
diff --git a/src/server.js b/src/server.js
index b5f2dce..1dcf068 100644
--- a/src/server.js
+++ b/src/server.js
@@ -40,6 +40,15 @@ catch (error) {
process.exit(1)
}
+// Import the locale
+try {
+ locale = require(`../locales/${config.locale}.json`);
+}
+catch (error) {
+ console.log("This locale doesn't exist, if you want to create it then you can create a PR")
+ console.log("Locale selected: ", config.locale)
+}
+
// https://showdownjs.com/docs/available-options
let converter = new showdown.Converter({
simpleLineBreaks: true, // Parse line breaks as
in paragraphs (GitHub-style behavior).
@@ -64,7 +73,7 @@ app.set('views', '../views')
app.get("/rss", (req,res) => {
if (config.rss == false) {
res.render("partials/message", {
- message: config.string.rss_disabled,
+ message: locale.rss_disabled,
config: config,
})
}
@@ -84,7 +93,7 @@ app.get("/user/:username/rss", (req,res) => {
const userID = func.get_userID(username);
if (config.rss == false) {
res.render("partials/message", {
- message: config.string.rss_disabled,
+ message: locale.rss_disabled,
config: config,
})
}
@@ -103,7 +112,7 @@ app.get("/user/:username/rss", (req,res) => {
app.get("/atom", (req,res) => {
if (config.atom == false) {
res.render("partials/message", {
- message: config.string.atom_disabled,
+ message: locale.atom_disabled,
config: config,
})
}
@@ -124,7 +133,7 @@ app.get("/user/:username/atom", (req,res) => {
const userID = func.get_userID(username);
if (config.atom == false) {
res.render("partials/message", {
- message: config.string.atom_disabled,
+ message: locale.atom_disabled,
config: config,
})
}
@@ -183,6 +192,7 @@ app.get("/", (req,res) => {
res.render("pages/timeline",
{
config,
+ locale,
posts,
users,
comments: comments.comments,
@@ -200,8 +210,9 @@ app.get("/user/:username", (req, res) => {
console.log(users[userID].prettyname)
res.render("pages/user",
{
- config: config,
- posts: posts,
+ config,
+ locale,
+ posts,
user: users[userID],
userID: userID,
comments: comments.comments,
@@ -216,7 +227,7 @@ app.get("/post/:post_index", (req, res) => {
const postID = req.params.post_index
if (posts[postID]["deleted"] == true) {
res.render("partials/message", {
- message: config.string.post_doesnt_exist,
+ message: locale.post_doesnt_exist,
config,
})
}
@@ -224,6 +235,7 @@ app.get("/post/:post_index", (req, res) => {
res.render("pages/post",
{
config,
+ locale,
post: posts[postID],
postID: postID,
user: users[posts[postID].userID],
@@ -244,10 +256,11 @@ app.get("/tag/:tag", (req,res) => {
const tag = req.params.tag
res.render("pages/tag",
{
- config: config,
- tag: tag,
- posts: posts,
- users: users,
+ config,
+ locale,
+ tag,
+ posts,
+ users,
comments: comments.comments,
fromUnixTime: fromUnixTime,
format: format,
@@ -262,13 +275,14 @@ app.get("/comment/:commentID", (req,res) => {
if (comment == -1) {
res.render("partials/message", {
config,
- message: config.string.comment_doesnt_exist,
+ message: locale.comment_doesnt_exist,
})
}
else {
res.render("pages/comment",
{
config: config,
+ locale,
post: posts[comment["id"]],
users,
comment,
@@ -285,7 +299,8 @@ app.get("/comment/:commentID", (req,res) => {
///////////////////// Form pages ////////////////////////////
app.get(config.new_post_url, (req,res) => {
res.render("forms/new_post", {
- config
+ config,
+ locale,
});
}); // /post
app.get(config.signup_url, (req,res) => {
@@ -293,13 +308,14 @@ app.get(config.signup_url, (req,res) => {
if (config.allow_signup == true) {
// Send the page for signing up to the server
res.render("forms/signup", {
- config
+ config,
+ locale,
});
}
// if the server does not allow signup
else if (config.allow_signup == false) {
res.render("partials/message", {
- message: config.string.signups_unavailable,
+ message: locale.signups_unavailable,
config,
})
}
@@ -311,7 +327,12 @@ app.get(config.signup_url, (req,res) => {
}); // /signup
app.get(`${config.edit_account_base_url}/:user_id`, (req,res) => {
const userID = parseInt(req.params.user_id);
- res.render("forms/edit_account", { config, user: users[userID], userID });
+ res.render("forms/edit_account", {
+ config,
+ locale,
+ user: users[userID],
+ userID
+ });
}); // /delete_account
app.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
const post_id = req.params.post_id
@@ -319,6 +340,7 @@ app.get(`${config.edit_post_base_url}/:post_id`, (req,res) => {
const user = users[post['userID']]
res.render("forms/edit_post", {
config,
+ locale,
post,
post_id,
user,
@@ -355,7 +377,7 @@ app.post("/submit_post", (req,res) => {
if (func.get_userID(username) == -1) {
res.render("partials/message", {
- message: config.string.user_doesnt_exit,
+ message: locale.user_doesnt_exit,
config,
})
}
@@ -378,7 +400,7 @@ app.post("/submit_post", (req,res) => {
}
else {
res.render("partials/message", {
- message: config.string.incorrect_password,
+ message: locale.incorrect_password,
config,
})
}
@@ -407,14 +429,14 @@ app.post("/submit_signup", (req,res) => {
// if the user does exist then
else {
res.render("partials/message", {
- message: config.string.user_exists,
+ message: locale.user_exists,
config,
})
}
}
else if (config.allow_signup == false) {
res.render("partials/message", {
- message: config.string.signups_unavailable,
+ message: locale.signups_unavailable,
config,
})
}
@@ -457,7 +479,7 @@ app.post("/submit_edit_user", (req,res) => {
}
else { // password does not match
res.render("partials/message", {
- message: config.string.incorrect_password,
+ message: locale.incorrect_password,
config
}
)
@@ -465,7 +487,7 @@ app.post("/submit_edit_user", (req,res) => {
}
else {
res.render("partials/message", {
- message: config.string.user_doesnt_exist,
+ message: locale.user_doesnt_exist,
config,
})
}
@@ -498,7 +520,7 @@ app.post("/submit_edit_post", (req,res) => {
}
else {
res.render("partials/message", {
- message: config.string.incorrect_password,
+ message: locale.incorrect_password,
config,
})
}
diff --git a/views/forms/edit_account.ejs b/views/forms/edit_account.ejs
index 1ba4ca6..686af52 100644
--- a/views/forms/edit_account.ejs
+++ b/views/forms/edit_account.ejs
@@ -6,10 +6,16 @@