How to use custom locale in vis.js timeline

2.2k views Asked by At

I am using the vis.js timeline for a project and tried to add a custom locale as explained in the documentation.

var options = {
  locales: {
    // create a new locale (text strings should be replaced with localized strings)
    mylocale: {
      current: 'current',
      time: 'time',
    }
  },

  // use the new locale
  locale: 'mylocale'
};

Although I'd like to make it work without moment.js I loaded moment.js before vis.js. Here is an example on jsfiddle that I expected to work but it doesn't. Can somebody please explain why it doesn't work as documented or if I missed something important?

2

There are 2 answers

0
Vincent GODIN On

You can simply set your options:

const options {
  option: 'fr'
}

But you need to add:

<script src="http://cdnjs.cloudflare.com/ajax/libs/moment.js/2.8.1/moment-with-locales.min.js"></script>

See https://visjs.github.io/vis-timeline/examples/timeline/other/localization.html for example.

0
Ahmed Hamed On

After doing some digging, you need to add these lines in this order :

load moment js first

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/moment.min.js"></script>

load "fr" since the example you provided in JSfiddle was in French

<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.24.0/locale/fr.js"></script>