Where can in find the locale objects for d3.js for different countries

旧城冷巷雨未停 提交于 2019-12-24 01:15:22

问题


this url (https://github.com/mbostock/d3/wiki/Localization) shows two examples for locales

en_US:
    {
    "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"]
    }

and

ru_RU:
{
"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": ["янв", "фев", "мар", "апр", "май", "июн", "июл", "авг", "сен", "окт", "ноя", "дек"]
 }

where can i find all the countries objects?

I am not able to find anything relevant on the page.

Help please.


回答1:


D3 does not load any localization strings, it creates a new object that handles the localization via d3.locale method. In the D3 source, there are some pre-made definitions; you can find them at:

  • https://github.com/d3/d3-format/tree/master/locale
  • https://github.com/d3/d3-time-format/tree/master/locale

When you want to use the format of another locale than en-US, this is an example for you:

var esLocaleDef = {...}; // your definition, you can copy from es-Es.js file in the above folder.
var esLocale = d3.locale(esLocaleDef);

// use esLocale.numberFormat instead of d3.format
var esNumberFormat = esLocale.numberFormat(...);

// use esLocale.timeFormat instead of d3.time.format
var esTimeFormat = esLocale.timeFormat(...);


来源:https://stackoverflow.com/questions/35451234/where-can-in-find-the-locale-objects-for-d3-js-for-different-countries

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!