Skip to content

Commit

Permalink
add translations for admin work
Browse files Browse the repository at this point in the history
  • Loading branch information
cblgh committed Jan 17, 2024
1 parent c5ff0dc commit ccc558d
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 44 deletions.
3 changes: 1 addition & 2 deletions html/admin-add-user.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
43 changes: 20 additions & 23 deletions html/admin.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,21 @@ <h1>{{ .Title }}</h1>
<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 }}
Expand All @@ -32,27 +32,24 @@ <h2> Admins </h2>
</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 }}
</table>
{{ 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>
Expand All @@ -64,17 +61,17 @@ <h2> Pending actions</h2>
</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 }}
Expand All @@ -85,13 +82,13 @@ <h2> Users </h2>
<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 }}
Expand Down
8 changes: 4 additions & 4 deletions html/admins-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -16,7 +16,7 @@ <h1>{{ .Title }}</h1>
</section>
{{ end }}
{{ else }}
<p> Only logged in users may view the forum's admins. </p>
<p> {{ "AdminOnlyLoggedInMayView" | translate }} </p>
{{ end }}
</main>
{{ template "footer" . }}
7 changes: 3 additions & 4 deletions html/moderation-log.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ <h1>{{ .Title }}</h1>
{{ 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 {
Expand All @@ -27,7 +26,7 @@ <h1>{{ .Title }}</h1>
</section>
{{ end }}
{{ else }}
<p> Only logged-in users may view the moderation log. </p>
<p> {{ "ModLogOnlyLoggedInMayView" | translate }} </p>
{{ end }}
</main>
{{ template "footer" . }}
44 changes: 43 additions & 1 deletion i18n/i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
Expand All @@ -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>?`,
Expand Down
23 changes: 13 additions & 10 deletions server/moderation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
}
}
Expand All @@ -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 {
Expand All @@ -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")
}

Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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
}

0 comments on commit ccc558d

Please sign in to comment.