From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Web site i18n with Haunt Date: Sun, 11 Feb 2018 15:45:12 +0100 Message-ID: <87tvunio07.fsf@elephly.net> References: <20171223125116.33r6kjnu2zze7f2o@floriannotebook> <20180208171243.dnligzfvwsxvc4l3@floriannotebook> <87a7wi2tey.fsf@gnu.org> <20180209133949.dvl2dry7oija5ayl@floriannotebook> <87y3k2xfj5.fsf_-_@gnu.org> <20180209174745.nlhk3vv3si7u4vs2@floriannotebook> <877erl7o31.fsf@elephly.net> <20180211135230.eowx3yvvm3fll3i6@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]:34108) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekssm-0001LD-Mz for guix-devel@gnu.org; Sun, 11 Feb 2018 09:45:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekssl-0007Sg-9t for guix-devel@gnu.org; Sun, 11 Feb 2018 09:45:32 -0500 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21087) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekssl-0007Qk-1b for guix-devel@gnu.org; Sun, 11 Feb 2018 09:45:31 -0500 In-reply-to: <20180211135230.eowx3yvvm3fll3i6@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, davet@gnu.org pelzflorian (Florian Pelz) writes: > I did not use SXPath. This one still looks ugly: > > (div (@ (id "powered-by")) > ,@(__ "Powered by url=3D\"https://www.gnu.org/software/guile/\">GNU Guile and \ > Haunt." > `(link > . ,(lambda (tag attr text) > (a-href > (cadadr attr) > text))))) > > I suppose I should have used SXPath for it to get the URL out of the > (@ (url "=E2=80=A6")) attribute? Since the URL isn=E2=80=99t supposed to be translated I wouldn=E2=80=99t pr= esent it as part of the translatable text, i.e. the string would be: Powered by GNU Guile and Haunt. And then I=E2=80=99d apply the transformations: (foo s `(guile . ,(lambda (_ . contents) (a-href "https://www.gnu.org/software/guile/" ,@contents))= ) `(haunt . ,(lambda (_ . contents) (a-href "https://haunt.dthompson.us/" ,@contents)))) You could use sxpath to avoid cadadr, but it wouldn=E2=80=99t be less verbo= se: (foo s `(link . ,(lambda (_ attr contents) (a-href (car ((sxpath '(url *text*)) attr)) ,contents)))) (Correctly but annoyingly, =E2=80=9Csxpath=E2=80=9D always returns a list, = so we still need to unpack the URL from the result with =E2=80=9Ccar=E2=80=9D.) sxpath takes a path as a list of symbols and returns a selector function that takes a nodeset. So the selector function applied to =E2=80=9Cattr=E2= =80=9D gets us a list of all =E2=80=9C*text*=E2=80=9D nodes inside of a =E2=80=9Curl=E2= =80=9D node in the argument =E2=80=9Cattr=E2=80=9D. -- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net