From: Yuri Khan <yuri.v.khan@gmail.com>
To: Tino Calancha <tino.calancha@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Generalize and standarize dired-plural-s
Date: Mon, 19 Sep 2016 02:47:18 +0600 [thread overview]
Message-ID: <CAP_d_8UcaHONYY_XrixuFSEZmFJdt_stARDrO9UTBXV0B4h9tA@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.20.1609190424080.31571@calancha-pc>
On Mon, Sep 19, 2016 at 2:28 AM, Tino Calancha <tino.calancha@gmail.com> wrote:
>> It is also easier to extend to other languages, if and when we deem it
>> necessary. (It would require passing an additional argument to specify
>> language, and more forms (singular, dual, trial, paucal, plural).)
>>
>> I also suggest that the function be split in two: a core function
>> dealing with integers only, and a convenience wrapper that also
>> accepts sequences.
>
> Thank you Yuri for your suggstions.
> Something like this? With the additional forms and the language argument
> keep unimplemented:
There’s not yet consensus on whether language support is desired, so
feel free to disregard the following. (The issue of providing Emacs
localization has been raised previously; the argument against is that
the Emacs UI consists not only of messages but also command names and
localizing those is harmful, see Microsoft Excel for an example of
what happens.)
Hypothetically, if it is…
At the lowest level, we’d need functions implementing the actual
selection for all supported languages. Untested, not-well-thought,
head-to-fingers-to-mail-client code follows:
(defun string-plural-japanese (_arg forms)
(car forms))
(defun string-plural-english (arg forms)
(if (= arg 1) (car forms) (cadr forms)))
(defun string-plural-russian (arg forms)
(pcase forms (`(,singular ,dual ,plural . ,_)
(pcase (list (% (/ arg 10) 10) (% arg 10))
(`(1 ,_ones) plural)
(`(,_tens 1) singular)
(`(,_tens 2) dual)
(`(,_tens 3) dual)
(`(,_tens 4) dual)
(`(,_tens ,_ones) plural)))))
I avoid assigning fixed positions for each form, for two reasons:
* not all languages use all forms;
* fixed positions are brittle in case we need to add a language with
even more forms.
Note how the selection logic can be complicated. Generally, taking the
length of a list is not avoidable; in Russian, a list of 1001 things
still wants the singular form while 1000 wants plural.
The wrapper function could accept the language worker function
directly as an argument:
(defun string-plural (lang arg &rest forms)
"<…docstring…>"
(cond
((natnump arg) (lang arg forms))
((sequencep arg) (lang (length arg) forms))
(t (error "<…some useful message…>"))))
However, this makes for clumsy usage syntax:
(message "%d %s of beer on the wall"
10
(string-plural string-plural-english 10 "bottle" "bottles"))
So maybe LANG could be a string serving as a key into an alist…
(defvar string-plural-languages
(("ja" . string-plural-japanese)
("en" . string-plural-english)
("ru" . string-plural-russian)))
(defun string-plural (lang arg &rest forms)
"<…docstring…>"
(let ((lang-function
(cond
((stringp lang) (assoc lang string-plural-languages))
((functionp lang) lang)
(t (error "…")))))
(cond
((natnump arg) (lang-function arg forms))
((sequencep arg) (lang-function (length arg) forms))
(t (error "<…some useful message…>"))))
(message "%d %s of beer on the wall"
10
(string-plural "en" 10 "bottle" "bottles"))
prev parent reply other threads:[~2016-09-18 20:47 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-18 14:00 Generalize and standarize dired-plural-s Tino Calancha
2016-09-18 15:06 ` Kaushal Modi
2016-09-18 15:12 ` Drew Adams
2016-09-18 17:45 ` Yuri Khan
2016-09-18 19:28 ` Tino Calancha
2016-09-18 20:47 ` Yuri Khan [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAP_d_8UcaHONYY_XrixuFSEZmFJdt_stARDrO9UTBXV0B4h9tA@mail.gmail.com \
--to=yuri.v.khan@gmail.com \
--cc=emacs-devel@gnu.org \
--cc=tino.calancha@gmail.com \
/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 external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.