web: initial migration to lingui

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer
2021-04-03 19:26:43 +02:00
parent fc1caf1469
commit 25300c1928
150 changed files with 8720 additions and 1482 deletions

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import PFExpandableSection from "../../node_modules/@patternfly/patternfly/components/ExpandableSection/expandable-section.css";
@ -26,7 +26,7 @@ export class Expand extends LitElement {
<span class="pf-c-expandable-section__toggle-icon">
<i class="fas fa-angle-right" aria-hidden="true"></i>
</span>
<span class="pf-c-expandable-section__toggle-text">${gettext(this.expanded ? this.textOpen : this.textClosed)}</span>
<span class="pf-c-expandable-section__toggle-text">${this.expanded ? t`${this.textOpen}` : t`${this.textClosed}`}</span>
</button>
<slot ?hidden=${!this.expanded} class="pf-c-expandable-section__content"></slot>
</div>`;

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { LitElement } from "lit-element";
import { html, TemplateResult } from "lit-html";
@ -15,9 +15,9 @@ export abstract class Page extends LitElement {
<div class="pf-c-content">
<h1>
<i class="${this.pageIcon()}"></i>
${gettext(this.pageTitle())}
${t`${this.pageTitle()}`}
</h1>
${description ? html`<p>${gettext(description)}</p>` : html``}
${description ? html`<p>${t`${description}`}</p>` : html``}
</div>
</section>
${this.renderContent()}`;

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import PFSpinner from "@patternfly/patternfly/components/Spinner/spinner.css";
@ -22,7 +22,7 @@ export class Spinner extends LitElement {
return html`<span
class="pf-c-spinner ${this.size.toString()}"
role="progressbar"
aria-valuetext="${gettext("Loading...")}">
aria-valuetext="${t`Loading...`}">
<span class="pf-c-spinner__clipper"></span>
<span class="pf-c-spinner__lead-ball"></span>
<span class="pf-c-spinner__tail-ball"></span>

View File

@ -4,7 +4,7 @@ import PFTabs from "@patternfly/patternfly/components/Tabs/tabs.css";
import PFGlobal from "@patternfly/patternfly/patternfly-base.css";
import AKGlobal from "../authentik.css";
import { CURRENT_CLASS } from "../constants";
import { gettext } from "django";
import { t } from "@lingui/macro";
@customElement("ak-tabs")
export class Tabs extends LitElement {
@ -62,7 +62,7 @@ export class Tabs extends LitElement {
const pages = Array.from(this.querySelectorAll("[slot^='page-']"));
if (!this.currentPage) {
if (pages.length < 1) {
return html`<h1>${gettext("no tabs defined")}</h1>`;
return html`<h1>${t`no tabs defined`}</h1>`;
}
this.currentPage = pages[0].attributes.getNamedItem("slot")?.value;
}

View File

@ -1,4 +1,3 @@
import { gettext } from "django";
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import { ifDefined } from "lit-html/directives/if-defined";
import PFBase from "@patternfly/patternfly/patternfly-base.css";
@ -47,7 +46,7 @@ export class AggregateCard extends LitElement {
return html`<div class="pf-c-card pf-c-card-aggregate">
<div class="pf-c-card__header pf-l-flex pf-m-justify-content-space-between">
<div class="pf-c-card__header-main">
<i class="${ifDefined(this.icon)}"></i> ${this.header ? gettext(this.header) : ""}
<i class="${ifDefined(this.icon)}"></i> ${this.header ? this.header : ""}
</div>
${this.renderHeaderLink()}
</div>

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
import { Table, TableColumn } from "../table/Table";
@ -44,10 +44,10 @@ export class ObjectChangelog extends Table<Event> {
columns(): TableColumn[] {
return [
new TableColumn("Action", "action"),
new TableColumn("User", "enabled"),
new TableColumn("Creation Date", "created"),
new TableColumn("Client IP", "client_ip"),
new TableColumn(t`Action`, t`action`),
new TableColumn(t`User`, t`enabled`),
new TableColumn(t`Creation Date`, t`created`),
new TableColumn(t`Client IP`, t`client_ip`),
];
}
@ -56,7 +56,7 @@ export class ObjectChangelog extends Table<Event> {
html`${item.action}`,
html`<div>${item.user?.username}</div>
${item.user.on_behalf_of ? html`<small>
${gettext(`On behalf of ${item.user.on_behalf_of.username}`)}
${t`On behalf of ${item.user.on_behalf_of.username}`}
</small>` : html``}`,
html`<span>${item.created?.toLocaleString()}</span>`,
html`<span>${item.clientIp}</span>`,
@ -76,9 +76,9 @@ export class ObjectChangelog extends Table<Event> {
}
renderEmpty(): TemplateResult {
return super.renderEmpty(html`<ak-empty-state header=${gettext("No Events found.")} icon="pf-icon-module">
return super.renderEmpty(html`<ak-empty-state header=${t`No Events found.`} icon="pf-icon-module">
<div slot="body">
${gettext("No matching events could be found.")}
${t`No matching events could be found.`}
</div>
</ak-empty-state>`);
}

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { EVENT_REFRESH } from "../../constants";
import { ModalButton } from "../buttons/ModalButton";
@ -37,14 +37,14 @@ export class ConfirmationForm extends ModalButton {
onSuccess(): void {
showMessage({
message: gettext(this.successMessage),
message: this.successMessage,
level: MessageLevel.success,
});
}
onError(e: Error): void {
showMessage({
message: gettext(`${this.errorMessage}: ${e.toString()}`),
message: t`${this.errorMessage}: ${e.toString()}`,
level: MessageLevel.error,
});
}
@ -76,14 +76,14 @@ export class ConfirmationForm extends ModalButton {
this.confirm();
}}
class="pf-m-danger">
${gettext(this.action)}
${this.action}
</ak-spinner-button>&nbsp;
<ak-spinner-button
.callAction=${() => {
this.open = false;
}}
class="pf-m-secondary">
${gettext("Cancel")}
${t`Cancel`}
</ak-spinner-button>
</footer>`;
}

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { EVENT_REFRESH } from "../../constants";
import { ModalButton } from "../buttons/ModalButton";
@ -35,14 +35,14 @@ export class DeleteForm extends ModalButton {
onSuccess(): void {
showMessage({
message: gettext(`Successfully deleted ${this.objectLabel} ${ this.obj?.name }`),
message: t`Successfully deleted ${this.objectLabel} ${ this.obj?.name }`,
level: MessageLevel.success,
});
}
onError(e: Error): void {
showMessage({
message: gettext(`Failed to delete ${this.objectLabel}: ${e.toString()}`),
message: t`Failed to delete ${this.objectLabel}: ${e.toString()}`,
level: MessageLevel.error,
});
}
@ -51,7 +51,7 @@ export class DeleteForm extends ModalButton {
return html`<section class="pf-c-page__main-section pf-m-light">
<div class="pf-c-content">
<h1 class="pf-c-title pf-m-2xl">
${gettext(`Delete ${this.objectLabel}`)}
${t`Delete ${this.objectLabel}`}
</h1>
</div>
</section>
@ -62,9 +62,7 @@ export class DeleteForm extends ModalButton {
<div class="pf-c-card__body">
<form class="pf-c-form pf-m-horizontal">
<p>
${gettext(
`Are you sure you want to delete ${this.objectLabel} '${this.obj?.name}'?`
)}
${t`Are you sure you want to delete ${this.objectLabel} '${this.obj?.name}'?`}
</p>
</form>
</div>
@ -78,14 +76,14 @@ export class DeleteForm extends ModalButton {
this.confirm();
}}
class="pf-m-danger">
${gettext("Delete")}
${t`Delete`}
</ak-spinner-button>&nbsp;
<ak-spinner-button
.callAction=${() => {
this.open = false;
}}
class="pf-m-secondary">
${gettext("Cancel")}
${t`Cancel`}
</ak-spinner-button>
</footer>`;
}

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { EVENT_REFRESH } from "../../constants";
import { ModalButton } from "../buttons/ModalButton";
@ -66,7 +66,7 @@ export class ModalForm extends ModalButton {
this.open = false;
}}
class="pf-m-secondary">
${gettext("Cancel")}
${t`Cancel`}
</ak-spinner-button>
</footer>`;
}

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { LitElement, html, customElement, TemplateResult, property, CSSResult, css } from "lit-element";
import "./Message";
import { APIMessage, MessageLevel } from "./Message";
@ -64,7 +64,7 @@ export class MessageContainer extends LitElement {
if (this.retryDelay > 3000) {
showMessage({
level: MessageLevel.error,
message: gettext("Connection error, reconnecting...")
message: t`Connection error, reconnecting...`
});
}
setTimeout(() => {

View File

@ -1,5 +1,5 @@
import { Middleware, ResponseContext } from "authentik-api";
import { gettext } from "django";
import { t } from "@lingui/macro";
import { MessageLevel } from "./Message";
import { showMessage } from "./MessageContainer";
@ -9,7 +9,7 @@ export class MessageMiddleware implements Middleware {
if (context.response.status >= 500) {
showMessage({
level: MessageLevel.error,
message: gettext("API request failed"),
message: t`API request failed`,
description: `${context.init.method} ${context.url}: ${context.response.status}`
});
}

View File

@ -5,7 +5,7 @@ import PFNotificationDrawer from "@patternfly/patternfly/components/Notification
import PFDropdown from "@patternfly/patternfly/components/Dropdown/dropdown.css";
import AKGlobal from "../../authentik.css";
import PFContent from "@patternfly/patternfly/components/Content/content.css";
import { gettext } from "django";
import { t } from "@lingui/macro";
import { EVENT_API_DRAWER_REFRESH } from "../../constants";
export interface RequestInfo {
@ -71,7 +71,7 @@ export class APIDrawer extends LitElement {
<div class="pf-c-notification-drawer">
<div class="pf-c-notification-drawer__header pf-c-content">
<h1>
${gettext("API Requests")}
${t`API Requests`}
</h1>
</div>
<div class="pf-c-notification-drawer__body">

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { css, CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import { EventsApi, Notification } from "authentik-api";
import { AKResponse } from "../../api/Client";
@ -100,10 +100,10 @@ export class NotificationDrawer extends LitElement {
<div class="pf-c-notification-drawer">
<div class="pf-c-notification-drawer__header pf-c-content">
<h1>
${gettext("Notifications")}
${t`Notifications`}
</h1>
<p>
${gettext(`${this.unread} unread`)}
${t`${this.unread} unread`}
</p>
</div>
<div class="pf-c-notification-drawer__body">

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
import { Table, TableColumn } from "../table/Table";
@ -26,9 +26,9 @@ export class UserOAuthCodeList extends Table<ExpiringBaseGrantModel> {
columns(): TableColumn[] {
return [
new TableColumn("Provider", "provider"),
new TableColumn("Expires", "expires"),
new TableColumn("Scopes", "scope"),
new TableColumn(t`Provider`, t`provider`),
new TableColumn(t`Expires`, t`expires`),
new TableColumn(t`Scopes`, t`scope`),
new TableColumn(""),
];
}
@ -41,14 +41,14 @@ export class UserOAuthCodeList extends Table<ExpiringBaseGrantModel> {
html`
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Authorization Code")}
objectLabel=${t`Authorization Code`}
.delete=${() => {
return new Oauth2Api(DEFAULT_CONFIG).oauth2AuthorizationCodesDelete({
id: item.pk || 0,
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
${gettext("Delete Authorization Code")}
${t`Delete Authorization Code`}
</button>
</ak-forms-delete>`,
];

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
import { Table, TableColumn } from "../table/Table";
@ -26,9 +26,9 @@ export class UserOAuthRefreshList extends Table<ExpiringBaseGrantModel> {
columns(): TableColumn[] {
return [
new TableColumn("Provider", "provider"),
new TableColumn("Expires", "expires"),
new TableColumn("Scopes", "scope"),
new TableColumn(t`Provider`, t`provider`),
new TableColumn(t`Expires`, t`expires`),
new TableColumn(t`Scopes`, t`scope`),
new TableColumn(""),
];
}
@ -41,14 +41,14 @@ export class UserOAuthRefreshList extends Table<ExpiringBaseGrantModel> {
html`
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Refresh Code")}
objectLabel=${t`Refresh Code`}
.delete=${() => {
return new Oauth2Api(DEFAULT_CONFIG).oauth2RefreshTokensDelete({
id: item.pk || 0,
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
${gettext("Delete Refresh Code")}
${t`Delete Refresh Code`}
</button>
</ak-forms-delete>`,
];

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import PFEmptyState from "@patternfly/patternfly/components/EmptyState/empty-state.css";
import PFTitle from "@patternfly/patternfly/components/Title/title.css";
@ -18,11 +18,11 @@ export class Router404 extends LitElement {
return html`<div class="pf-c-empty-state pf-m-full-height">
<div class="pf-c-empty-state__content">
<i class="fas fa-question-circle pf-c-empty-state__icon" aria-hidden="true"></i>
<h1 class="pf-c-title pf-m-lg">${gettext("Not found")}</h1>
<h1 class="pf-c-title pf-m-lg">${t`Not found`}</h1>
<div class="pf-c-empty-state__body">
${gettext(`The URL '${this.url}' was not found.`)}
${t`The URL '${this.url}' was not found.`}
</div>
<a href="#/" class="pf-c-button pf-m-primary" type="button">${gettext("Return home")}</a>
<a href="#/" class="pf-c-button pf-m-primary" type="button">${t`Return home`}</a>
</div>
</div>`;
}

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { CSSResult, html, LitElement, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
@ -54,7 +54,7 @@ export class TableColumn {
return html`
<button class="pf-c-table__button" @click=${() => this.headerClickHandler(table)}>
<div class="pf-c-table__button-content">
<span class="pf-c-table__text">${gettext(this.title)}</span>
<span class="pf-c-table__text">${this.title}</span>
<span class="pf-c-table__sort-indicator">
<i class="fas ${this.getSortIndicator(table)}"></i>
</span>
@ -70,7 +70,7 @@ export class TableColumn {
${this.orderBy ? "pf-c-table__sort " : " "}
${(table.order === this.orderBy || table.order === `-${this.orderBy}`) ? "pf-m-selected " : ""}
">
${this.orderBy ? this.renderSortable(table) : html`${gettext(this.title)}`}
${this.orderBy ? this.renderSortable(table) : html`${this.title}`}
</th>`;
}
@ -147,7 +147,7 @@ export abstract class Table<T> extends LitElement {
<div class="pf-l-bullseye">
<ak-empty-state
?loading="${true}"
header=${gettext("Loading")}>
header=${t`Loading`}>
</ak-empty-state>
</div>
</td>
@ -159,7 +159,7 @@ export abstract class Table<T> extends LitElement {
<tr role="row">
<td role="cell" colspan="8">
<div class="pf-l-bullseye">
${inner ? inner : html`<ak-empty-state header="${gettext("No elements found.")}"></ak-empty-state>`}
${inner ? inner : html`<ak-empty-state header="${t`No elements found.`}"></ak-empty-state>`}
</div>
</td>
</tr>
@ -218,7 +218,7 @@ export abstract class Table<T> extends LitElement {
return html`<button
@click=${() => { this.fetch(); }}
class="pf-c-button pf-m-primary">
${gettext("Refresh")}
${t`Refresh`}
</button>`;
}
@ -253,7 +253,7 @@ export abstract class Table<T> extends LitElement {
<thead>
<tr role="row">
${this.checkbox ? html`<td class="pf-c-table__check" role="cell">
<input type="checkbox" aria-label=${gettext("Select all rows")} @input=${(ev: InputEvent) => {
<input type="checkbox" aria-label=${t`Select all rows`} @input=${(ev: InputEvent) => {
if ((ev.target as HTMLInputElement).checked) {
this.selectedElements = this.data?.results || [];
} else {

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { CSSResult } from "lit-element";
import { html, TemplateResult } from "lit-html";
import { ifDefined } from "lit-html/directives/if-defined";
@ -34,9 +34,9 @@ export abstract class TablePage<T> extends Table<T> {
<div class="pf-c-content">
<h1>
<i class="${this.pageIcon()}"></i>
${gettext(this.pageTitle())}
${t`${this.pageTitle()}`}
</h1>
${description ? html`<p>${gettext(description)}</p>` : html``}
${description ? html`<p>${t`${description}`}</p>` : html``}
</div>
</section>
<section class="pf-c-page__main-section pf-m-no-padding-mobile">

View File

@ -1,6 +1,6 @@
import { CSSResult, customElement, html, LitElement, property, TemplateResult } from "lit-element";
import { AKPagination } from "../../api/Client";
import { gettext } from "django";
import { t } from "@lingui/macro";
import PFBase from "@patternfly/patternfly/patternfly-base.css";
import PFButton from "@patternfly/patternfly/components/Button/button.css";
import PFPagination from "@patternfly/patternfly/components/Pagination/pagination.css";
@ -37,7 +37,7 @@ export class TablePagination extends LitElement {
class="pf-c-button pf-m-plain"
@click=${() => { this.pageChangeHandler(this.pages?.previous || 0); }}
?disabled="${(this.pages?.previous || 0) < 1}"
aria-label="${gettext("Go to previous page")}"
aria-label="${t`Go to previous page`}"
>
<i class="fas fa-angle-left" aria-hidden="true"></i>
</button>
@ -47,7 +47,7 @@ export class TablePagination extends LitElement {
class="pf-c-button pf-m-plain"
@click=${() => { this.pageChangeHandler(this.pages?.next || 0); }}
?disabled="${(this.pages?.next || 0) <= 0}"
aria-label="${gettext("Go to next page")}"
aria-label="${t`Go to next page`}"
>
<i class="fas fa-angle-right" aria-hidden="true"></i>
</button>

View File

@ -1,4 +1,4 @@
import { gettext } from "django";
import { t } from "@lingui/macro";
import { customElement, html, property, TemplateResult } from "lit-element";
import { AKResponse } from "../../api/Client";
import { Table, TableColumn } from "../table/Table";
@ -26,8 +26,8 @@ export class UserConsentList extends Table<UserConsent> {
columns(): TableColumn[] {
return [
new TableColumn("Application", "application"),
new TableColumn("Expires", "expires"),
new TableColumn(t`Application`, t`application`),
new TableColumn(t`Expires`, t`expires`),
new TableColumn(""),
];
}
@ -39,14 +39,14 @@ export class UserConsentList extends Table<UserConsent> {
html`
<ak-forms-delete
.obj=${item}
objectLabel=${gettext("Consent")}
objectLabel=${t`Consent`}
.delete=${() => {
return new CoreApi(DEFAULT_CONFIG).coreUserConsentDelete({
id: item.pk || 0,
});
}}>
<button slot="trigger" class="pf-c-button pf-m-danger">
${gettext("Delete Consent")}
${t`Delete Consent`}
</button>
</ak-forms-delete>`,
];