-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Languages: Add Hebrew language #4183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 }; |
| 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"; | ||||||||||
| } | ||||||||||
| case "object": { | ||||||||||
| if (Array.isArray(data)) { | ||||||||||
| return "array"; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| } | ||||||||||
| 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: "קלט", | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe something like "ביטוי רגולרי" or "תבנית"? |
||||||||||
| email: "כתובת אימייל", | ||||||||||
| url: "כתובת רשת", | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
I think it might make more sense, WDYT? |
||||||||||
| emoji: "אימוג'י", | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 לכתובות רשת", | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
same as above |
||||||||||
| json_string: "מחרוזת JSON", | ||||||||||
| e164: "מספר E.164", | ||||||||||
| jwt: "JWT", | ||||||||||
| template_literal: "קלט", | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)}`; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)}`; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| 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 ? "<=" : "<"; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"}`; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
shouldn't be translated as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why aren't you using the sizing verb?
Suggested change
anyway, I think the output sentence will be a broken hebrew There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}"`; | ||||||||||
colinhacks marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
| 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}`; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| case "invalid_union": | ||||||||||
| return "קלט לא תקין"; | ||||||||||
| case "invalid_element": | ||||||||||
| return `ערך לא תקין ב${issue.origin}`; | ||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
| default: | ||||||||||
| return `קלט לא תקין`; | ||||||||||
| } | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export { error }; | ||||||||||
|
|
||||||||||
| export default function (): { localeError: errors.$ZodErrorMap } { | ||||||||||
| return { | ||||||||||
| localeError: error, | ||||||||||
| }; | ||||||||||
| } | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -340,3 +340,4 @@ The following locales are available: | |
|
|
||
| - `az` — Azerbaijani | ||
| - `en` — English | ||
| - `he` — Hebrew | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.