mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-24 12:06:15 +01:00
[CL-128] Support placeholders in i18n mock (#6254)
This commit is contained in:
parent
90d4655092
commit
fc4379f392
@ -24,7 +24,7 @@ export default {
|
||||
required: "required",
|
||||
inputRequired: "Input is required.",
|
||||
inputEmail: "Input is not an email-address.",
|
||||
fieldsNeedAttention: "$COUNT$ field(s) above need your attention.",
|
||||
fieldsNeedAttention: "__$1__ field(s) above need your attention.",
|
||||
});
|
||||
},
|
||||
},
|
||||
@ -63,12 +63,12 @@ export const Default: StoryObj<BitFormFieldComponent> = {
|
||||
<bit-label>Name</bit-label>
|
||||
<input bitInput formControlName="name" />
|
||||
</bit-form-field>
|
||||
|
||||
|
||||
<bit-form-field>
|
||||
<bit-label>Email</bit-label>
|
||||
<input bitInput formControlName="email" />
|
||||
</bit-form-field>
|
||||
|
||||
|
||||
<button type="submit" bitButton buttonType="primary">Submit</button>
|
||||
<bit-error-summary [formGroup]="formObj"></bit-error-summary>
|
||||
</form>
|
||||
|
@ -12,8 +12,20 @@ export class I18nMockService implements I18nService {
|
||||
constructor(private lookupTable: Record<string, string | ((...args: string[]) => string)>) {}
|
||||
|
||||
t(id: string, p1?: string, p2?: string, p3?: string) {
|
||||
const value = this.lookupTable[id];
|
||||
let value = this.lookupTable[id];
|
||||
if (typeof value == "string") {
|
||||
if (value !== "") {
|
||||
if (p1 != null) {
|
||||
value = value.split("__$1__").join(p1.toString());
|
||||
}
|
||||
if (p2 != null) {
|
||||
value = value.split("__$2__").join(p2.toString());
|
||||
}
|
||||
if (p3 != null) {
|
||||
value = value.split("__$3__").join(p3.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
return value(p1, p2, p3);
|
||||
|
Loading…
Reference in New Issue
Block a user