Beta Preview

Improving Internationalization Support in Our Date and Time Components

By Yihui Liao ·

Internationalization is a core feature of our Date and Time components. We support 13 different calendar systems as well as locale-specific formatting, number systems, and 12 and 24 hour time. However, we identified an issue in our support for several right-to-left (RTL) languages where in some, the format of the date and time fields was incorrect. While investigating this bug, we faced several challenges in ensuring accurate date and time representation in RTL languages and implemented various strategies that we'd like to share.

The Structure of Our Date and Time Components

In a previous blog post, we discussed the reasoning behind the component structure of our date and time components. In short, we designed these components to render individually focusable segments for each date and time unit, eliminating the challenges of parsing various date formats — an issue commonly encountered with free-form text fields. Since the date and time format is automatically determined based on the user's locale, the user only needs to fill in the values without worrying about the appropriate separators or the order. This made for a smoother, more intuitive experience for the user, removing the guesswork associated with formatting and parsing dates in various locales.

Unicode Bidirectional Algorithm

To format the segments according to the user locale, we relied on the Intl.DateTimeFormat API to help localize our dates and flexbox to handle the layout. Flexbox conveniently handled the right-to-left layouts by mirroring the segment order provided by the API which typically works well for RTL languages. However, in some cases, it is more complex. RTL languages often have bidirectional text, meaning it contains a mix of right-to-left and left-to-right elements. For example, in Arabic and Hebrew, numbers are always written from left-to-right. In cases where numbers are combined with text, the general flow proceeds right to left, but the numbers are written from left to right.

We found that dates behave bidirectionally in right-to-left languages and just mirroring the segment order was too simplistic for this complex behavior. As a result, some of our date fields were formatted incorrectly. For instance, in Hebrew (he-IL), the proper numeric date format should be DD.MM.YYYY, but our date component was displaying YYYY.MM.DD. This issue varied across different RTL languages for date fields, but for time fields, we observed a consistent problem across all RTL languages where time segments were flipped, rendering MM:HH instead of the correct HH:MM format.

Incorrect (he-IL)Start Date45:8 , 2025.1.31Start Date8:45 , 31.1.2025Correct (he-IL) Date۸:۴۵ , ۱۳۹۹/۱۲/۲۴With actual values (fa-AF)With placeholder values (fa-AF)Date—:— , روز/ماه/سالHour:Minute Year/Month/DayMinute:Hour Day/Month/Year