From 6fc1f85e188791d588b3c1370fb71d5ebfbc893b Mon Sep 17 00:00:00 2001 From: DeaDvey Date: Sat, 9 Aug 2025 16:57:31 +0100 Subject: [PATCH] Added locale (english only at the moment) and modifed the EJS so I think every string is customisable (via the /locales/selected locale) --- locales/en.json | 38 ++++++++++++++++++++ src/server.js | 68 ++++++++++++++++++++++++------------ views/forms/edit_account.ejs | 14 +++++--- views/forms/edit_post.ejs | 18 +++++++--- views/forms/new_post.ejs | 21 +++++++---- views/forms/signup.ejs | 18 +++++++--- views/headers/site_wide.ejs | 6 +++- views/headers/tag.ejs | 2 +- views/headers/timeline.ejs | 16 ++++++--- views/headers/user.ejs | 8 ++--- views/pages/tag.ejs | 12 ++++--- views/pages/timeline.ejs | 1 + views/partials/footer.ejs | 2 +- views/posts/post.ejs | 14 ++++---- views/posts/tag.ejs | 9 ++--- views/posts/timeline.ejs | 11 +++--- views/posts/user.ejs | 9 ++--- 17 files changed, 187 insertions(+), 80 deletions(-) create mode 100644 locales/en.json 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 @@
-
-
-
-
+
+

+ +
+

+ +
+

+ +

diff --git a/views/forms/edit_post.ejs b/views/forms/edit_post.ejs index 59a5ecd..bfed15a 100644 --- a/views/forms/edit_post.ejs +++ b/views/forms/edit_post.ejs @@ -7,13 +7,21 @@
-
-
-
-
+ +
+

+ +
+

+ +
+

+ +
+

+

- * Markdown supported
diff --git a/views/forms/new_post.ejs b/views/forms/new_post.ejs index 465eb9a..2b2362c 100644 --- a/views/forms/new_post.ejs +++ b/views/forms/new_post.ejs @@ -5,12 +5,21 @@
-
-
-
-
-
+
+

+ +
+

+ +
+

+ +
+

+ +
+

+
- * Markdown supported
diff --git a/views/forms/signup.ejs b/views/forms/signup.ejs index b56c328..3fb32e3 100644 --- a/views/forms/signup.ejs +++ b/views/forms/signup.ejs @@ -5,11 +5,19 @@
-
-
-
-
-
+
+

+ +
+

+ +
+

+ +
+

+ +

diff --git a/views/headers/site_wide.ejs b/views/headers/site_wide.ejs index a0ff034..400d8b4 100644 --- a/views/headers/site_wide.ejs +++ b/views/headers/site_wide.ejs @@ -1 +1,5 @@ -Home Page
+<%= locale.home_page %> +<%= locale.site_index %> +<%= locale.new_post %> +
+<%- config.seperator %> diff --git a/views/headers/tag.ejs b/views/headers/tag.ejs index 2ba4e40..6d96152 100644 --- a/views/headers/tag.ejs +++ b/views/headers/tag.ejs @@ -1,4 +1,4 @@

- Post's tagged "<%- tag %>": + <%= locale.posts_tagged %>: "<%- tag %>"

<%- config.seperator %> diff --git a/views/headers/timeline.ejs b/views/headers/timeline.ejs index a4ce164..a18ae8c 100644 --- a/views/headers/timeline.ejs +++ b/views/headers/timeline.ejs @@ -4,11 +4,17 @@

<%- config.site_description %>

-RSS Feed
-ATOM Feed
-New post
-Sign Up
+<% if (config.rss == true) { %> + <%= locale.rss_feed %>
+<% } %> +<% if (config.atom == true) { %> + <%= locale.atom_feed %>
+<% } %> +<%= locale.new_post %>
+<% if (config.allow_signup == true) { %> + <%= locale.sign_up %>
+<% } %> <% if (config.enable_hitcount == true) { %> -Hitcount: <%= hitcount %> +<%= locale.hitcount %>: <%= hitcount %> <% } %> <%- config.seperator %> diff --git a/views/headers/user.ejs b/views/headers/user.ejs index dfbff1c..4f67f8e 100644 --- a/views/headers/user.ejs +++ b/views/headers/user.ejs @@ -1,8 +1,8 @@

- <%= user.prettyname %>'s posts + <%= user.prettyname %>

<%- converter.makeHtml(user.description) %>

-edit account
-RSS
-ATOM +<%= locale.edit_account %>
+<%= locale.rss_feed %>
+<%= locale.atom_feed %> <%- config.seperator %> diff --git a/views/pages/tag.ejs b/views/pages/tag.ejs index 9033241..849f76c 100644 --- a/views/pages/tag.ejs +++ b/views/pages/tag.ejs @@ -10,11 +10,13 @@
<% for (let index = posts.length - 1; index >= 0; index--) { %> - <% posts[index].tags.forEach((current_tag, tag_index) => { %> - <% if (current_tag == tag) { %> - <%- include('../posts/tag', {post: posts[index], postID: index}); %> - <% } %> - <% }) %> + <% if ( posts[index].deleted != true) { %> + <% posts[index].tags.forEach((current_tag, tag_index) => { %> + <% if (current_tag == tag) { %> + <%- include('../posts/tag', {post: posts[index], postID: index}); %> + <% } %> + <% }) %> + <% } %> <% } %>