7

I use jqplot, and I have date into my x-axis.

I use the DateAxisRenderer plugin but I want to translate the date to my current locale.

For example, for english

Jan 2012 
Feb 2012...

and for french

Jan 2012
Fév 2012...

Any ideas?

arulmr
  • 8,620
  • 9
  • 54
  • 69
Sam
  • 779
  • 3
  • 18
  • 39

1 Answers1

7

A bit of explanation

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

jsDate has built-in localization support and locale detection. This capability, however, is limited to a few ,pre-configured languages, on internal regional table (see 2.).

1. For the lucky ones

Since in my version of jqPlot (v1.0.4) the French language is included in this table (maybe a gift from the authors) all you have to do is simply setting the lang attribute on your <html> tag:

<html lang="fr">

Et voilà...

2. Foreigners

If you want to add your own missing language at runtime you can use these 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();
});

Do not forget to call $.jsDate.regional.getLocale() to refresh internal settings and to set the <html> tag accordingly.

Mine looks like:

<html lang="it">

That's all...

If you aren't able to control the markup for the html tag, you can set it with

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

It doesn't work to set lang of an intermediate element, like a surrounding div.

benomatis
  • 5,536
  • 7
  • 36
  • 59
Alessandro Alessandra
  • 1,065
  • 12
  • 18
  • 1
    Thank you Allessandro, it's a very good and clear answer. I added some information about setting the lang attribute with js. – Zeemee Oct 25 '13 at 07:42