Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow static localization of d3.time.format. #753

Closed
wants to merge 2 commits into from

Conversation

mbostock
Copy link
Member

@mbostock mbostock commented Aug 7, 2012

You can now build a locale-specific version of d3.time.format. For example,

LOCALE=fr_FR make

will pull strings from the time/format-fr_FR.js file, rather than en_US.

You can now build a locale-specific version of d3.time.format. For example,

  LANG=fr_FR make

will pull strings from the time/format-fr_FR.js file, rather than en_US.
@rodionos
Copy link

rodionos commented Aug 8, 2012

Mike,

In en_US: substring(0, 3).toLowerCase() works.

d3_time_weekdays = [ "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" ]
d3_time_weekdayAbbrevRe = /^(?:sun|mon|tue|wed|thu|fri|sat)/i

In ru_RU: substring doesn't work as the abbreviated weekday is based on the first two consonants.

d3_time_weekdays = [ "Voskresenie", "Ponedelnik", "Vtornik", "Sreda", "Chetverg", "Pyatnitsa", "Subbota" ]
d3_time_weekdayAbbrevRe = /^(?:vs|pn|vt|sr|ct|pt|sb)/i

Which is why 'Remove duplicate locale specification.' commit break things.
The 2 letter codes can be padded to 3 letters as specified in the locale specification file.

P.S. I'm using a transliterated Cyrillic to illustrate the issue.

Thanks,

Sergei

@mbostock
Copy link
Member Author

mbostock commented Aug 8, 2012

It was already the case in the previous version that the abbreviations had to be three characters long; see the substring call in time/format.js.

I think it would be possible to rewrite the code to allow arbitrary abbreviations. Trying to decide whether I should require the length of the abbreviations to be identical or allow variable length.

@mbostock
Copy link
Member Author

mbostock commented Aug 9, 2012

Merged into #756; staged for 2.10.0.

@mbostock mbostock closed this Aug 9, 2012
@mbostock
Copy link
Member Author

mbostock commented Aug 9, 2012

I think I've fixed this in 3d4d679. I've also added a locale file for ru_RU, but I don't speak Russian so feel free to correct it if I made any typos!

@rodionos
Copy link

Hello Mike,

Another suggested fix to make the default d3 scale more useful is 24-hour format instead 12 hour (AM/PM) format.
Reason being is that 12 hour format is used only in small set of countries.
The following changes need to be introduced into scale.js and scale-utc.js:

scale.js - var d3_time_scaleLocalFormats = [
OLD
[d3.time.format("%I %p"), function(d) { return d.getHours(); }],
[d3.time.format("%I:%M"), function(d) { return d.getMinutes(); }],

NEW
[d3.time.format("%H"), function(d) { return d.getHours(); }],
[d3.time.format("%H:%M"), function(d) { return d.getMinutes(); }],

scale-utc.js - var d3_time_scaleUTCFormats = [
OLD
[d3.time.format.utc("%I %p"), function(d) { return d.getUTCHours(); }],
[d3.time.format.utc("%I:%M"), function(d) { return d.getUTCMinutes(); }],

NEW
[d3.time.format.utc("%H"), function(d) { return d.getUTCHours(); }],
[d3.time.format.utc("%H:%M"), function(d) { return d.getUTCMinutes(); }],

Could you please add a 12/24 switch into the build file?
Alternatively, it would be nice to be able to switch formats at runtime.

Thanks,

Sergei

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants