Andreas Roehler wrote:
Thanks all for your useful hints. Here an already working draft:
;; (defcustom calendar-use-locales nil
;; "Use local names of day and month"
;; :type 'boolean
;; :group 'calendar)
(setq calendar-use-locales t)
(defun calendar-use-locales-function ()
" "
(interactive)
(when calendar-use-locales
(progn
(setq calendar-day-name-array (locale-info 'days))
(setq calendar-month-name-array (locale-info 'months)))))
;; with $LANG=de_DE.UTF-8
GNU Emacs 22.0.50.1 (i686-pc-linux-gnu, X toolkit, Xaw3d scroll bars)
of 2006-09-11
Would be nice to hear from users with different languages.
locale-info returns nil on:
GNU Emacs 22.0.50.1 (i386-mingw-nt5.1.2600) of 2006-04-22 on YAMALOK
so maybe the default value of calendar-use-locales should depend on
system-type, or you should just get rid of it:
(let ((days (locale-info 'days))
(months (locale-info 'months)))
(when days
(setq calendar-day-name-array days))
(when months
(setq calendar-month-name-array months)))
And since format-time-string's doc string claims that it takes the
locale into account, you could use it to provide the values when
locale-info can't:
(let ((days (locale-info 'days))
(months (locale-info 'months)))
(if days
(setq calendar-day-name-array days)
(let ((this-year
(string-to-number (format-time-string "%Y")))
(this-month
(string-to-number (format-time-string "%m"))))
(setq calendar-day-name-array
(apply 'vector
(mapcar (lambda (time)
(format-time-string "%A" time))
(sort (mapcar (lambda (day)
(encode-time 0 0 0 day
this-month this-year
0))
'(1 2 3 4 5 6 7))
;; by day of week:
(lambda (time-1 time-2)
(< (nth 6 (decode-time time-1))
(nth 6 (decode-time time-2))))))))))
(if months
(setq calendar-month-name-array months)
(let ((this-year
(string-to-number (format-time-string "%Y"))))
(setq calendar-month-name-array
(apply 'vector
(mapcar (lambda (month)
(let ((first (encode-time 0 0 0 1 month
this-year
0)))
(format-time-string "%B" first t)))
'(1 2 3 4 5 6 7 8 9 10 11 12)))))))
Is there any reason not to roll that directly into each variable's
defcustom in calendar.el, where the default values are defined?
And note that "%a" and "%b" can be used the same way to initialize
calendar-day-abbrev-array and calendar-month-abbrev-array, resp.