Jqplot - date axis rendering: internationalization

I am using jqplot and I have a date in my x axis.

I am using the DateAxisRenderer plugin, but I want to translate the date to the current locale.

For example, for English

Jan 2012 Feb 2012... 

and for french

 Jan 2012 FΓ©v 2012... 

Any ideas?

+6
source share
1 answer

Little explanation

jqPlot uses jsDate internally: http://sandbox.kendsnyder.com/date2/

jsDate has built-in support for localization and locale. However, this feature is limited by several pre-configured languages ​​in the internal regional table (see 2. ).

1. For the happy

Since in my version of jqPlot (v1.0.4) French is included in this table (perhaps a gift from the authors), all you have to do is just set the lang attribute in the <html> :

 <html lang="fr"> 

Et voilΓ  ...

2. Foreigners

If you want to add your own missing language at run time, you can use the following instructions:

 $(document).ready(function(){ // Add a new localization $.jsDate.regional['it'] = { monthNames: ['Gennaio','Febbraio','Marzo','Aprile','Maggio','Giugno','Luglio','Agosto','Settembre','Ottobre','Novembre','Dicembre'], monthNamesShort: ['Gen','Feb','Mar','Apr','Mag','Giu','Lug','Ago','Set','Ott','Nov','Dic'], dayNames: ['Domenica','Lunedi','Martedi','Mercoledi','Giovedi','Venerdi','Sabato'], dayNamesShort: ['Dom','Lun','Mar','Mer','Gio','Ven','Sab'], formatString: '%d-%m-%Y %H:%M:%S' }; // Do not forget to call $.jsDate.regional.getLocale(); }); 

Remember to call $.jsDate.regional.getLocale() to update the internal settings and set the <html> accordingly.

My looks like:

 <html lang="it"> 

What all...

If you cannot control the markup for the html tag, you can set it with

 document.documentElement.setAttribute('lang', 'it'); 

The lang setting of an intermediate element, such as the surrounding div , does not work.

+6
source

Source: https://habr.com/ru/post/921120/


All Articles