-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Languages: Add Arabic language #4176
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
Merged
colinhacks
merged 37 commits into
colinhacks:v4
from
Abdalrhman-Almarakeby:feat/arabic-language
May 13, 2025
Merged
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
5a7c373
feat(lang): Add Arabic locale support
Abdalrhman-Almarakeby 42bb7f0
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 9c90710
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby b09cda6
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 9a437fb
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby b6d7c77
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 9cab990
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby f0559d6
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 1f54f0c
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 5737fbc
remove period
Abdalrhman-Almarakeby 69aa8cd
fix: add space after comparison operator
Abdalrhman-Almarakeby 9cf2c88
feat(lang): Add Arabic locale support
Abdalrhman-Almarakeby 5028645
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 871edb0
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 62912ab
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby ff3b4b8
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 71840d0
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 475472e
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 4a33f79
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 585cb56
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 98f8d28
remove period
Abdalrhman-Almarakeby 33bb8a0
fix: add space after comparison operator
Abdalrhman-Almarakeby 97fc2c7
Tweak
colinhacks 270dd56
Merge branch 'feat/arabic-language' of https://github.com/Abdalrhman-…
Abdalrhman-Almarakeby 98aec74
Updated ar.ts with new edits discussed in #4176
hAbuMustafa 0d2855e
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 56228a1
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 9fac08e
Update packages/core/src/locales/ar.ts
Abdalrhman-Almarakeby 3538f12
Merge pull request #1 from hAbuMustafa/patch-1
Abdalrhman-Almarakeby 2df796d
chore: format
Abdalrhman-Almarakeby 15b3de5
fix: update translation for template_literal
Abdalrhman-Almarakeby 34fafd5
fix: correct translation for invalid input error message
Abdalrhman-Almarakeby e5a6989
fix: spacing in error messages
Abdalrhman-Almarakeby 0570b8b
fix: show correct prefix
Abdalrhman-Almarakeby b8c6142
fix: remove unused template literal
Abdalrhman-Almarakeby cdf52ee
Update error-customization.mdx
Abdalrhman-Almarakeby 0f10b94
Merge branch 'v4' into feat/arabic-language
colinhacks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import ar from "./locales/ar.js"; | ||
| import az from "./locales/az.js"; | ||
| import en from "./locales/en.js"; | ||
| import es from "./locales/es.js"; | ||
|
|
||
| export { az, es, en }; | ||
| export { ar, az, es, en }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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"; | ||
| } | ||
| 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: "input", | ||
| email: "email address", | ||
| url: "URL", | ||
| emoji: "emoji", | ||
| uuid: "UUID", | ||
| uuidv4: "UUIDv4", | ||
| uuidv6: "UUIDv6", | ||
| nanoid: "nanoid", | ||
| guid: "GUID", | ||
| cuid: "cuid", | ||
| cuid2: "cuid2", | ||
| ulid: "ULID", | ||
| xid: "XID", | ||
| ksuid: "KSUID", | ||
| datetime: "ISO datetime", | ||
| date: "ISO date", | ||
| time: "ISO time", | ||
| duration: "ISO duration", | ||
| ipv4: "IPv4 address", | ||
| ipv6: "IPv6 address", | ||
| cidrv4: "IPv4 range", | ||
| cidrv6: "IPv6 range", | ||
| base64: "base64-encoded string", | ||
| base64url: "base64url-encoded string", | ||
| json_string: "JSON string", | ||
| e164: "E.164 number", | ||
| jwt: "JWT", | ||
| template_literal: "input", | ||
| }; | ||
|
|
||
| const error: errors.$ZodErrorMap = (issue) => { | ||
| switch (issue.code) { | ||
| case "invalid_type": | ||
| return `نوع غير صالح: كان من المتوقع ${issue.expected}، تم استلام ${parsedType(issue.input)}`; | ||
Abdalrhman-Almarakeby marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 ? "<=" : "<"; | ||
| const sizing = getSizing(issue.origin); | ||
| if (sizing) | ||
| return `كبير جدًا: من المتوقع أن يحتوي ${issue.origin ?? "value"} على ${adj}${issue.maximum.toString()} ${sizing.unit ?? "elements"}`; | ||
| 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}"`; | ||
Abdalrhman-Almarakeby marked this conversation as resolved.
Outdated
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 ? "مفاتيح غير مُعرَّفة" : "مفتاح غير مُعرَّف"}: ${util.joinValues(issue.keys, "، ")}`; | ||
Abdalrhman-Almarakeby marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| case "invalid_key": | ||
| return `مفتاح غير صالح في ${issue.origin}`; | ||
| case "invalid_union": | ||
| return "القيمة المُدخلة لا تطابق أيًا من الأنواع المتوقعة"; | ||
| case "invalid_element": | ||
| return `عنصر غير صالح ضمن: ${issue.origin}`; | ||
| default: | ||
| return "إدخال غير صالح"; | ||
| } | ||
| }; | ||
|
|
||
| export { error }; | ||
|
|
||
| export default function (): { localeError: errors.$ZodErrorMap } { | ||
| return { | ||
| localeError: error, | ||
| }; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.