chartjs / chartjs-adapter-moment

MIT License
37 stars 23 forks source link

Enhancement: what do you think to add I18N support? #21

Closed stockiNail closed 4 years ago

stockiNail commented 4 years ago

Currently the adapater is not managing the I18N.

Nevertheless Moment.js is supporting I18N and due to CHART.JS 3 introuced the locale options, maybe it could make sense to add this kind of support also for Moment adapter.

In my opinion to use I18N in moment, the user should:

  1. should have a look how to prepare the I18N into Moment.js (see doc https://momentjs.com/docs/#/i18n/) in order to be aware how to leverage on this feature, depending on the runtime; environment;
  2. pass an options (like the other adapters) where is setting the locale as following:
// time scale config
scales: {
    x: {
        type: 'time',
        adapters: {
            date: {
                locale: 'en-US'
            },
        },
        time: {
            unit: 'day'
        }
    },
}

What do you think? If you think it could be helpful, I can try to submit a PR.

benmccann commented 4 years ago

I don't know that I'm necessarily against the feature, but if you want i18n you're really much better off using Luxon. It results in much smaller bundles because it uses the browser's built-in i18n support

stockiNail commented 4 years ago

@benmccann ok I agree because could make sense to use Luxon if you need I18N. Thank you very much

danilkinkin commented 1 year ago

I'm thinks this option should be implemented, because without this function, adapter useless. Not all world speaks on English.

For example, if my old app already uses moment and I can't migrate to another library, it's cool if I can use function which already exist, but I can't use it.

About problem with size app, must thinks who use this library. Also, this function not make library weigher

danilkinkin commented 1 year ago

Ok, I found another solution. If you execute this code before usage Chart.js, right locale will be applied

import moment from 'moment';
moment.locale('cz');