diff --git a/HISTORY.md b/HISTORY.md index bb8cc623..57311976 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -9,6 +9,7 @@ http://visjs.org - Fixed the `change` event sometimes being fired twice on IE10. - Fixed canceling moving an item to another group did not move the item back to the original group. +- Added localization support. ### Network @@ -21,7 +22,7 @@ http://visjs.org - Added 'allowOverlap' option for barCharts. - Added two examples showing the two additions above. - Added 'customRange' for the Y axis and an example showing how it works. - +- Added localization support. ## 2014-08-14, version 3.2.0 diff --git a/docs/graph2d.html b/docs/graph2d.html index f2657c65..f7c2bf24 100644 --- a/docs/graph2d.html +++ b/docs/graph2d.html @@ -48,6 +48,8 @@
  • Methods
  • Events
  • +
  • Localization
  • +
  • Styles
  • Data Policy
  • @@ -91,7 +93,7 @@ start: '2014-06-10', end: '2014-06-18' }; - var graph2d = new vis.Graph2d(container, dataset, options); + var Graph2d = new vis.Graph2d(container, dataset, options); </script> </body> </html> @@ -278,13 +280,13 @@ groups.add({ slots.slot Number - The slot the bar chart is plotted in. This has to be used in combination with slots.total. See example 11 for more information. + The slot the bar chart is plotted in. This has to be used in combination with slots.total. See example 11 for more information. slots.total Number - The total amount of slots available. This has to be used in combination with slots.slot. See example 11 for more information. + The total amount of slots available. This has to be used in combination with slots.slot. See example 11 for more information. @@ -316,7 +318,7 @@ The options colored in green can also be used as options for the groups. All opt yAxisOrientation String 'left' - This defines with which axis, left or right, the graph is coupled. Example 5 shows groups with different Y axis. If no groups are coupled + This defines with which axis, left or right, the graph is coupled. Example 5 shows groups with different Y axis. If no groups are coupled with an axis, it will not be shown. @@ -336,7 +338,7 @@ The options colored in green can also be used as options for the groups. All opt sampling Boolean true - If sampling is enabled, graph2D will automatically determine the amount of points per pixel. + If sampling is enabled, Graph2d will automatically determine the amount of points per pixel. If there are more than 1 point per pixel, not all points will be drawn. Disabling sampling will cause a decrease in performance. @@ -388,8 +390,8 @@ The options colored in green can also be used as options for the groups. All opt Boolean true When true, bars that have the same x coordinate are plotted on top of eachother (not stacking). - See example 10 for more information. - When using groups, see example 11. + See example 10 for more information. + When using groups, see example 11. @@ -408,7 +410,7 @@ The options colored in green can also be used as options for the groups. All opt catmullRom.parametrization String 'centripetal' - Define the type of parametrizaion. Example 7 shows the different methods. The options are 'centripetal' (best results), 'chordal' and 'uniform'. Uniform is the computationally cheapest variant. + Define the type of parametrizaion. Example 7 shows the different methods. The options are 'centripetal' (best results), 'chordal' and 'uniform'. Uniform is the computationally cheapest variant. If catmullRom is disabled, linear interpolation is used. @@ -512,7 +514,7 @@ The options colored in green can also be used as options for the groups. All opt

    Timeline Options

    - Graph2d is built upon the framework of the timeline. These options from the timeline can be used with graph2D. + Graph2d is built upon the framework of the timeline. These options from the timeline can be used with Graph2d. All options are optional.

    @@ -917,16 +919,72 @@ Graph2d.off('rangechanged', onChange); +

    Localization

    +

    + Graph2d can be localized. For localization, Graph2d depends largely on the localization of moment.js. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales. +

    + +

    + To set a locale for the Graph2d, specify the option locale: +

    + +
    var options = {
    +  locale: 'nl'
    +};
    +
    + +

    Create a new locale

    + +To load a locale into the Graph2d not supported by default, one can add a new locale to the option locales: + +
    var options = {
    +  locales: {
    +    // create a new locale
    +    mylocale: {
    +      current: 'current',
    +      time: 'time',
    +    }
    +  },
    +
    +  // use the new locale
    +  locale: 'mylocale'
    +};
    +
    + +

    Available locales

    + +Graph2d comes with support for the following locales: + + + + + + + + + + + +
    LanguageCode
    English + en
    + en_EN
    + en_US +
    Dutch + nl
    + nl_NL
    + nl_BE +
    +

    Styles

    - All parts of the Graph2d have a class name and a default css style just like the Timeline. + All parts of the Graph2d have a class name and a default css style just like the Graph2d. The styles can be overwritten, which enables full customization of the layout of the Graph2d.

    Additionally, Graph2d has 10 preset styles for graphs, which are cycled through when loading groups. These styles can be overwritten - as well, along with defining your own classes to style the graphs! Example 4 and - example 5 show the usage of custom styles. + as well, along with defining your own classes to style the graphs! Example 4 and + example 5 show the usage of custom styles.

    Data Policy

    diff --git a/docs/timeline.html b/docs/timeline.html index a99bfdf2..fdba8c52 100644 --- a/docs/timeline.html +++ b/docs/timeline.html @@ -43,6 +43,7 @@
  • Methods
  • Events
  • Editing Items
  • +
  • Localization
  • Styles
  • Data Policy
  • @@ -438,6 +439,20 @@ var options = { + + locale + String + none + Select a locale for the Timeline. See section Localization for more information. + + + + locales + Object + none + A map with i18n locales. See section Localization for more information. + + margin.axis Number @@ -985,11 +1000,67 @@ var options = { callback(null); // cancel updating the item } } -} +}; A full example is available here: 08_edit_items.html. +

    Localization

    +

    + Timeline can be localized. For localization, Timeline depends largely on the localization of moment.js. Locales are not included in vis.js by default. To enable localization, moment.js must be loaded with locales. Moment.js offers a bundle named "moment-with-locales.min.js" for this and there are various alternative ways to load locales. +

    + +

    + To set a locale for the Timeline, specify the option locale: +

    + +
    var options = {
    +  locale: 'nl'
    +};
    +
    + +

    Create a new locale

    + +To load a locale into the Timeline not supported by default, one can add a new locale to the option locales: + +
    var options = {
    +  locales: {
    +    // create a new locale
    +    mylocale: {
    +      current: 'current',
    +      time: 'time',
    +    }
    +  },
    +
    +  // use the new locale
    +  locale: 'mylocale'
    +};
    +
    + +

    Available locales

    + +Timeline comes with support for the following locales: + + + + + + + + + + + +
    LanguageCode
    English + en
    + en_EN
    + en_US +
    Dutch + nl
    + nl_NL
    + nl_BE +
    +

    Styles

    @@ -1008,7 +1079,6 @@ A full example is available here: Data Policy

    All code and data is processed and rendered in the browser. diff --git a/examples/graph2d/01_basic.html b/examples/graph2d/01_basic.html index 45619ca0..f878d25c 100644 --- a/examples/graph2d/01_basic.html +++ b/examples/graph2d/01_basic.html @@ -2,8 +2,8 @@ - - + + Graph2d | Basic Example + + + + + + +

    Graph2d | Localization

    +

    + To localize Graph2d, one has to load a version of moment.js including locales. To set a locale, specify option {locale: STRING}. +

    + +

    + + +

    + +
    + + + + \ No newline at end of file diff --git a/examples/graph2d/index.html b/examples/graph2d/index.html index c0fc098b..3d116670 100644 --- a/examples/graph2d/index.html +++ b/examples/graph2d/index.html @@ -19,6 +19,7 @@

    10_barsSideBySide.html

    11_barsSideBySideGroups.html

    12_customRange.html

    +

    13_localization.html

    diff --git a/examples/timeline/19_localization.html b/examples/timeline/19_localization.html new file mode 100644 index 00000000..3c2c18bd --- /dev/null +++ b/examples/timeline/19_localization.html @@ -0,0 +1,65 @@ + + + + Timeline | Localization + + + + + + + + +

    + To localize the Timeline, one has to load a version of moment.js including locales. To set a locale, specify option {locale: STRING}. +

    + +

    + + +

    + +
    + + + + \ No newline at end of file diff --git a/examples/timeline/index.html b/examples/timeline/index.html index 79b67820..87d052f4 100644 --- a/examples/timeline/index.html +++ b/examples/timeline/index.html @@ -30,6 +30,7 @@

    16_navigation_menu.html

    17_data_serialization.html

    18_range_overflow.html

    +

    19_localization.html

    requirejs_example.html

    diff --git a/lib/timeline/component/CurrentTime.js b/lib/timeline/component/CurrentTime.js index e3735b7f..f3193da8 100644 --- a/lib/timeline/component/CurrentTime.js +++ b/lib/timeline/component/CurrentTime.js @@ -1,5 +1,7 @@ var util = require('../../util'); var Component = require('./Component'); +var moment = require('../../module/moment'); +var locales = require('../locales'); /** * A current time bar @@ -14,7 +16,10 @@ function CurrentTime (body, options) { // default options this.defaultOptions = { - showCurrentTime: true + showCurrentTime: true, + + locales: locales, + locale: 'en' }; this.options = util.extend({}, this.defaultOptions); @@ -57,7 +62,7 @@ CurrentTime.prototype.destroy = function () { CurrentTime.prototype.setOptions = function(options) { if (options) { // copy all options that we know - util.selectiveExtend(['showCurrentTime'], this.options, options); + util.selectiveExtend(['showCurrentTime', 'locale', 'locales'], this.options, options); } }; @@ -81,8 +86,12 @@ CurrentTime.prototype.redraw = function() { var now = new Date(); var x = this.body.util.toScreen(now); + var locale = this.options.locales[this.options.locale]; + var title = locale.current + ' ' + locale.time + ': ' + moment(now).format('dddd, MMMM Do YYYY, H:mm:ss'); + title = title.charAt(0).toUpperCase() + title.substring(1); + this.bar.style.left = x + 'px'; - this.bar.title = 'Current time: ' + now; + this.bar.title = title; } else { // remove the line from the DOM diff --git a/lib/timeline/component/CustomTime.js b/lib/timeline/component/CustomTime.js index 985dc11e..85f04fcf 100644 --- a/lib/timeline/component/CustomTime.js +++ b/lib/timeline/component/CustomTime.js @@ -1,6 +1,8 @@ var Hammer = require('../../module/hammer'); var util = require('../../util'); var Component = require('./Component'); +var moment = require('../../module/moment'); +var locales = require('../locales'); /** * A custom time bar @@ -16,7 +18,9 @@ function CustomTime (body, options) { // default options this.defaultOptions = { - showCustomTime: false + showCustomTime: false, + locales: locales, + locale: 'en' }; this.options = util.extend({}, this.defaultOptions); @@ -39,7 +43,7 @@ CustomTime.prototype = new Component(); CustomTime.prototype.setOptions = function(options) { if (options) { // copy all options that we know - util.selectiveExtend(['showCustomTime'], this.options, options); + util.selectiveExtend(['showCustomTime', 'locale', 'locales'], this.options, options); } }; @@ -102,8 +106,12 @@ CustomTime.prototype.redraw = function () { var x = this.body.util.toScreen(this.customTime); + var locale = this.options.locales[this.options.locale]; + var title = locale.time + ': ' + moment(this.customTime).format('dddd, MMMM Do YYYY, H:mm:ss'); + title = title.charAt(0).toUpperCase() + title.substring(1); + this.bar.style.left = x + 'px'; - this.bar.title = 'Time: ' + this.customTime; + this.bar.title = title; } else { // remove the line from the DOM diff --git a/lib/timeline/component/TimeAxis.js b/lib/timeline/component/TimeAxis.js index e26259a2..6762a468 100644 --- a/lib/timeline/component/TimeAxis.js +++ b/lib/timeline/component/TimeAxis.js @@ -1,6 +1,7 @@ var util = require('../../util'); var Component = require('./Component'); var TimeStep = require('../TimeStep'); +var moment = require('../../module/moment'); /** * A horizontal time axis @@ -63,6 +64,18 @@ TimeAxis.prototype.setOptions = function(options) { if (options) { // copy all options that we know util.selectiveExtend(['orientation', 'showMinorLabels', 'showMajorLabels'], this.options, options); + + // apply locale to moment.js + // TODO: not so nice, this is applied globally to moment.js + if ('locale' in options) { + if (typeof moment.locale === 'function') { + // moment.js 2.8.1+ + moment.locale(options.locale); + } + else { + moment.lang(options.locale); + } + } } }; diff --git a/lib/timeline/locales.js b/lib/timeline/locales.js new file mode 100644 index 00000000..7150dcc7 --- /dev/null +++ b/lib/timeline/locales.js @@ -0,0 +1,41 @@ +// English +exports['en'] = { + // Timeline + current: 'current', + time: 'time', + + // Network + add: 'Add Node', + edit: 'Edit', + link: 'Add Link', + del: 'Delete selected', + editNode: 'Edit Node', + editEdge: 'Edit Edge', + back: 'Back', + addDescription: 'Click in an empty space to place a new node.', + linkDescription: 'Click on a node and drag the edge to another node to connect them.', + editEdgeDescription: 'Click on the control points and drag them to a node to connect to it.' +}; +exports['en_EN'] = exports['en']; +exports['en_US'] = exports['en']; + +// Dutch +exports['nl'] = { + // Timeline + custom: 'aangepaste', + time: 'tijd', + + // Network + add: 'Node', + edit: 'Wijzigen', + link: 'Link toevoegen', + del: 'Selectie verwijderen', + editNode: 'Node wijzigen', + editEdge: 'Link wijzigen', + back: 'Terug', + addDescription: 'Klik op een leeg gebied om een nieuwe node te maken.', + linkDescription: 'Klik op een node en sleep de link naar een andere node om ze te verbinden.', + editEdgeDescription: 'Klik op de verbindingspunten en sleep ze naar een node om daarmee te verbinden.' +}; +exports['nl_NL'] = exports['nl']; +exports['nl_BE'] = exports['nl'];