unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Andreas Roehler <andreas.roehler@easy-emacs.de>
Cc: Glenn Morris <rgm@gnu.org>, emacs-devel <emacs-devel@gnu.org>
Subject: Re: calendar m17n
Date: Sat, 16 Sep 2006 09:21:20 +0200	[thread overview]
Message-ID: <450BA5F0.4050804@easy-emacs.de> (raw)
In-Reply-To: <eeep2k$3sm$1@sea.gmane.org>

Kevin Rodgers schrieb:
> 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.
>

OK, thanks! Last question I would leave to the maintainer.

Here the combined results so far:

(defcustom calendar-use-locales  nil
  "Use local names of day and month"
 
  :type 'boolean
  :group 'calendar)

;; Sometimes `defcustom' doesn't take effect immediatitly
;; (setq calendar-use-locales t)

(defun calendar-use-locales-function ()
  " "
  (interactive)
  (when calendar-use-locales
    (progn
      (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))))))))))

  reply	other threads:[~2006-09-16  7:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-09-14  7:31 calendar m17n Andreas Roehler
2006-09-14  8:43 ` Reiner Steib
2006-09-14  8:52 ` Andreas Schwab
2006-09-14 15:39   ` Kevin Rodgers
2006-09-14 18:56   ` Andreas Roehler
2006-09-15 17:38     ` Glenn Morris
2006-09-15 17:48     ` Kevin Rodgers
2006-09-16  7:21       ` Andreas Roehler [this message]
2006-09-16 11:08       ` Eli Zaretskii
2006-09-16 19:05         ` Richard Stallman
2006-09-24 12:53         ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=450BA5F0.4050804@easy-emacs.de \
    --to=andreas.roehler@easy-emacs.de \
    --cc=emacs-devel@gnu.org \
    --cc=rgm@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).