From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Translating to Chinese, Spanish and Japanese (and more) Date: Mon, 05 Feb 2018 13:26:04 +0100 Message-ID: <87po5jd3mr.fsf@elephly.net> References: <20180205090716.GB10165@thebird.nl> <30df6bb24a385c945d261feb5f2f99d2@lepiller.eu> <20180205094129.efgxn7nucoj3kwsf@floriannotebook> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:43353) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eiqs1-00075p-Vj for guix-devel@gnu.org; Mon, 05 Feb 2018 19:12:23 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eiqry-0004yH-NY for guix-devel@gnu.org; Mon, 05 Feb 2018 19:12:21 -0500 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21143) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eiqry-0004xu-Cs for guix-devel@gnu.org; Mon, 05 Feb 2018 19:12:18 -0500 In-reply-to: <20180205094129.efgxn7nucoj3kwsf@floriannotebook> List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: "Guix-devel" To: "pelzflorian (Florian Pelz)" Cc: guix-devel@gnu.org pelzflorian (Florian Pelz) writes: > How do you plan to do the translation with Haunt? Looking at the current implementation of the website, we=E2=80=99re dealing= with abstractions like this: --8<---------------cut here---------------start------------->8--- (define (download dnd) "Return an SHTML representation of the given download object. DND () A download object as defined in (apps download types)." `(div (@ (class "download-box")) (img (@ (src ,(download-image dnd)) (alt ""))) (h3 ,(download-title dnd)) ,(download-description dnd) (p "Download options:") ,@(map (lambda (variant) =09 `(a =09 (@ (class "download-btn") =09=09 (download "") =09=09 (href ,(string-append =09=09=09 (download-base-url dnd) =09=09=09 (variant-file variant)))) =09 ,(variant-label variant) =09 " ")) ; Force a space for readability in non-CSS browsers. =09 (download-variants dnd)) (p "Signatures: " ,@(map (lambda (variant) =09 `(a =09 (@ (class "signature-btn") =09=09 (download "") =09=09 (href ,(string-append =09=09=09 (download-base-url dnd) =09=09=09 (variant-file variant) ".sig"))) =09 ,(variant-label variant) =09 " ")) ; Force a space for readability in non-CSS browsers. =09 (download-variants dnd))) (p (a (@ (href ,(download-manual dnd))) "Installation instructions") "."))) --8<---------------cut here---------------end--------------->8--- We could use the usual Gettext wrapping to provide a list of strings: "Download options:", "Signatures: ", and "Installation instructions". But there are two problems: 1) chopped up strings like the link label =E2=80=9CInstallation instruction= s=E2=80=9D and the trailing =E2=80=9C.=E2=80=9D that is outside of the link label. So= me systems implement a DSL and present the string to translators as =E2=80=9C%aInstall= ation instructions%b.=E2=80=9D where =E2=80=9C%a=E2=80=9D and =E2=80=9C%b=E2=80= =9D are assumed to be replaced by the anchor tags. This is bad because it is ad-hoc and intended to be used by gluing together strings. Simple XML might be a better candidate for a DSL. Translators would get a string like =E2=80=9CInstallation instructions.=E2=80=9D and= give us back a translated string such as =E2=80=9C=E5=AE=89=E8=A3=85=E8=AF=B4=E6= =98=8E=E3=80=82=E2=80=9D On the haunt side we would have a procedure that parses the XML to SXML and we could operate on the S-expression. So instead of this: (p (a (@ (href ,(download-manual dnd))) "Installation instructions") ".") we would have (let ((tr (G_* "Installation instructions."))) (p (sx-until '(link) tr) (a (@ (href ,(download-manual dnd))) (sx '(link *text*) tr)) (sx-after '(link) tr))) The procedure =E2=80=9CG_*=E2=80=9D would get the gettext translation for t= he given string and parse the XML. Then in haunt we can operate on the SXML with the (sxml xpath) module, and with helpers that are built around it. =E2=80=9Csx=E2=80=9D, =E2=80=9Csxuntil=E2=80=9D, and =E2=80=9Csxafter=E2=80= =9D don=E2=80=99t exist yet, but they could be procedures to extract the appropriate built on top of sxpath. =E2=80=9Csx= =E2=80=9D is essentially this: (define (sx path sxml) (let ((match ((sxpath path) sxml))) (if (null? match) "OOPS" (car match)))) 2) procedure calls like =E2=80=9C(variant-label variant)=E2=80=9D The translatable output in these cases is generated SXML. Maybe it is sufficient to treat this as code and translate it like any other procedure with Gettext. -- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net