mirror of
https://github.com/bitwarden/browser
synced 2026-01-07 02:53:28 +00:00
[EC-772] Add i18n key typechecking in web (#4023)
This commit is contained in:
@@ -15,7 +15,7 @@ export class AdjustSubscription {
|
||||
@Input() maxAutoscaleSeats: number;
|
||||
@Input() currentSeatCount: number;
|
||||
@Input() seatPrice = 0;
|
||||
@Input() interval = "year";
|
||||
@Input() interval: "month" | "year" = "year";
|
||||
@Output() onAdjusted = new EventEmitter();
|
||||
|
||||
formPromise: Promise<void>;
|
||||
|
||||
@@ -6,6 +6,8 @@ import { FormSelectionList } from "@bitwarden/angular/utils/form-selection-list"
|
||||
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
||||
import { SelectItemView } from "@bitwarden/components/src/multi-select/models/select-item-view";
|
||||
|
||||
import { WebI18nKey } from "../../../core/web-i18n.service.implementation";
|
||||
|
||||
import {
|
||||
AccessItemType,
|
||||
AccessItemValue,
|
||||
@@ -83,7 +85,7 @@ export class AccessSelectorComponent implements ControlValueAccessor, OnInit, On
|
||||
});
|
||||
|
||||
protected itemType = AccessItemType;
|
||||
protected permissionList = [
|
||||
protected permissionList: { perm: CollectionPermission; labelId: WebI18nKey }[] = [
|
||||
{ perm: CollectionPermission.View, labelId: "canView" },
|
||||
{ perm: CollectionPermission.ViewExceptPass, labelId: "canViewExceptPass" },
|
||||
{ perm: CollectionPermission.Edit, labelId: "canEdit" },
|
||||
|
||||
@@ -14,6 +14,8 @@ import {
|
||||
} from "@bitwarden/common/abstractions/organization/organization.service.abstraction";
|
||||
import { Organization } from "@bitwarden/common/models/domain/organization";
|
||||
|
||||
import { WebI18nKey } from "../../core/web-i18n.service.implementation";
|
||||
|
||||
@Component({
|
||||
selector: "app-organization-layout",
|
||||
templateUrl: "organization-layout.component.html",
|
||||
@@ -69,7 +71,7 @@ export class OrganizationLayoutComponent implements OnInit, OnDestroy {
|
||||
return canAccessBillingTab(organization);
|
||||
}
|
||||
|
||||
getReportTabLabel(organization: Organization): string {
|
||||
getReportTabLabel(organization: Organization): WebI18nKey {
|
||||
return organization.useEvents ? "reporting" : "reports";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,10 @@ import { SelectionReadOnlyRequest } from "@bitwarden/common/models/request/selec
|
||||
import { CollectionDetailsResponse } from "@bitwarden/common/models/response/collection.response";
|
||||
import { CollectionView } from "@bitwarden/common/models/view/collection.view";
|
||||
|
||||
import { WebI18nKey } from "../../core/web-i18n.service.implementation";
|
||||
|
||||
type NestedCheckbox = { id: WebI18nKey; get: () => boolean; set: (v: boolean) => boolean };
|
||||
|
||||
@Component({
|
||||
selector: "app-user-add-edit",
|
||||
templateUrl: "user-add-edit.component.html",
|
||||
@@ -49,7 +53,7 @@ export class UserAddEditComponent implements OnInit {
|
||||
organizationUserType = OrganizationUserType;
|
||||
canUseCustomPermissions: boolean;
|
||||
|
||||
manageAllCollectionsCheckboxes = [
|
||||
manageAllCollectionsCheckboxes: NestedCheckbox[] = [
|
||||
{
|
||||
id: "createNewCollections",
|
||||
get: () => this.permissions.createNewCollections,
|
||||
@@ -67,7 +71,7 @@ export class UserAddEditComponent implements OnInit {
|
||||
},
|
||||
];
|
||||
|
||||
manageAssignedCollectionsCheckboxes = [
|
||||
manageAssignedCollectionsCheckboxes: NestedCheckbox[] = [
|
||||
{
|
||||
id: "editAssignedCollections",
|
||||
get: () => this.permissions.editAssignedCollections,
|
||||
|
||||
@@ -6,9 +6,11 @@ import { Organization } from "@bitwarden/common/models/domain/organization";
|
||||
import { PolicyRequest } from "@bitwarden/common/models/request/policy.request";
|
||||
import { PolicyResponse } from "@bitwarden/common/models/response/policy.response";
|
||||
|
||||
import { WebI18nKey } from "../../core/web-i18n.service.implementation";
|
||||
|
||||
export abstract class BasePolicy {
|
||||
abstract name: string;
|
||||
abstract description: string;
|
||||
abstract name: WebI18nKey;
|
||||
abstract description: WebI18nKey;
|
||||
abstract type: PolicyType;
|
||||
abstract component: any;
|
||||
|
||||
|
||||
@@ -5,8 +5,8 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class DisableSendPolicy extends BasePolicy {
|
||||
name = "disableSend";
|
||||
description = "disableSendPolicyDesc";
|
||||
readonly name = "disableSend";
|
||||
readonly description = "disableSendPolicyDesc";
|
||||
type = PolicyType.DisableSend;
|
||||
component = DisableSendPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class MasterPasswordPolicy extends BasePolicy {
|
||||
name = "masterPassPolicyTitle";
|
||||
description = "masterPassPolicyDesc";
|
||||
readonly name = "masterPassPolicyTitle";
|
||||
readonly description = "masterPassPolicyDesc";
|
||||
type = PolicyType.MasterPassword;
|
||||
component = MasterPasswordPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class PasswordGeneratorPolicy extends BasePolicy {
|
||||
name = "passwordGenerator";
|
||||
description = "passwordGeneratorPolicyDesc";
|
||||
readonly name = "passwordGenerator";
|
||||
readonly description = "passwordGeneratorPolicyDesc";
|
||||
type = PolicyType.PasswordGenerator;
|
||||
component = PasswordGeneratorPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class PersonalOwnershipPolicy extends BasePolicy {
|
||||
name = "personalOwnership";
|
||||
description = "personalOwnershipPolicyDesc";
|
||||
readonly name = "personalOwnership";
|
||||
readonly description = "personalOwnershipPolicyDesc";
|
||||
type = PolicyType.PersonalOwnership;
|
||||
component = PersonalOwnershipPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,8 @@ import { PolicyRequest } from "@bitwarden/common/models/request/policy.request";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class RequireSsoPolicy extends BasePolicy {
|
||||
name = "requireSso";
|
||||
description = "requireSsoPolicyDesc";
|
||||
readonly name = "requireSso";
|
||||
readonly description = "requireSsoPolicyDesc";
|
||||
type = PolicyType.RequireSso;
|
||||
component = RequireSsoPolicyComponent;
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ import { Organization } from "@bitwarden/common/models/domain/organization";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class ResetPasswordPolicy extends BasePolicy {
|
||||
name = "resetPasswordPolicy";
|
||||
description = "resetPasswordPolicyDescription";
|
||||
readonly name = "resetPasswordPolicy";
|
||||
readonly description = "resetPasswordPolicyDescription";
|
||||
type = PolicyType.ResetPassword;
|
||||
component = ResetPasswordPolicyComponent;
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class SendOptionsPolicy extends BasePolicy {
|
||||
name = "sendOptions";
|
||||
description = "sendOptionsPolicyDesc";
|
||||
readonly name = "sendOptions";
|
||||
readonly description = "sendOptionsPolicyDesc";
|
||||
type = PolicyType.SendOptions;
|
||||
component = SendOptionsPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -7,8 +7,8 @@ import { PolicyRequest } from "@bitwarden/common/models/request/policy.request";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class SingleOrgPolicy extends BasePolicy {
|
||||
name = "singleOrg";
|
||||
description = "singleOrgDesc";
|
||||
readonly name = "singleOrg";
|
||||
readonly description = "singleOrgDesc";
|
||||
type = PolicyType.SingleOrg;
|
||||
component = SingleOrgPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -5,8 +5,8 @@ import { PolicyType } from "@bitwarden/common/enums/policyType";
|
||||
import { BasePolicy, BasePolicyComponent } from "./base-policy.component";
|
||||
|
||||
export class TwoFactorAuthenticationPolicy extends BasePolicy {
|
||||
name = "twoStepLoginPolicyTitle";
|
||||
description = "twoStepLoginPolicyDesc";
|
||||
readonly name = "twoStepLoginPolicyTitle";
|
||||
readonly description = "twoStepLoginPolicyDesc";
|
||||
type = PolicyType.TwoFactorAuthentication;
|
||||
component = TwoFactorAuthenticationPolicyComponent;
|
||||
}
|
||||
|
||||
@@ -12,15 +12,17 @@ import { Utils } from "@bitwarden/common/misc/utils";
|
||||
import { CipherView } from "@bitwarden/common/models/view/cipher.view";
|
||||
import { Verification } from "@bitwarden/common/types/verification";
|
||||
|
||||
import { WebI18nKey } from "../../core/web-i18n.service.implementation";
|
||||
|
||||
class CountBasedLocalizationKey {
|
||||
singular: string;
|
||||
plural: string;
|
||||
singular: WebI18nKey;
|
||||
plural: WebI18nKey;
|
||||
|
||||
getKey(count: number) {
|
||||
return count == 1 ? this.singular : this.plural;
|
||||
}
|
||||
|
||||
constructor(singular: string, plural: string) {
|
||||
constructor(singular: WebI18nKey, plural: WebI18nKey) {
|
||||
this.singular = singular;
|
||||
this.plural = plural;
|
||||
}
|
||||
@@ -28,7 +30,7 @@ class CountBasedLocalizationKey {
|
||||
|
||||
class OrganizationContentSummaryItem {
|
||||
count: number;
|
||||
get localizationKey(): string {
|
||||
get localizationKey() {
|
||||
return this.localizationKeyOptions.getKey(this.count);
|
||||
}
|
||||
private localizationKeyOptions: CountBasedLocalizationKey;
|
||||
@@ -126,6 +128,9 @@ export class DeleteOrganizationComponent implements OnInit {
|
||||
}
|
||||
|
||||
private getOrganizationItemLocalizationKeysByType(type: string): CountBasedLocalizationKey {
|
||||
return new CountBasedLocalizationKey(`type${type}`, `type${type}Plural`);
|
||||
return new CountBasedLocalizationKey(
|
||||
`type${type}` as WebI18nKey,
|
||||
`type${type}Plural` as WebI18nKey
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user