The post has been translated automatically. Original language: Russian
The main audience of one of our projects speaks Haitian Creole (language code "ht"). When the frontend switched to server rendering (SSR) on React, we received a stream of hydration errors. (#418, #422, #425) — and almost everything is on the date and time pages.
Reason. There is no Creole in the ICU library data, which relies on the Intl in browsers and Node.js . At the same time, new Intl.DateTimeFormat('ht') does not give an error, but silently rolls back to the environment locale. This is one locale on the server, and another on the user's phone. The same time is formatted in different ways, most often with a different clock format (12 or 24 hours). The server markup does not match the client's markup, and React reports a hydration error each time.
Decision.
- Do not transfer "ht" to the Intl directly. We use fr-FR to format dates and numbers: Haiti has adopted the French rules for writing dates and the 24-hour format.
- We translate the names of the months and days of the week in Creole separately, according to our own dictionary, and not using the Intl.
- We format the time on the server and the client in the same explicitly specified time zone.
Result. In this locale, error #418 was reduced by 76%, and error #422 by 93%.
Conclusion for those who make products in rare languages: check if your locale is in ICU (Intl.DateTimeFormat.supportedLocalesOf(['ht']) returns an empty array). If not, don't rely on silent rollback and set the formatting explicitly.
Основная аудитория одного из наших проектов говорит на гаитянском креольском (код языка «ht»). При переходе фронтенда на серверный рендеринг (SSR) на React мы получили поток ошибок гидратации (#418, #422, #425) — и почти все на страницах с датами и временем.
Причина. Креольского нет в данных ICU — библиотеки, на которую опирается Intl в браузерах и Node.js. При этом new Intl.DateTimeFormat('ht') не выдаёт ошибку, а молча откатывается на локаль окружения. На сервере это одна локаль, на телефоне пользователя — другая. Одно и то же время форматируется по-разному, чаще всего разным форматом часов (12 или 24 часа). Разметка сервера не совпадает с разметкой клиента, и React каждый раз сообщает об ошибке гидратации.
Решение.
- Не передавать «ht» в Intl напрямую. Для форматирования дат и чисел мы используем fr-FR: в Гаити приняты французские правила записи дат и 24-часовой формат.
- Названия месяцев и дней недели на креольском переводим отдельно, по своему словарю, а не через Intl.
- Время на сервере и клиенте форматируем в одном явно заданном часовом поясе.
Результат. На этой локали ошибка #418 сократилась на 76 %, #422 — на 93 %.
Вывод для тех, кто делает продукт на редкие языки: проверьте, есть ли ваша локаль в ICU (Intl.DateTimeFormat.supportedLocalesOf(['ht']) вернёт пустой массив). Если нет — не полагайтесь на молчаливый откат и задайте форматирование явно.
Comments 0
Newest Popular