Skip to content

Commit 3950dcb

Browse files
committed
Fix double-translation issue from switching from Transifex
Strings in src/schemas are no longer translated. FormInputError already translates these strings. Having src/schemas translate strings would cause a double translation. Having FormInputError not translate strings would cause these strings to not update when switching languages. This was not an issue with @transifex/native, which seems to defer evaluation of the strings, somehow. This assumes strings in src/schemas all pass through FormInputError!
1 parent 1f07b8b commit 3950dcb

File tree

3 files changed

+89
-89
lines changed

3 files changed

+89
-89
lines changed

src/schemas/OCPsettings.ts

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,65 @@
11
import { type TypeOf, z } from "zod";
2-
import { t } from "../util/i18n";
32

43
import { CREDIT_PRODUCT_TYPE } from "../constants";
54

6-
const creditProviderNameSchema = z.string().min(1, t("Provider name is required"));
7-
const creditProviderTypeSchema = z.string().min(1, t("Provider type is required"));
5+
const creditProviderNameSchema = z.string().min(1, "Provider name is required");
6+
const creditProviderTypeSchema = z.string().min(1, "Provider type is required");
87

98
export const lenderSchema = z.object({
109
name: creditProviderNameSchema,
1110
type: creditProviderTypeSchema,
1211
sla_days: z.coerce
1312
.number()
1413
.int()
15-
.positive(t("SLA days must be greater than 0"))
16-
.min(1, t("SLA days must be greater than 0")),
17-
email_group: z.string().email(t("Email Address is invalid")),
14+
.positive("SLA days must be greater than 0")
15+
.min(1, "SLA days must be greater than 0"),
16+
email_group: z.string().email("Email Address is invalid"),
1817
logo_filename: z.string(),
19-
external_onboarding_url: z.string().url(t("URL is invalid (Hint: include http:// or https://)")),
18+
external_onboarding_url: z.string().url("URL is invalid (Hint: include http:// or https://)"),
2019
});
2120

2221
export type ProviderInput = TypeOf<typeof lenderSchema>;
2322

24-
export const creditProductSchema = z.object({
25-
borrower_size: z.string().min(1, t("Borrower size is required")),
26-
lower_limit: z.coerce.number().min(1, t("Lower limit must be greater than 0")),
27-
upper_limit: z.coerce.number().min(1, t("Upper limit must be greater than 0")),
28-
interest_rate: z.string().min(1, t("Interest rate description is required")),
29-
type: z.nativeEnum(CREDIT_PRODUCT_TYPE, {
30-
errorMap: (issue) => {
31-
switch (issue.code) {
32-
case "invalid_type":
33-
case "invalid_enum_value":
34-
return { message: t("Type of product is required") };
35-
default:
36-
return { message: t("Select an option") };
37-
}
38-
},
39-
}),
40-
procurement_category_to_exclude: z.string(),
41-
required_document_types: z.record(z.string().min(1), z.boolean()),
42-
borrower_types: z.record(z.string().min(1), z.boolean()),
43-
other_fees_total_amount: z.preprocess(
44-
(args) => (args === "" ? undefined : args),
45-
z.coerce
46-
.number({
47-
required_error: t("Other fees total amount is required"),
48-
invalid_type_error: t("Other fees total amount must be a number"),
49-
})
50-
.gte(0, t("Other fees total amount must be greater or equal than 0")),
51-
),
52-
other_fees_description: z.string().min(1, t("Other fees description is required")),
53-
additional_information: z.string(),
54-
more_info_url: z.string().url(t("URL is invalid (Hint: include http:// or https://)")),
55-
})
23+
export const creditProductSchema = z
24+
.object({
25+
borrower_size: z.string().min(1, "Borrower size is required"),
26+
lower_limit: z.coerce.number().min(1, "Lower limit must be greater than 0"),
27+
upper_limit: z.coerce.number().min(1, "Upper limit must be greater than 0"),
28+
interest_rate: z.string().min(1, "Interest rate description is required"),
29+
type: z.nativeEnum(CREDIT_PRODUCT_TYPE, {
30+
errorMap: (issue) => {
31+
switch (issue.code) {
32+
case "invalid_type":
33+
case "invalid_enum_value":
34+
return { message: "Type of product is required" };
35+
default:
36+
return { message: "Select an option" };
37+
}
38+
},
39+
}),
40+
procurement_category_to_exclude: z.string(),
41+
required_document_types: z.record(z.string().min(1), z.boolean()),
42+
borrower_types: z.record(z.string().min(1), z.boolean()),
43+
other_fees_total_amount: z.preprocess(
44+
(args) => (args === "" ? undefined : args),
45+
z.coerce
46+
.number({
47+
required_error: "Other fees total amount is required",
48+
invalid_type_error: "Other fees total amount must be a number",
49+
})
50+
.gte(0, "Other fees total amount must be greater or equal than 0"),
51+
),
52+
other_fees_description: z.string().min(1, "Other fees description is required"),
53+
additional_information: z.string(),
54+
more_info_url: z.string().url("URL is invalid (Hint: include http:// or https://)"),
55+
})
5656
.refine((data) => data.lower_limit < data.upper_limit, {
5757
path: ["lower_limit"],
58-
message: t("Lower limit must be less than upper limit"),
58+
message: "Lower limit must be less than upper limit",
5959
})
6060
.refine((data) => data.lower_limit < data.upper_limit, {
6161
path: ["upper_limit"],
62-
message: t("Upper limit must be greater than lower limit"),
62+
message: "Upper limit must be greater than lower limit",
6363
});
6464

6565
export type CreditProductInput = TypeOf<typeof creditProductSchema>;

src/schemas/application.ts

Lines changed: 33 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import { type TypeOf, z } from "zod";
2-
import { t } from "../util/i18n";
32

43
import type { APPLICATION_STATUS, USER_TYPES } from "../constants";
54
import { isDateAfterCurrentDate } from "../util";
65
import { emailSchema } from "./auth";
76

87
export const introSchema = z.object({
98
accept_terms_and_conditions: z.boolean().refine((value) => value === true, {
10-
message: t("You need to check this option to Access the Scheme"),
9+
message: "You need to check this option to Access the Scheme",
1110
}),
1211
});
1312

1413
export type IntroInput = TypeOf<typeof introSchema>;
1514

1615
export const submitSchema = z.object({
1716
agree_topass_info_to_banking_partner: z.boolean().refine((value) => value === true, {
18-
message: t("You need to check this option to submit the application"),
17+
message: "You need to check this option to submit the application",
1918
}),
2019
});
2120

@@ -29,14 +28,16 @@ export const applicationBaseSchema = z.object({
2928

3029
export type ApplicationBaseInput = TypeOf<typeof applicationBaseSchema>;
3130

32-
export const declineApplicationSchema = z.object({
33-
decline_this: z.boolean(),
34-
decline_all: z.boolean(),
35-
uuid: UUIDType,
36-
}).refine((data) => data.decline_this || data.decline_all, {
37-
path: ["decline_all"],
38-
message: t("You need to check at least one option to Decline the Scheme"),
39-
});
31+
export const declineApplicationSchema = z
32+
.object({
33+
decline_this: z.boolean(),
34+
decline_all: z.boolean(),
35+
uuid: UUIDType,
36+
})
37+
.refine((data) => data.decline_this || data.decline_all, {
38+
path: ["decline_all"],
39+
message: "You need to check at least one option to Decline the Scheme",
40+
});
4041

4142
export type DeclineApplicationInput = TypeOf<typeof declineApplicationSchema>;
4243

@@ -50,14 +51,13 @@ export enum DECLINE_FEEDBACK {
5051
}
5152

5253
export const DECLINE_FEEDBACK_NAMES: { [key: string]: string } = {
53-
[DECLINE_FEEDBACK.dont_need_access_credit]: t("Don't need access credit"),
54-
[DECLINE_FEEDBACK.already_have_acredit]: t("Already have acredit"),
55-
[DECLINE_FEEDBACK.preffer_to_go_to_bank]: t("Preffer to go to bank"),
56-
[DECLINE_FEEDBACK.dont_want_access_credit]: t("Don't want access credit"),
57-
[DECLINE_FEEDBACK.suspicious_email]: t(
54+
[DECLINE_FEEDBACK.dont_need_access_credit]: "Don't need access credit",
55+
[DECLINE_FEEDBACK.already_have_acredit]: "Already have acredit",
56+
[DECLINE_FEEDBACK.preffer_to_go_to_bank]: "Preffer to go to bank",
57+
[DECLINE_FEEDBACK.dont_want_access_credit]: "Don't want access credit",
58+
[DECLINE_FEEDBACK.suspicious_email]:
5859
"I perceive the email as suspicious or I do not trust that the credit proposal is true",
59-
),
60-
[DECLINE_FEEDBACK.other]: t("Other"),
60+
[DECLINE_FEEDBACK.other]: "Other",
6161
};
6262

6363
export const declineFeedbackSchema = z.object({
@@ -74,10 +74,10 @@ export const declineFeedbackSchema = z.object({
7474
export type DeclineFeedbackInput = TypeOf<typeof declineFeedbackSchema>;
7575

7676
export const creditOptionsSchema = z.object({
77-
borrower_size: z.string().min(1, t("Borrower size is required")),
78-
sector: z.string().min(1, t("Sector is required")),
77+
borrower_size: z.string().min(1, "Borrower size is required"),
78+
sector: z.string().min(1, "Sector is required"),
7979
annual_revenue: z.coerce.number().optional().nullable(),
80-
amount_requested: z.coerce.number().min(1, t("Amount requested must be greater than 0")),
80+
amount_requested: z.coerce.number().min(1, "Amount requested must be greater than 0"),
8181
uuid: UUIDType,
8282
});
8383

@@ -88,15 +88,16 @@ export type GetCreditProductsOptionsInput = Omit<CreditOptionsInput, "sector" |
8888
export const repaymentTermsSchema = z.object({
8989
repayment_years: z.coerce
9090
.number({
91-
required_error: t("Years is required"),
92-
invalid_type_error: t("Years must be a number"),
91+
required_error: "Years is required",
92+
invalid_type_error: "Years must be a number",
9393
})
94-
.gte(0, t("Years must be greater or equal than ")),
95-
repayment_months: z.coerce.number().min(1, t("Months must be greater or equal than 1")),
96-
payment_start_date: z.string()
97-
.min(1, t("Payment start date is required"))
94+
.gte(0, "Years must be greater or equal than "),
95+
repayment_months: z.coerce.number().min(1, "Months must be greater or equal than 1"),
96+
payment_start_date: z
97+
.string()
98+
.min(1, "Payment start date is required")
9899
.refine((value) => isDateAfterCurrentDate(value), {
99-
message: t("Payment start date must be after current date"),
100+
message: "Payment start date must be after current date",
100101
}),
101102
});
102103

@@ -336,7 +337,7 @@ export interface ILenderListResponse {
336337
}
337338

338339
export const formEmailSchema = z.object({
339-
message: z.string().min(1, t("A message is required")),
340+
message: z.string().min(1, "A message is required"),
340341
});
341342

342343
export type FormEmailInput = TypeOf<typeof formEmailSchema>;
@@ -348,10 +349,10 @@ export const approveSchema = z.object({
348349
compliant_checks_passed: z.boolean(),
349350
disbursed_final_amount: z.coerce
350351
.number({
351-
required_error: t("Disbursed final amount is required"),
352-
invalid_type_error: t("Disbursed final amount must be a number"),
352+
required_error: "Disbursed final amount is required",
353+
invalid_type_error: "Disbursed final amount must be a number",
353354
})
354-
.gt(0, t("Disbursed final amount must be greater than 0")),
355+
.gt(0, "Disbursed final amount must be greater than 0"),
355356
});
356357

357358
export type FormApprovedInput = TypeOf<typeof approveSchema>;

src/schemas/auth.ts

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
import { type TypeOf, z } from "zod";
2-
import { t } from "../util/i18n";
32

43
import { USER_TYPES } from "../constants";
54
import type { ILender } from "./application";
65

7-
export const emailSchema = z.string().min(1, t("Email address is required")).email(t("Email Address is invalid"));
8-
const passwordSchema = z.string()
9-
.min(1, t("Password is required"))
10-
.min(14, t("Password must be more than 14 characters"));
11-
const otp = z.string().min(6, t("OTP length must be 6 digits")).max(6, t("OTP length must be 6 digits"));
6+
export const emailSchema = z.string().min(1, "Email address is required").email("Email Address is invalid");
7+
const passwordSchema = z.string().min(1, "Password is required").min(14, "Password must be more than 14 characters");
8+
const otp = z.string().min(6, "OTP length must be 6 digits").max(6, "OTP length must be 6 digits");
129

1310
export const loginSchema = z.object({
1411
username: emailSchema,
@@ -29,7 +26,7 @@ export interface SetupMFAInput {
2926
session: string;
3027
}
3128

32-
const nameSchema = z.string().nonempty(t("Full name is required"));
29+
const nameSchema = z.string().nonempty("Full name is required");
3330

3431
export const createUserSchema = z.object({
3532
name: nameSchema,
@@ -39,9 +36,9 @@ export const createUserSchema = z.object({
3936
switch (issue.code) {
4037
case "invalid_type":
4138
case "invalid_enum_value":
42-
return { message: t("Type of user is required") };
39+
return { message: "Type of user is required" };
4340
default:
44-
return { message: t("Select an option") };
41+
return { message: "Select an option" };
4542
}
4643
},
4744
}),
@@ -52,13 +49,15 @@ export type CreateUserInput = TypeOf<typeof createUserSchema>;
5249

5350
export type UpdateUserInput = Omit<CreateUserInput, "email"> & { id: string | undefined };
5451

55-
export const setPasswordSchema = z.object({
56-
password: passwordSchema,
57-
passwordConfirm: z.string().min(1, t("Please confirm your password")),
58-
}).refine((data) => data.password === data.passwordConfirm, {
59-
path: ["passwordConfirm"],
60-
message: t("Passwords do not match"),
61-
});
52+
export const setPasswordSchema = z
53+
.object({
54+
password: passwordSchema,
55+
passwordConfirm: z.string().min(1, "Please confirm your password"),
56+
})
57+
.refine((data) => data.password === data.passwordConfirm, {
58+
path: ["passwordConfirm"],
59+
message: "Passwords do not match",
60+
});
6261

6362
export type UpdatePasswordInput = TypeOf<typeof setPasswordSchema>;
6463
export type UpdatePasswordPayload = {

0 commit comments

Comments
 (0)