API Reference ▸ Core ▸ Localization
The formatting of numbers, dates and currencies varies by language and locale. While the default build of D3 is intended for U.S. English, you can change the behavior of D3’s formatters by loading new locales as needed.
Returns a new locale given the specified definition. The locale definition must include the following properties for number formatting:
"."
).","
).[3]
), cycled as needed.["$", ""]
).(Note that the thousands property is a slight misnomer, as the grouping definition allows groups other than thousands.)
The locale definition must also include the following properties for time formatting:
"%a %b %e %X %Y")
."%m/%d/%Y"
)."%H:%M:%S"
).["AM", "PM"]
).For example, the default U.S. English (en_US) locale is defined as:
{ "decimal": ".", "thousands": ",", "grouping": [3], "currency": ["$", ""], "dateTime": "%a %b %e %X %Y", "date": "%m/%d/%Y", "time": "%H:%M:%S", "periods": ["AM", "PM"], "days": ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"], "shortDays": ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"], "months": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], "shortMonths": ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"] }
A locale for Russian (ru_RU) might be defined as:
{ "decimal": ",", "thousands": "\u00A0", "grouping": [3], "currency": ["", " руб."], "dateTime": "%A, %e %B %Y г. %X", "date": "%d.%m.%Y", "time": "%H:%M:%S", "periods": ["AM", "PM"], "days": ["воскресенье", "понедельник", "вторник", "среда", "четверг", "пятница", "суббота"], "shortDays": ["вс", "пн", "вт", "ср", "чт", "пт", "сб"], "months": ["января", "февраля", "марта", "апреля", "мая", "июня", "июля", "августа", "сентября", "октября", "ноября", "декабря"], "shortMonths": ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"] }
The locale’s equivalent of d3.format.
The locale’s equivalent of d3.time.format.
The locale’s equivalent of d3.time.format.utc.
© 2010–2016 Michael Bostock
Licensed under the BSD License.
https://github.com/d3/d3-3.x-api-reference/blob/master/Localization.md