简体   繁体   中英

How to render vis.js timeline elements in Portuguese?

I was tasked to do a basic timeline using the components of vis.js, the question is that I'm from Brazil, and the timeline os vis.js displays months in English and I need them to be in Portuguese, studying the docs I found something about locale that allows the change in language, but as much as I tried, I couldn't change it.

It would be of great help if you could help me do it, here is my code regarding the change in language:

   var options = {
        width: "100%",
        height: "381px",
        timeAxis: {scale: 'year', step: 1},
        zoomable: false,
        maxMinorChars: 1,
        locales: {
            mylocale: {
                current: 'atual',
                time: 'tempo'
            }
        },
        locale: 'mylocale',
        format: {
            minorLabels: {
                day: 'DD',
                month: 'MMMM',
                year: 'YYYY'
            },
            majorLabels: {
                day: 'DD',
                month: 'MMMM',
                year: 'YYYY'
            }
        }
    };

Code was based on this links: ( http://visjs.org/docs/timeline/ ) ( http://momentjs.com/ )

I know this question is old and I don't know if the version of vis.js supported this when you asked the question, but...

the minorLabels and majorLabels can be functions instead of an object and you can return whatever string you want. The functions take 3 arguments (date, scale, step).

options: {
  format: {
    minorLabels: function (date, scale, step) {
      // return minor label with date in your locale
    },
    majorLabels: function (date, scale, step) {
      // return major label with date in your locale
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM