Added locale (english only at the moment) and modifed the EJS so I think

every string is customisable (via the /locales/selected locale)
This commit is contained in:
2025-08-09 16:57:31 +01:00
parent 8418318d80
commit 6fc1f85e18
17 changed files with 187 additions and 80 deletions

View File

@@ -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 <br/> 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,
})
}