Skip to content

Add Arabic (ar) locale - #1111

Open
moamen-ui wants to merge 1 commit into
python-pendulum:masterfrom
moamen-ui:add-arabic-locale
Open

moamen-ui wants to merge 1 commit into
python-pendulum:masterfrom
moamen-ui:add-arabic-locale

Conversation

@moamen-ui

Copy link
Copy Markdown

Adds an Arabic (ar) locale under src/pendulum/locales/ar/, following the most recent additions (gu in #963, hi in #902): same file layout, same locale/custom structure, and a test module in tests/localization/test_ar.py.

What is in it:

  • Modern Standard Arabic weekday and month names (wide, abbreviated, short, narrow), using CLDR spelling.
  • Unit names and relative phrases for diff_for_humans (منذ for past, خلال for future), and بعد / قبل for comparisons between two dates, plus "بضع ثوانٍ" for a few seconds.
  • Day periods (ص / م) and date formats (L, LL, LLL, LLLL, LT, LTS).
  • A six-form plural rule (zero, one, two, few, many, other) that follows the CLDR Arabic rules for integers. Every unit has all six forms, so counts such as 2 (يومان), 3-10 (أيام), 11-99 (يومًا) and 100+ are each handled.
  • Week data: first day Saturday and weekend Friday-Saturday, which matches CLDR ar-EG. Tell me if you prefer the Sunday-first ar-SA convention.

Not included:

  • Ordinals: Arabic has no ordinal suffix, so ordinal returns other and no custom.ordinal is set (same as gu and hi).
  • Regional tags such as ar-SA or ar_EG raise Locale [ar_sa] does not exist., the same as the existing he-IL and de-CH. This is pre-existing loader behaviour and is not changed here.
  • No docs change: the localization page has no list of locales.

Output samples (real runs on this branch, Python 3.12, pure-Python path):

>>> now.subtract(seconds=1).diff_for_humans(locale="ar")   -> منذ بضع ثوانٍ
>>> now.subtract(seconds=30).diff_for_humans(locale="ar")  -> منذ 30 ثانية
>>> now.subtract(minutes=2).diff_for_humans(locale="ar")   -> منذ دقيقتين
>>> now.subtract(hours=5).diff_for_humans(locale="ar")     -> منذ 5 ساعات
>>> now.subtract(days=3).diff_for_humans(locale="ar")      -> منذ 3 أيام
>>> now.subtract(years=2).diff_for_humans(locale="ar")     -> منذ سنتين
>>> now.add(hours=3).diff_for_humans(locale="ar")          -> خلال 3 ساعات
>>> b.diff_for_humans(a, locale="ar")  (b = a + 3 hours)   -> بعد 3 ساعات
>>> Duration(years=11).in_words(locale="ar")               -> 11 سنة
>>> Duration(years=100).in_words(locale="ar")              -> 100 سنة
>>> Duration(days=2).in_words(locale="ar")                 -> يومان
>>> pendulum.datetime(2016, 8, 29, 15, 3, 6).format("LLLL", locale="ar")
                                                           -> الاثنين، 29 أغسطس 2016، 3:03 م
>>> ... .format("LT", locale="ar")                         -> 3:03 م

An AI tool helped with the locale data and the tests, and a second AI review of the Arabic strings found two wording issues (narrow month letters and the "few" form of microseconds), which were fixed. I am an Arabic speaker, but a native review is welcome, especially for the unit phrases and the plural forms.

Checks:

  • Passed: pytest tests (1873 passed; the new locale tests pass), ruff check and ruff format --check on the new files, mypy (strict, full project, 232 files).
  • Pre-existing and unrelated: tests/test_main.py::test_instance_with_aware_datetime_any_tzinfo fails on an unmodified master in this environment (timezone-dependent, Europe/Paris vs +02:00). It is not touched by this PR.

Not run or not verified:

  • The Rust extension build path (only the pure-Python path was run).
  • Codex review was unavailable (usage limit). The Arabic strings were reviewed by a fresh independent AI reviewer instead.
  • No native speaker has reviewed the strings yet.

This PR is part of Taareeb, an open project for Arabic localization of open source software: https://github.com/moamen-ui/taareeb

Adds src/pendulum/locales/ar with Modern Standard Arabic names, relative
and duration phrases, day periods and date formats, plus a six-form plural
rule (zero, one, two, few, many, other) following the CLDR Arabic rules.
Tests cover diff_for_humans, in_words, format and the plural forms.

Signed-off-by: Moamen Abdulraouf Mansour <moamen.ui@gmail.com>
moamen-ui added a commit to moamen-ui/taareeb that referenced this pull request Dec 5, 2026

This branch has not been deployed

No deployments
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.

1 participant