Date.ext.locales['fr'] = { a: ['dim', 'lun', 'mar', 'mer', 'jeu', 'ven', 'sam'], A: ['dimanche', 'lundi', 'mardi', 'mercredi', 'jeudi', 'vendredi', 'samedi'], b: ['jan', 'fév', 'mar', 'avr', 'mai', 'jun', 'jui', 'aoû', 'sep', 'oct', 'nov', 'déc'], B: ['janvier', 'février', 'mars', 'avril', 'mai', 'juin', 'juillet', 'août', 'septembre', 'octobre', 'novembre', 'décembre'], c: '%a %d %b %Y %T %Z', p: ['', ''], P: ['', ''], x: '%d.%m.%Y', X: '%T' };
This locale definition may be included in your own source file, or in the HTML file including strftime.js
, however it must be defined after including strftime.js
The above definition includes generic french strings and formats that are used in France. Other french speaking countries may have other representations for dates and times, so we need to override this for them. For example, Canadian french uses a Y-m-d date format, while French french uses d.m.Y. We fix this by defining Canadian french to be the same as generic french, and then override the format specifiers for x
for the fr-CA
locale:
Date.ext.locales['fr-CA'] = Date.ext.locales['fr']; Date.ext.locales['fr-CA'].x = '%Y-%m-%d'; //! End french
You can now use any of the French locales at any time by setting Date.locale to "fr"
, "fr-FR"
, "fr-CA"
, or any other french dialect:
var d = new Date("2008/04/22"); d.locale = "fr"; d.strftime("%A, %d %B == %x");
mardi, 22 avril == 22.04.2008
d.locale = "fr-CA"; d.strftime("%A, %d %B == %x");
mardi, 22 avril == 2008-04-22
You can use any of the format specifiers defined at formats
The locale for all dates defaults to the value of the lang
attribute of your HTML document if it is set, or to "en"
otherwise.
eg: fr-FR, de-DE, hi-IN
http://www.loc.gov/standards/iso639-2/php/code_list.php
http://www.iso.org/iso/country_codes/iso_3166_code_lists/english_country_names_and_code_elements.htm
"en"
. No warning will be issued.For example, if we define a locale for de:
Date.ext.locales['de'] = { a: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'], A: ['Sonntag', 'Montag', 'Dienstag', 'Mittwoch', 'Donnerstag', 'Freitag', 'Samstag'], b: ['Jan', 'Feb', 'Mär', 'Apr', 'Mai', 'Jun', 'Jul', 'Aug', 'Sep', 'Okt', 'Nov', 'Dez'], B: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'], c: '%a %d %b %Y %T %Z', p: ['', ''], P: ['', ''], x: '%d.%m.%Y', X: '%T' };
"de-DE"
: d.locale = "de-DE"; d.strftime("%a, %d %b");
"de"
locale will be used since "de-DE"
has not been defined: Di, 22 Apr
Swiss german will return the same since it will also fall back to "de"
:
d.locale = "de-CH"; d.strftime("%a, %d %b");
Di, 22 Apr
We need to override the a
specifier for Swiss german, since it's different from German german:
Date.ext.locales['de-CH'] = Date.ext.locales['de']; Date.ext.locales['de-CH'].a = ['Son', 'Mon', 'Die', 'Mit', 'Don', 'Fre', 'Sam']; //! End german
d.locale = "de-CH"; d.strftime("%a, %d %b");
Die, 22 Apr