From mboxrd@z Thu Jan 1 00:00:00 1970 From: "pelzflorian (Florian Pelz)" Subject: Re: Web site i18n with Haunt Date: Sun, 11 Feb 2018 14:52:30 +0100 Message-ID: <20180211135230.eowx3yvvm3fll3i6@floriannotebook> 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> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="twpfz7tq6ckadykk" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:49728) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eks3c-0001W7-M0 for guix-devel@gnu.org; Sun, 11 Feb 2018 08:52:43 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eks3b-0004Tu-Jx for guix-devel@gnu.org; Sun, 11 Feb 2018 08:52:40 -0500 Content-Disposition: inline In-Reply-To: <877erl7o31.fsf@elephly.net> 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: Ricardo Wurmus Cc: guix-devel@gnu.org, davet@gnu.org --twpfz7tq6ckadykk Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Feb 10, 2018 at 12:14:26AM +0100, Ricardo Wurmus wrote: > pelzflorian (Florian Pelz) writes: >=20 > > How for example would this excerpt from my website better be rendered > > as XML or is this or another non-XML approach better? >=20 > I=E2=80=99d much prefer XML here. One reason is that I find it very hard= to > understand the syntax and how it is processed in your example. [=E2=80= =A6] I agree. > The translatable text could be written as two or more strings (it > doesn=E2=80=99t matter that they end up in the same paragraph). [=E2=80= =A6] Yes, you are right, the context will still be clear for translators because the consecutive line numbers are next to each other in the PO file and they do not appear at two unrelated places in the code. > With sxpath we can easily pick tagged substrings by specifying their > path. Or we could fold over the parse tree and transform it by applying > an arbitrary transformation. >=20 > Here=E2=80=99s a trivial example of such a transform: >=20 > --8<---------------cut here---------------start------------->8--- > (use-modules (sxml simple) (sxml transform)) > ;; This is the translated string, wrapped in some tag to make it a valid > ;; XML fragment. > (define tr "Click here") >=20 > ;; Convert to SXML, then transform it. > (pre-post-order (xml->sxml tr) > ;; When we find the tag =E2=80=9Clink=E2=80=9D wrap the contents in a UR= L anchor. > `((link . ,(lambda (tag . kids) > `(a (@ (href "http://gnu.org")) ,kids))) > ;; Just wrap the contents in a tag for everything else > (*default* . ,(lambda (tag . kids) `(,tag ,@kids))) > ;; Unwrap all text > (*text* . ,(lambda (_ txt) txt)))) >=20 > =3D> (*TOP* (translation "Click " (a (@ (href "http://gnu.org")) "here"))) > --8<---------------cut here---------------end--------------->8--- >=20 > Using =E2=80=9Cpre-post-order=E2=80=9D directly is verbose as you need to= specify the > *default* and *text* handlers, but this can easily be hidden by a > friendlier procedure that would present a user interface that wouldn=E2= =80=99t > look too different from what your macro presents to users. >=20 > --8<---------------cut here---------------start------------->8--- > (define (foo str . handlers) > (pre-post-order (xml->sxml (string-append "" str "")) > `(,@handlers > (*default* . ,(lambda (tag . kids) `(,tag ,@kids))) > (*text* . ,(lambda (_ txt) txt))))) >=20 > (foo "Click here" > `(link . ,(lambda (tag . contents) > `(a (@ (href "/help")) ,@contents)))) > --8<---------------cut here---------------end--------------->8--- > So I took your approach and ran with it: https://pelzflorian.de/git/pelzfloriande-website/commit/?id=3D77e1c30532f0b= f834ddc6709c7883c17bb46740f I did not use SXPath. This one still looks ugly: (div (@ (id "powered-by")) ,@(__ "Powered by 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? Thank you all so much for your code and your help. Regards, Florian --twpfz7tq6ckadykk Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEwRjGsqAMqXB4uw3y3T6EbElHBVsFAlqASpgACgkQ3T6EbElH BVsITQ/7BchPmWNgSGThglVhkpjFIgoCP2H0jXyZJH+S/ezwdVJDP5Y/2WkW2jpy epHyDdTk/ZQkx/PwcekAIGiotR45R+MUEhb6x++n3Olut7+R6whyml+iv8KkO9Gn UI+TZpbWo8KI30pQQFcnrpbNWH5O5GczRL+Mwz5Sz7P/azbckM34FhLQq/9rTm2A pjzCBUZQGL0z03rlZ+xbHBM+Ov9OhQVlMq5u5JVU4hhO+Xqw3abRL5NO+8GkwuDc oknjx2ffiRLX/5jjvhyiFWIT5wj51L3d6tnDxHcr5CztGiNCjUzEZkrr59gPlDxb dvWe8qzgX3bBXxqTdjjY8Iu8GxrusHGjNBoV7sLi/t0hphy7aD12eXG0FhnY9Ggi /0qAFglo+DuxanjzjrozZnwAYjB3JoturVKhJcXRk6nIIhYf/+2W29xZBmvSjsC8 Ou8Ltd2OKoA/nilMdGuJQ3bI+q29ZquuKFQ5BZx/e/EXdYl/FblG4IV01DFt7vHJ 7fibhBkAWOj8DKfdERGZfHuAVU4vcypUiPhmljjZ1fLHpRR066g0yZWjpMECfo7X rcpIfJdksiQgGXrmStrHv2dY8exoYknNukXy/TAT+0l1sdP1j1kVtoxv4W0qHQNC WquwDAuQAwTGsqDaru6fsjmXNvOHxNGhgkJPlJ4+sTGdTzr66rE= =1iUF -----END PGP SIGNATURE----- --twpfz7tq6ckadykk--