Wielojęzyczność
i18n/explicit-locale
Intl formatters and toLocale*String() receive the app's active locale instead of relying on the runtime default.
drobnastatycznefe-i18n
Dlaczego
Without a locale, formatting follows the browser or server default. A Polish page then shows English dates to a visitor with an English browser, and server rendering (often en-US in a container) produces text that differs from the client, which causes hydration mismatches.
Poprawka
Pass the locale the app uses for its messages (from the router, the i18n library or <html lang>), and set timeZone explicitly when rendering dates on the server.
Przykłady
// bad
date.toLocaleDateString()
// good
date.toLocaleDateString(locale, { dateStyle: 'long', timeZone })Źródła
Fakty
- Identyfikator
i18n/explicit-locale- Waga
- drobna
- Sprawdzanie
- statyczne sprawdzane w kodzie źródłowym przez
audit - Dotyczy plików
jsxvuesvelteastrohtml- Uczy jej skill
fe-i18nInternationalisation- Od wersji
- 0.1.0
Przeczytaj w terminalu
npx github:dawidolko/frontend-skills explain i18n/explicit-locale