Skip to content

Instantly share code, notes, and snippets.

@nl-hugo
Last active July 30, 2018 13:36
Show Gist options
  • Save nl-hugo/7f86f88665dfc07a0f2f8bd3da312b4f to your computer and use it in GitHub Desktop.
Save nl-hugo/7f86f88665dfc07a0f2f8bd3da312b4f to your computer and use it in GitHub Desktop.
Simple localization example
height: 100
license: MIT

Simple localization example.

<!DOCTYPE html>
<meta charset="utf-8">
<style>
body {
font-size: 18px;
font-family: sans-serif;
fill: #777;
}
</style>
<body>
<svg width="400" height="100"></svg>
</body>
<script src="https://d3js.org/d3.v4.min.js"></script>
<script>
var svg = d3.select("svg"),
margin = {top: 50, right: 20, bottom: 30, left: 20},
width = +svg.attr("width") - margin.left - margin.right,
height = +svg.attr("height") - margin.top - margin.bottom,
g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
d3.json("https://unpkg.com/d3-time-format@2/locale/nl-NL.json", function(error, locale) {
if (error) throw error;
d3.timeFormatDefaultLocale(locale);
var format = d3.timeFormat("%A %d %B %Y, %X");
// console.log(format(new Date));
g.append("text").text("Now is: " + format(new Date()));
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment