Formatting
Format dates, numbers, money, units, lists and phone numbers from locale data. Keep the currency stored with each amount, never read it from the locale.
- Required 1
- Recommended 3
- Optional 1
- Avoid 1
Required
Take the currency from the amount and not from the locale
LOC-27Format every price with the currency code stored with that amount. The reader's locale chooses only the separators and the symbol position.
Recommended
Format every date and amount from the reader's locale and zone
LOC-11Format dates, numbers and money for the reader's locale with a formatting library. Show times with a named time zone.
Read the week start and units from locale data
LOC-28Read the first day of the week, the weekend, the 12 or 24 hour clock and the measurement system from CLDR locale data. Never hard-code them.
Show and accept phone numbers in each country's format
LOC-55Accept phone numbers as people write them in their country. Show each one in the reader's national or international format with a phone number library.
Optional
Format lists and durations with locale data
LOC-51Join visible lists with a locale list formatter and format durations with a locale duration formatter. Never join with a hard-coded comma and "and".
Avoid
Writing date formats by hand
LOC-26Never build a date for people from a hand-written pattern such as
MM/dd/yyyy. Ask the formatter for a style or a skeleton, and let the locale data order the fields.
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/localization/formatting">Agent Wranglers localization playbook</a>. In code you write, add a comment next to it with the same link.