Abdulkader Safi

LaralCN-UI date picker: Arabic month names, Western digits

The LaralCN-UI date picker is a calendar popover that reads month and weekday names from the browser in whatever language the page is in, and always submits Y-m-d. Getting the label right before JavaScript runs meant formatting dates in PHP with the same pattern the browser uses.

5 min read

Share
The LaralCN-UI date picker on the Arabic docs page, showing an Arabic month title and a selected date range in a right-to-left calendar.

The new date-picker component is an input-style button that opens a calendar. It handles a single date or a range within optional min and max limits, and every part of it works from the keyboard. The month and weekday names come from the browser's Intl API in the language of the page, so the Arabic docs show Arabic names with no setup, while the value the form submits stays a plain 2026-12-01.

Let the browser translate the calendar

A date picker usually ships twelve month names and seven day names per language, or pulls in a date library that does. I did not want either in a copy-and-own Blade file. Every browser already has Intl.DateTimeFormat, so the script asks it for each label in the page's language:

function formatter(root, options) {
    var tag = root.dataset.locale || document.documentElement.lang || undefined;
    try {
        return new Intl.DateTimeFormat(tag, options);
    } catch (e) {
        return new Intl.DateTimeFormat(undefined, options);
    }
}

The title uses { month: 'long', year: 'numeric' }, the column headers use weekday: 'narrow' with the long name in the abbr attribute, and each day button gets dateStyle: 'full' as its aria-label. Because the docs set <html lang="ar"> under /ar, the calendar there reads in Arabic without a single string in lang/ar.json. A locale prop overrides the page language, and week-starts-on takes 0 to 6 for regions where the week starts on Monday or Saturday.

One thing surprised me while testing. With lang="ar", Chrome renders the day numbers in Western digits. With ar-EG, it switches to Arabic-Indic digits. Both are correct for their locale, so the component leaves that choice to whoever sets lang.

The value never gets translated

Whatever the calendar shows, the hidden input gets a date string built by hand from the numeric parts of the date:

// Always Western digits: this is what the form submits.
function iso(date) {
    return date.getFullYear() + '-' +
        String(date.getMonth() + 1).padStart(2, '0') + '-' +
        String(date.getDate()).padStart(2, '0');
}

Laravel's date validation rule and Carbon both read that format directly. A range is still one input: mode="range" submits 2026-12-01,2026-12-07. I went back and forth on two inputs versus one. One won because wire:model and x-model bind to a single element, and splitting the string in a controller is one line.

Like the combobox, the value sits in a hidden input, and a hidden input fires no events on its own. After each pick the script dispatches bubbling input and change events, which is what Livewire and Alpine listen for. id and aria-* attributes go to the visible trigger so <label for> and aria-invalid work; everything else, including wire:model, lands on the hidden input.

A label that is right before the script runs

If only JavaScript rendered the trigger label, a slow page would flash the placeholder text, or the raw 2026-12-01, before the script replaced it. So the server formats the label first, using PHP's intl extension with the same skeleton the script uses (year, short month, day):

$pattern = (new \IntlDatePatternGenerator($labelLocale))->getBestPattern('yMMMd');

return (new \IntlDateFormatter($labelLocale, \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, null, null, $pattern))->format($date);

IntlDatePatternGenerator picks the right order for the locale, so English gets "Dec 1, 2026" and Arabic gets its own arrangement. If the intl extension is missing, the label falls back to Y-m-d.

This raised the one open question in the component. To pick the server-side locale it calls app()->getLocale(), guarded with function_exists('app'). The authoring rules say the only outside symbol a component may use is TailwindMerge, and this is now the single exception in the registry. I kept it because a wrong first label is worse than a bent rule, but it is written down as a known limit in PR #7 in case a cleaner option turns up.

Keyboard, including right to left

The grid follows the ARIA date grid pattern. Arrow keys move by one day sideways and one week up or down. PageUp and PageDown move a month, Shift with PageUp or PageDown moves a year, and Home and End jump to the start or end of the week. Enter and Space need no code because each day is a real <button>.

In a right-to-left page the week runs from right to left, so ArrowRight has to go back a day. The script checks the computed direction rather than the dir attribute, which also covers a picker inside a dir="rtl" container on an English page:

var step = getComputedStyle(root).direction === 'rtl' ? -1 : 1;

The month arrows use rtl:rotate-180, the popover anchors with start-0, and the grid always renders six rows so the popover never changes height between months.

Known limits

required lands on the hidden input, and browsers never validate hidden inputs, so validate on the server. And if Livewire writes a new value into the input from outside, the trigger label updates on the next re-render rather than instantly.

Where it is

composer require --dev safi/laralcn-ui
php artisan ui:init
php artisan ui:add date-picker

Docs and demos are at https://laralcn-ui.abdulkadersafi.com/components/date-picker, and the Arabic version at https://laralcn-ui.abdulkadersafi.com/ar/components/date-picker. Source: https://github.com/Abdulkader-Safi/LaralCN-UI. MIT licensed.

Next: the file upload dropzone, and why the native file input stays the field that submits.

Last updated 1 Dec 2026 · filed under Laravel, blade, javascript, laralcn-ui, rtl

Every entry on this project

26 build notes, in order

Including the ones where nothing worked. You are on part 16.

Read the series →

FAQ

Frequently asked questions

What format does the date picker submit?

Always Y-m-d in Western digits, whatever language the calendar shows. A range submits one value, start,end, so split it on the comma in your controller.

How do I get Arabic or French month names?

Set lang on your <html> tag, or pass locale="fr" to the component. The names come from the browser's Intl API, so there are no translation files to add.

Does it work with Livewire?

Yes. wire:model="dueAt" lands on the hidden input, and the component fires input and change events after every pick.

Why does required not stop the form from submitting?

The value lives in a hidden input, and browsers skip hidden inputs during validation. Use Laravel's required|date rule on the server.

Written by

Abdulkader Safi

Software Engineer

Lead engineer at DSRPT, from Lebanon and based in Kuwait. I write about the tools and bugs from real client work, with the numbers I measured.

About me → GitHub LinkedIn

Need this kind of work done on your project?

Start a project →

Keep reading

More from LaralCN-UI: shadcn-style Blade components and blocks you own

All 26 entries →