Skip to content

feat(ar): add native Arabic language support (ar locale) - #656

Open
KareemHussen wants to merge 1 commit into
wanasit:masterfrom
KareemHussen:feat/arabic-locale-support
Open

feat(ar): add native Arabic language support (ar locale)#656
KareemHussen wants to merge 1 commit into
wanasit:masterfrom
KareemHussen:feat/arabic-locale-support

Conversation

@KareemHussen

Copy link
Copy Markdown

Summary

This PR introduces native Arabic (ar) language parsing support to Chrono (chrono-node), aligning with the architecture and standards established in recently merged language locales (such as Vietnamese #641, Finnish #642, and Russian #458).

Features & Implementation

  • Core Locale Configuration (src/locales/ar/):
    • Weekdays: Sunday through Saturday (الأحد to السبت).
    • Dual Month Dictionaries:
      • Standard Gregorian: يناير, فبراير, مارس, أبريل, مايو, يونيو, يوليو, أغسطس, سبتمبر, أكتوبر, نوفمبر, ديسمبر.
      • Levantine & Mesopotamian Gregorian: كانون الثاني, شباط, آذار, نيسان, أيار, حزيران, تموز, آب, أيلول, تشرين الأول, تشرين الثاني, كانون الأول.
    • Dual Forms (المثنى): Support for 2 units without explicit numbers (يومين/يومان, ساعتين/ساعتان, أسبوعين/أسبوعان, شهرين/شهران, سنتين/عامين).
    • Numeral Support: Built-in support and normalization for both Western digits (0-9) and Eastern Arabic numerals (٠-٩).
    • Unicode Boundaries: RegEx boundary matching using \p{L} and \p{N} with iu flags to properly detect Arabic word boundaries.
  • Parsers & Refiners:
    • ARCasualDateParser: اليوم, غداً, غدا, بعد غد, أمس, أول أمس, الآن.
    • ARCasualTimeParser: هذا الصباح, الظهر, بعد الظهر, عصراً, هذا المساء, منتصف الليل.
    • ARWeekdayParser: Modified and standalone weekdays (الجمعة القادم, الخميس الماضي, هذا الأحد, يوم ...).
    • ARMonthNameLittleEndianParser: Expressions like 15 يناير 2023, ١٥ كانون الثاني ٢٠٢٣, 15 من مارس, and date ranges with 1 <= day <= 31 bounds validation.
    • ARMonthNameParser: Month + Year (يناير 2025, شهر مارس) with preceding day-number collision rejection.
    • ARTimeExpressionParser: Clock times (الساعة 5:30 مساءً, 8:00 ص, في تمام 6:00), Eastern numerals (الساعة ٥:٣٠ مساءً), and ranges (من 2:00 إلى 4:00 مساءً).
    • ARTimeUnitAgoFormatParser, ARTimeUnitLaterFormatParser, ARTimeUnitWithinFormatParser: Relative durations (منذ 3 أيام, قبل ساعتين, بعد يومين, خلال 3 ساعات).
    • ARRelativeDateFormatParser: الشهر القادم, الأسبوع الماضي, السنة القادمة.
    • ARMergeDateTimeRefiner & ARMergeDateRangeRefiner: Merges date and time expressions and date ranges.
  • Exports & Documentation:
    • Exposed chrono.ar with casual, strict, parse, and parseDate in src/locales/ar/index.ts and src/index.ts.
    • Updated README.md in both language lists (lines 40 and 226).

Testing

  • Added comprehensive unit tests in test/ar/:
    • ar_casual.test.ts: Casual dates and times, shortcuts, and strict mode.
    • ar_weekday.test.ts: Standalone and modified weekdays.
    • ar_month.test.ts: Standard and Levantine month dates, Eastern Arabic numerals, and ranges.
    • ar_time_exp.test.ts: Time expressions, AM/PM, and time ranges.
    • ar_time_units.test.ts: Past/future/within durations and dual forms.
    • ar_negative_cases.test.ts: False positive checks against phone numbers, currencies, bare numbers, percentages, and impossible dates.
  • All 6 Arabic test suites (22 tests) pass.
  • Verified zero regressions across the entire test suite (151 test suites, 688 total tests).

@MohmeedSalah

Copy link
Copy Markdown

good job

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants