commit ccc558d5e81deeaef76a1f1fb268f43b523eccf7
parent c5ff0dce3893a461e17b9ce0f7fbf4fb61c67b3e
Author: cblgh <cblgh@cblgh.org>
Date: Fri, 12 Jan 2024 12:29:21 +0100
add translations for admin work
Diffstat:
6 files changed, 84 insertions(+), 44 deletions(-)
diff --git a/html/admin-add-user.html b/html/admin-add-user.html
@@ -1,8 +1,7 @@
{{ template "head" . }}
<main>
<h1> {{ .Title }}</h1>
- <p>Register a new user account. After registering the account you will be given a generated password and
- instructions to pass onto the user.</p>
+ <p>{{ "AdminAddUserExplanation" | translate }}</p>
<form method="post">
<label for="username">{{ "Username" | translate | capitalize }}:</label>
diff --git a/html/admin.html b/html/admin.html
@@ -8,21 +8,21 @@
<input type="hidden" name="userid" value="{{ .LoggedInID }}">
</form>
<p>
- Does someone wish admittance? You can <button form="add-user" type="submit">Add new user</button>.
+ {{ "AdminAddNewUserQuestion" | translate }} <button form="add-user" type="submit"> {{ "AdminAddNewUser" | translate }}</button>.
</p>
<p>
- If you want to stop being an admin, you can <button form="demote-self" type="submit">Step down</button>.
+ {{ "AdminStepDownExplanation" | translate }} <button form="demote-self" type="submit">{{ "AdminStepDown" | translate }}</button>.
</p>
<p>
- View past actions in the <a href="/moderations">moderation log</a>.
+ {{ "AdminViewPastActions" | translate }} <a href="/moderations">{{ "ModerationLog" | translate }}</a>.
</p>
</section>
{{ if .LoggedIn }}
{{ $userID := .LoggedInID }}
<section>
- <h2> Admins </h2>
+ <h2> {{ "Admins" | translate | capitalize }} </h2>
{{ if len .Data.Admins | eq 0 }}
- <p> there are no admins; chaos reigns </p>
+ <p> {{ "AdminNoAdmins" | translate }} </p>
{{ else }}
<table>
{{ range $index, $user := .Data.Admins }}
@@ -32,8 +32,8 @@
</form>
<td>{{ $user.Name }} ({{ $user.ID }}) </td>
<td>
- {{ if eq $userID $user.ID }} <i>(you!)</i>
- {{ else }}<button type="submit" form="demote-admin-{{$user.ID}}">Demote</button>{{ end }}
+ {{ if eq $userID $user.ID }} <i>({{ "AdminYou" | translate }})</i>
+ {{ else }}<button type="submit" form="demote-admin-{{$user.ID}}">{{ "AdminDemote" | translate }}</button>{{ end }}
</td>
</tr>
{{ end }}
@@ -41,18 +41,15 @@
{{ end }}
</section>
<section>
- <h2> Pending actions</h2>
- <p>Two admins are required for <i>making a user an admin</i>, <i>demoting an existing admin</i>, or <i>removing a user</i>. The
- first proposes the action, the second confirms (or vetos) it. If enough time elapses without a veto, the
- proposer may confirm their own proposal.</p>
-
+ <h2> {{ "PendingProposals" | translate }} </h2>
+ <p> {{ "AdminPendingExplanation" | translate | tohtml }}</p>
{{ if len .Data.Proposals | eq 0}}
- <p><i>there are no pending proposals</i></p>
+ <p><i>{{ "AdminNoPendingProposals" | translate }}</i></p>
{{ else }}
<table>
<tr>
- <th>Proposal</th>
- <th colspan="3">Date self-proposals become valid</th>
+ <th>{{ "Proposal" | translate }}</th>
+ <th colspan="3">{{ "AdminSelfProposalsBecomeValid" | translate }}</th>
</tr>
{{ range $index, $proposal := .Data.Proposals }}
<tr>
@@ -64,17 +61,17 @@
</form>
<td> {{ $proposal.Action | tohtml }} </td>
<td> {{ $proposal.Time | formatDateTime }} </td>
- <td><button type="submit" form="veto-{{$proposal.ID}}">Veto</button></td>
- <td><button {{ if not $proposal.TimePassed }} disabled title="a week must pass before self-confirmations are ok" {{ end }} type="submit" form="confirm-{{$proposal.ID}}">Confirm</button></td>
+ <td><button type="submit" form="veto-{{$proposal.ID}}">{{ "AdminVeto" | translate }}</button></td>
+ <td><button {{ if not $proposal.TimePassed }} disabled title='{{ "AdminSelfConfirmationHover" | translate}}' {{ end }} type="submit" form="confirm-{{$proposal.ID}}">{{"AdminConfirm" | translate}}</button></td>
</tr>
{{ end }}
</table>
{{ end }}
<section>
- <h2> Users </h2>
+ <h2> {{ "AdminUsers" | translate }} </h2>
{{ if len .Data.Users | eq 0 }}
- <p> there are no other users </p>
+ <p> {{ "AdminNoUsers" | translate }} </p>
{{ else }}
<table>
{{ range $index, $user := .Data.Users }}
@@ -85,13 +82,13 @@
<td>{{ $user.Name }} ({{ $user.ID }})</td>
<td>
<select name="admin-action" action="/admin/" id="select-{{$user.ID}}">
- <option selected value="reset-password">Reset password</option>
- <option value="remove-account">Remove account</option>
- <option value="make-admin">Make admin</option>
+ <option selected value="reset-password">{{ "PasswordReset" | translate | capitalize }}</option>
+ <option value="remove-account">{{ "RemoveAccount" | translate | capitalize }}</option>
+ <option value="make-admin">{{ "AdminMakeAdmin" | translate }}</option>
</select>
</td>
<td>
- <button type="submit">Submit</button>
+ <button type="submit">{{ "Submit" | translate }}</button>
</td>
</tr>
{{ end }}
diff --git a/html/admins-list.html b/html/admins-list.html
@@ -3,11 +3,11 @@
<h1>{{ .Title }}</h1>
{{ if .LoggedIn }}
<section>
- <p>View the <a href="/moderations">moderation log</a>.</p>
+ <p>{{ "AdminViewPastActions" | translate }} <a href="/moderations">{{ "ModerationLog" | translate }}</a>.</p>
{{ if len .Data.Admins | eq 0 }}
- <p> there are no admins; chaos reigns </p>
+ <p> {{ "AdminNoAdmins" | translate }} </p>
{{ else }}
- <p>This forum currently has the following {{ len .Data.Admins }} admins:
+ <p>{{ "AdminForumHasAdmins" | translate }}:</p>
<ul>
{{ range $index, $user := .Data.Admins }}
<li> {{ $user.Name }} </li>
@@ -16,7 +16,7 @@
</section>
{{ end }}
{{ else }}
- <p> Only logged in users may view the forum's admins. </p>
+ <p> {{ "AdminOnlyLoggedInMayView" | translate }} </p>
{{ end }}
</main>
{{ template "footer" . }}
diff --git a/html/moderation-log.html b/html/moderation-log.html
@@ -4,10 +4,9 @@
{{ if .LoggedIn }}
<section>
{{ if len .Data.Log | eq 100 }}
- <p> there are no logged moderation actions </p>
+ <p> {{ "ModLogNoActions" | translate }} </p>
{{ else }}
- <p>This resource lists the moderation actions taken by the forum's administrators. {{ if .IsAdmin }} You are
- viewing this page as an admin, you will see slightly more details. {{ end }}</p>
+ <p>{{ "ModLogExplanation" | translate }} {{ if .IsAdmin }} {{ "ModLogExplanationAdmin" | translate }} {{ end }} </p>
<style>
section ul { padding-left: 0; }
section ul li {
@@ -27,7 +26,7 @@
</section>
{{ end }}
{{ else }}
- <p> Only logged-in users may view the moderation log. </p>
+ <p> {{ "ModLogOnlyLoggedInMayView" | translate }} </p>
{{ end }}
</main>
{{ template "footer" . }}
diff --git a/i18n/i18n.go b/i18n/i18n.go
@@ -31,7 +31,8 @@ var English = map[string]string{
"modlogResetPasswordAdmin": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> reset <b> {{ .Data.RecipientUsername}}</b>'s password`,
"modlogRemoveUser": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> removed a user's account`,
"modlogMakeAdmin": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> made <b> {{ .Data.RecipientUsername}}</b> an admin`,
- "modlogAddUser": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> manually registered an account for <b> {{ .Data.RecipientUsername }}</b>`,
+ "modlogAddUser": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> manually registered an account for a new user`,
+ "modlogAddUserAdmin": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> manually registered an account for <b> {{ .Data.RecipientUsername }}</b>`,
"modlogDemoteAdmin": `<code>{{ .Data.Time }}</code> <b>{{ .Data.ActingUsername }}</b> demoted <b>
{{ if eq .Data.ActingUsername .Data.RecipientUsername }} themselves
{{ else }} {{ .Data.RecipientUsername}} {{ end }}</b> from admin back to normal user`,
@@ -42,6 +43,47 @@ var English = map[string]string{
"modlogConfirm": "{{ .Data.Action }} <i>confirmed by {{ .Data.ActingUsername }}</i>",
"modlogVeto": "<s>{{ .Data.Action }}</s> <i>vetoed by {{ .Data.ActingUsername }}</i>",
+
+
+ "Admins": "admins",
+ "AdminVeto": "Veto",
+ "AdminConfirm": "Confirm",
+ "AdminForumAdministration": "Forum Administration",
+ "AdminYou": "you!",
+ "AdminUsers": "Users",
+ "AdminNoAdmins": "There are no admins",
+ "AdminNoUsers": "There are no other users",
+ "AdminNoPendingProposals": "There are no pending proposals",
+ "AdminAddNewUser": "Add new user",
+ "AdminAddNewUserQuestion": "Does someone wish attendence? You can ",
+ "AdminStepDown": "Step down",
+ "AdminStepDownExplanation": "If you want to stop being an admin, you can",
+ "AdminViewPastActions": "View past actions in the",
+ "ModerationLog": "moderation log",
+ "AdminDemote": "Demote",
+ "DeletedUser": "deleted user",
+ "RemoveAccount": "remove account",
+ "AdminMakeAdmin": "Make admin",
+ "Submit": "Submit",
+ "AdminSelfConfirmationsHover": "a week must pass before self-confirmations are ok",
+ "Proposal": "Proposal",
+ "PendingProposals": "Pending Proposals",
+ "AdminSelfProposalsBecomeValid": "Date self-proposals become valid",
+ "AdminPendingExplanation": `Two admins are required for <i>making a user an admin</i>, <i>demoting an existing
+ admin</i>, or <i>removing a user</i>. The first proposes the action, the second confirms
+ (or vetos) it. If enough time elapses without a veto, the proposer may confirm their own
+ proposal.`,
+
+ "AdminAddUserExplanation": "Register a new user account. After registering the account you will be given a generated password and instructions to pass onto the user.",
+ "AdminForumHasAdmins": "The forum currently has the following admins",
+ "AdminOnlyLoggedInMayView": "Only logged in users may view the forum's admins.",
+ "AdminPasswordSuccessInstructions": `Instructions: %s's password was set to: %s. After logging in, please change your password by going to /reset`,
+
+ "ModLogNoActions": "there are no logged moderation actions",
+ "ModLogExplanation": `This resource lists the moderation actions taken by the forum's administrators.`,
+ "ModLogExplanationAdmin": `You are viewing this page as an admin, you will see slightly more details.`,
+ "ModLogOnlyLoggedInMayView": "Only logged in users may view the moderation log.",
+
"LoginNoAccount": "Don't have an account yet? <a href='/register'>Register</a> one.",
"LoginFailure": "<b>Failed login attempt:</b> incorrect password, wrong username, or a non-existent user.",
"LoginAlreadyLoggedIn": `You are already logged in. Would you like to <a href="/logout">log out</a>?`,
diff --git a/server/moderation.go b/server/moderation.go
@@ -151,7 +151,7 @@ func (h *RequestHandler) AdminMakeUserAdmin(res http.ResponseWriter, req *http.R
return
}
- title := "Make admin"
+ title := h.translator.Translate("AdminMakeAdmin")
err := performQuorumCheck(ed, h.db, adminUserId, targetUserId, constants.MODLOG_ADMIN_PROPOSE_MAKE_ADMIN)
@@ -180,7 +180,7 @@ func (h *RequestHandler) AdminDemoteAdmin(res http.ResponseWriter, req *http.Req
return
}
- title := "Demote admin"
+ title := h.translator.Translate("AdminDemote")
useridString := req.PostFormValue("userid")
targetUserId, err := strconv.Atoi(useridString)
@@ -218,7 +218,7 @@ func (h *RequestHandler) AdminManualAddUserRoute(res http.ResponseWriter, req *h
}
var data AddUser
- view := TemplateData{Title: "Add a new user", Data: &data, HasRSS: false, IsAdmin: isAdmin, LoggedIn: loggedIn}
+ view := TemplateData{Title: h.translator.Translate("AdminAddNewUser"), Data: &data, HasRSS: false, IsAdmin: isAdmin, LoggedIn: loggedIn}
if req.Method == "GET" {
h.renderView(res, "admin-add-user", view)
@@ -251,8 +251,8 @@ func (h *RequestHandler) AdminManualAddUserRoute(res http.ResponseWriter, req *h
fmt.Println(ed.Eout(err, "error adding moderation log"))
}
- title := "User successfully added"
- message := fmt.Sprintf("Instructions: %s's password was set to: %s. After logging in, please change your password by going to /reset", username, newPassword)
+ title := h.translator.Translate("AdminAddNewUser")
+ message := fmt.Sprintf(h.translator.Translate("AdminPasswordSuccessInstructions"), template.HTMLEscapeString(username), newPassword)
h.displaySuccess(res, req, title, message, "/add-user")
}
}
@@ -266,7 +266,7 @@ func (h *RequestHandler) AdminResetUserPassword(res http.ResponseWriter, req *ht
return
}
- title := "Admin reset password"
+ title := util.Capitalize(h.translator.Translate("PasswordReset"))
newPassword, err := h.db.ResetPassword(targetUserId)
if err != nil {
@@ -281,7 +281,7 @@ func (h *RequestHandler) AdminResetUserPassword(res http.ResponseWriter, req *ht
username, _ := h.db.GetUsername(targetUserId)
- message := fmt.Sprintf("Instructions: User %s's password was reset to: %s. After logging in, please change your password by going to /reset", username, newPassword)
+ message := fmt.Sprintf(h.translator.Translate("AdminPasswordSuccessInstructions"), template.HTMLEscapeString(username), newPassword)
h.displaySuccess(res, req, title, message, "/admin")
}
@@ -348,6 +348,9 @@ func (h *RequestHandler) ModerationLogRoute(res http.ResponseWriter, req *http.R
translationString = "modlogRemoveUser"
case constants.MODLOG_ADMIN_ADD_USER:
translationString = "modlogAddUser"
+ if isAdmin {
+ translationString += "Admin"
+ }
case constants.MODLOG_ADMIN_DEMOTE:
translationString = "modlogDemoteAdmin"
case constants.MODLOG_ADMIN_PROPOSE_DEMOTE_ADMIN:
@@ -382,7 +385,7 @@ func (h *RequestHandler) ModerationLogRoute(res http.ResponseWriter, req *http.R
viewData.Log = append(viewData.Log, actionString)
}
}
- view := TemplateData{Title: "Moderation log", IsAdmin: isAdmin, LoggedIn: loggedIn, Data: viewData}
+ view := TemplateData{Title: h.translator.Translate("ModerationLog"), IsAdmin: isAdmin, LoggedIn: loggedIn, Data: viewData}
h.renderView(res, "moderation-log", view)
}
@@ -440,7 +443,7 @@ func (h *RequestHandler) AdminRoute(res http.ResponseWriter, req *http.Request)
pendingProposals[i] = PendingProposal{ID: prop.ProposalID, ProposerID: prop.ActingID, Action: proposalString, Time: t, TimePassed: now.After(t)}
}
data := AdminData{Admins: admins, Users: normalUsers, Proposals: pendingProposals}
- view := TemplateData{Title: "Forum Administration", Data: &data, HasRSS: false, LoggedIn: loggedIn, LoggedInID: userid}
+ view := TemplateData{Title: h.translator.Translate("AdminForumAdministration"), Data: &data, HasRSS: false, LoggedIn: loggedIn, LoggedInID: userid}
h.renderView(res, "admin", view)
}
}
@@ -450,7 +453,7 @@ func (h *RequestHandler) ListAdmins(res http.ResponseWriter, req *http.Request)
loggedIn, _ := h.IsLoggedIn(req)
admins := h.db.GetAdmins()
data := AdminData{Admins: admins}
- view := TemplateData{Title: "Forum Administrators", Data: &data, HasRSS: false, LoggedIn: loggedIn}
+ view := TemplateData{Title: h.translator.Translate("AdminForumAdministration"), Data: &data, HasRSS: false, LoggedIn: loggedIn}
h.renderView(res, "admins-list", view)
return
}