Created
April 22, 2015 14:26
-
-
Save ningunaparte/9d67f051e3f7fedf4e20 to your computer and use it in GitHub Desktop.
How to format D3.js dates and numbers to spanish - Localizar al español fechas y números
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.5/d3.js | |
// SAMPLE https://jsfiddle.net/ningunaparte/9gm68vmn/ | |
var nowDate = new Date(); | |
// ES LOCATION | |
// d3.locale Spanish Spain / Español | |
// https://github.com/mbostock/d3/wiki/Localization | |
var es_ES = { | |
"decimal": ",", | |
"thousands": ".", | |
"grouping": [3], | |
"currency": ["€", ""], | |
"dateTime": "%a %b %e %X %Y", | |
"date": "%d/%m/%Y", | |
"time": "%H:%M:%S", | |
"periods": ["AM", "PM"], | |
"days": ["Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado"], | |
"shortDays": ["Dom", "Lun", "Mar", "Mi", "Jue", "Vie", "Sab"], | |
"months": ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"], | |
"shortMonths": ["Ene", "Feb", "Mar", "Abr", "May", "Jun", "Jul", "Ago", "Sep", "Oct", "Nov", "Dic"] | |
}; | |
var ES = d3.locale(es_ES); | |
// PARAMS AVAILABLE https://github.com/mbostock/d3/wiki/Time-Formatting | |
var myDefaultFormat = d3.time.format("%A %d, %H:%M"); | |
var mySampleFormat = ES.timeFormat("%A %d, %H:%M"); | |
var mySampleNumber = 155624.55; | |
var strings = [nowDate, myDefaultFormat(nowDate), mySampleFormat(nowDate), ES.numberFormat(",.")(mySampleNumber)] | |
d3.select("body").append('ul').selectAll('li') | |
.data(strings) | |
.enter().append('li') | |
.text(function(d) { | |
return d; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment