Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/core/src/locales.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import az from "./locales/az.js";
import en from "./locales/en.js";
import es from "./locales/es.js";
import he from "./locales/he.js";

export { az, es, en };
export { az, es, en, he };
125 changes: 125 additions & 0 deletions packages/core/src/locales/he.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import type { $ZodStringFormats } from "../checks.js";
import type * as errors from "../errors.js";
import * as util from "../util.js";

const Sizable: Record<string, { unit: string; verb: string }> = {
string: { unit: "אותיות", verb: "לכלול" },
file: { unit: "בייטים", verb: "לכלול" },
array: { unit: "פריטים", verb: "לכלול" },
set: { unit: "פריטים", verb: "לכלול" },
};

function getSizing(origin: string): { unit: string; verb: string } | null {
return Sizable[origin] ?? null;
}

export const parsedType = (data: any): string => {
const t = typeof data;

switch (t) {
case "number": {
return Number.isNaN(data) ? "NaN" : "number";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return Number.isNaN(data) ? "NaN" : "number";
return Number.isNaN(data) ? "NaN" : "מספר";

}
case "object": {
if (Array.isArray(data)) {
return "array";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return "array";
return "מערך";

}
if (data === null) {
return "null";
}

if (Object.getPrototypeOf(data) !== Object.prototype && data.constructor) {
return data.constructor.name;
}
}
}
return t;
};

const Nouns: {
[k in $ZodStringFormats | (string & {})]?: string;
} = {
regex: "קלט",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe something like "ביטוי רגולרי" or "תבנית"?

email: "כתובת אימייל",
url: "כתובת רשת",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
url: "כתובת רשת",
url: "כתובת אתר",

I think it might make more sense, WDYT?

emoji: "אימוג'י",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

technically should be "פַּרְצוּפוֹן", but I agree this one is better 😅

https://hebrew-academy.org.il/2019/11/11/%D7%94%D7%9E%D7%A8%D7%A9%D7%AA%D7%AA/

uuid: "UUID",
uuidv4: "UUIDv4",
uuidv6: "UUIDv6",
nanoid: "nanoid",
guid: "GUID",
cuid: "cuid",
cuid2: "cuid2",
ulid: "ULID",
xid: "XID",
ksuid: "KSUID",
datetime: "תאריך וזמן ISO",
date: "תאריך ISO",
time: "זמן ISO",
duration: "משך זמן ISO",
ipv4: "כתובת IPv4",
ipv6: "כתובת IPv6",
cidrv4: "טווח IPv4",
cidrv6: "טווח IPv6",
base64: "מחרוזת בבסיס 64",
base64url: "מחרוזת בבסיס 64 לכתובות רשת",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
base64url: "מחרוזת בבסיס 64 לכתובות רשת",
base64url: "מחרוזת בבסיס 64 לכתובות אתר",

same as above

json_string: "מחרוזת JSON",
e164: "מספר E.164",
jwt: "JWT",
template_literal: "קלט",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, not sure how to translate that

EDIT: oh ok, now I see that it's a direct translation of the englsh version

};

const error: errors.$ZodErrorMap = (issue) => {
switch (issue.code) {
case "invalid_type":
return `קלט לא תקין: צריך ${issue.expected}, התקבל ${parsedType(issue.input)}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure whether "צריך" is the right term here, since the direct translation of "expected" is "צפוי", but it might sound weird in this sentence

also in other cases

// return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(issue.input)}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// return `Invalid input: expected ${issue.expected}, received ${util.getParsedType(issue.input)}`;

case "invalid_value":
if (issue.values.length === 1) return `קלט לא תקין: צריך ${util.stringifyPrimitive(issue.values[0])}`;
return `קלט לא תקין: צריך אחת מהאפשרויות ${util.joinValues(issue.values, "|")}`;
case "too_big": {
const adj = issue.inclusive ? "<=" : "<";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would translate the sign as well, since using ">=" in a hebrew sentence doesn't really make sense

const sizing = getSizing(issue.origin);
if (sizing)
return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `גדול מדי: ${issue.origin ?? "הערך"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "אלמנטים"}`;

shouldn't be translated as well?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why aren't you using the sizing verb?

Suggested change
return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;
return `גדול מדי: ${issue.origin ?? "value"} צריך ${sizing.verb} ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`;

anyway, I think the output sentence will be a broken hebrew

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

starting the error with "גדול מדי" or "קטן מדי" in hebrew is weird IMO, but maybe it's fine? 🤷

return `גדול מדי: ${issue.origin ?? "value"} צריך להיות ${adj}${issue.maximum.toString()}`;
}
case "too_small": {
const adj = issue.inclusive ? ">=" : ">";
const sizing = getSizing(issue.origin);
if (sizing) {
return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()} ${sizing.unit}`;
}

return `קטן מדי: ${issue.origin} צריך להיות ${adj}${issue.minimum.toString()}`;
}
case "invalid_format": {
const _issue = issue as errors.$ZodStringFormatIssues;
if (_issue.format === "starts_with") return `מחרוזת לא תקינה: חייבת להתחיל ב"${issue}"`;
if (_issue.format === "ends_with") return `מחרוזת לא תקינה: חייבת להסתיים ב "${_issue.suffix}"`;
if (_issue.format === "includes") return `מחרוזת לא תקינה: חייבת לכלול "${_issue.includes}"`;
if (_issue.format === "regex") return `מחרוזת לא תקינה: חייבת להתאים לתבנית ${_issue.pattern}`;
return `${Nouns[_issue.format] ?? issue.format} לא תקין`;
}
case "not_multiple_of":
return `מספר לא תקין: חייב להיות מכפלה של ${issue.divisor}`;
case "unrecognized_keys":
return `מפתח${issue.keys.length > 1 ? "ות" : ""} לא מזוה${issue.keys.length > 1 ? "ים" : "ה"}: ${util.joinValues(issue.keys, ", ")}`;
case "invalid_key":
return `מפתח לא תקין ב${issue.origin}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return `מפתח לא תקין ב${issue.origin}`;
return `מפתח לא תקין ב ${issue.origin}`;

case "invalid_union":
return "קלט לא תקין";
case "invalid_element":
return `ערך לא תקין ב${issue.origin}`;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return `ערך לא תקין ב${issue.origin}`;
return `ערך לא תקין ב ${issue.origin}`;

default:
return `קלט לא תקין`;
}
};

export { error };

export default function (): { localeError: errors.$ZodErrorMap } {
return {
localeError: error,
};
}
1 change: 1 addition & 0 deletions packages/docs/content/error-customization.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -340,3 +340,4 @@ The following locales are available:

- `az` — Azerbaijani
- `en` — English
- `he` — Hebrew