set locale object
isaacs opened this issue · comments
It'd be nice if this had support for passing in a locale object, so that you could print the date using different languages and whatnot.
Just pushed a first stab at this to the loc branch. Here's an example of the API: https://gist.github.com/852901
How does that look?
That's pretty rad :)
My first instinct would've been to go with passing in an object of the various things, like:
strftime("%blah", new Date(),
{ days: ["domenica","lundi",...]
, months: ["genniao", ...]
})
but just providing a translation function seems kind of simple.
It'd be nice if I could provide a translation object, and then have the loc
function generated to do function localize (x) { return locale[x] || x }
.
Also, it'd be cool if there was a way to also override some of the "default" type formats. For example, I might do strftime("%D") to get the date, but want that to be "%m/%d/%Y"
in America, "%d/%m/%Y"
in Europe, and "%Y-%m-%d"
in Asia. I'm not sure what the ideal API for that would be. Maybe you could have something like this:
strftime(str, date,
{ days: ["domenica",...] // if unspecified, use english
, months: ["genniao", ...] // if unspecified, use english
, formats: // these would inherit from the "default" american styles
{ "D": "%Y-%m-%d" }})
My thinking at the time was that by making it a function it could by dynamic but that's probably not important, can't think of a use right now... YAGNI. Objects it is.
I like the idea of localizing formats too. I'll pull something together.
Untested but here it is: https://github.com/samsonjs/strftime/blob/loc/lib/index.js
Not sure if you're using this or not but I polished it up, merged to master, and published to npm. Let me know if there are any problems with it.