From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Yuri Khan Newsgroups: gmane.emacs.devel Subject: Re: Generalize and standarize dired-plural-s Date: Mon, 19 Sep 2016 02:47:18 +0600 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: blaine.gmane.org 1474231839 3884 195.159.176.226 (18 Sep 2016 20:50:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 18 Sep 2016 20:50:39 +0000 (UTC) Cc: Emacs developers To: Tino Calancha Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Sep 18 22:50:33 2016 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1blj2k-0008Mq-5u for ged-emacs-devel@m.gmane.org; Sun, 18 Sep 2016 22:50:30 +0200 Original-Received: from localhost ([::1]:51423 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blj2h-0003wu-U8 for ged-emacs-devel@m.gmane.org; Sun, 18 Sep 2016 16:50:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60048) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blj12-0002gL-SQ for emacs-devel@gnu.org; Sun, 18 Sep 2016 16:48:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1blj0y-0006Vk-Qf for emacs-devel@gnu.org; Sun, 18 Sep 2016 16:48:43 -0400 Original-Received: from mail-lf0-f54.google.com ([209.85.215.54]:33332) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1blj0y-0006VP-Dx for emacs-devel@gnu.org; Sun, 18 Sep 2016 16:48:40 -0400 Original-Received: by mail-lf0-f54.google.com with SMTP id h127so97848830lfh.0 for ; Sun, 18 Sep 2016 13:48:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc:content-transfer-encoding; bh=koODHWUHJgT9T0wXFkbRXfnLSWo5BBDhAa2WgwZ2pk4=; b=b32AzqLyzc747ROe5feXqR571l43yTksOZ5RKU1A5jwj2yKUBIv1OQQ+YIOBXvNRSx D3XsiB9xPAulub99jKuWVUO6VA9YyphnQiw+rECO37aaN5AsdqbA8n3WwUigLIxAZw3f dQKh1Mf+6LxKLaRwFy+1SOqPpOYjUHdJqi2iMyfAg/f6yaS/ZZW/whKJBZUh+YTlWYOJ PaRbCA2h00CDVGVEehF71M2ZhxjyERztYP09tUGLmV+bZdtnxmC1xka67/E45o87Qgwl 17le+VcbIZtEx24srGR6ZOHlGQvTwgfUuAtFrt3lcaFt9+wIqoMnlh8STX2n6tUaxz8l 5RaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc:content-transfer-encoding; bh=koODHWUHJgT9T0wXFkbRXfnLSWo5BBDhAa2WgwZ2pk4=; b=UFzwyFs2kH1mZhXlhu+uvcfmv5KaWkCZrPBxsxHkLhiQ1uE3RR94stC7/OFDOJXq3X TcIPNEQiyS4pyP0nRaG9lr7pnAXXvPeJNeStSkfJ9+VYkO1dhY5ka62NiMGY1hDBL96D Cdb0tjSWOrOIsiHtcAgQZoRynLEgyrpTaU8UjF8llsozChxBH9FN89SFSqXM6RdQiZlD KoJFcc0YGxi/m4brT6Y5rxhKTXHel/yWTj+txQBHnzzKZL/rv83PEOw0hs0qglmVc3Yb IYkRQi5HTjIr3Gdsg4EOqm8R6Mq7+EOwt1s5j4UNvxA6AYgcSJu7c1LatAGizBiU/kPh l37g== X-Gm-Message-State: AE9vXwPQvOxozkTi2GiisYKaD1r4+8yPJk+w0+GIpP3ONYpAzv89RuCyBgaDzck/Hogg71YKT2lBLy05VDEYIw== X-Received: by 10.46.32.5 with SMTP id g5mr8742647ljg.51.1474231659435; Sun, 18 Sep 2016 13:47:39 -0700 (PDT) Original-Received: by 10.114.80.163 with HTTP; Sun, 18 Sep 2016 13:47:18 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: 82SNlPrf9hcYrbrta154uNKXlTA X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.85.215.54 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:207589 Archived-At: On Mon, Sep 19, 2016 at 2:28 AM, Tino Calancha wr= ote: >> 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=E2=80=99s not yet consensus on whether language support is desired, s= o 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=E2=80=A6 At the lowest level, we=E2=80=99d 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 (=3D 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) "<=E2=80=A6docstring=E2=80=A6>" (cond ((natnump arg) (lang arg forms)) ((sequencep arg) (lang (length arg) forms)) (t (error "<=E2=80=A6some useful message=E2=80=A6>")))) 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=E2=80=A6 (defvar string-plural-languages (("ja" . string-plural-japanese) ("en" . string-plural-english) ("ru" . string-plural-russian))) (defun string-plural (lang arg &rest forms) "<=E2=80=A6docstring=E2=80=A6>" (let ((lang-function (cond ((stringp lang) (assoc lang string-plural-languages)) ((functionp lang) lang) (t (error "=E2=80=A6"))))) (cond ((natnump arg) (lang-function arg forms)) ((sequencep arg) (lang-function (length arg) forms)) (t (error "<=E2=80=A6some useful message=E2=80=A6>")))) (message "%d %s of beer on the wall" 10 (string-plural "en" 10 "bottle" "bottles"))