From mboxrd@z Thu Jan 1 00:00:00 1970 From: Ricardo Wurmus Subject: Re: Web site i18n with Haunt Date: Sat, 10 Feb 2018 00:14:26 +0100 Message-ID: <877erl7o31.fsf@elephly.net> References: <20171223125116.33r6kjnu2zze7f2o@floriannotebook> <20180208171243.dnligzfvwsxvc4l3@floriannotebook> <87a7wi2tey.fsf@gnu.org> <20180209133949.dvl2dry7oija5ayl@floriannotebook> <87y3k2xfj5.fsf_-_@gnu.org> <20180209174745.nlhk3vv3si7u4vs2@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]:37473) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ekHso-0006lF-Cf for guix-devel@gnu.org; Fri, 09 Feb 2018 18:15:09 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ekHsm-000389-PY for guix-devel@gnu.org; Fri, 09 Feb 2018 18:15:06 -0500 Received: from sender-of-o51.zoho.com ([135.84.80.216]:21046) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ekHsm-00037p-Ht for guix-devel@gnu.org; Fri, 09 Feb 2018 18:15:04 -0500 In-reply-to: <20180209174745.nlhk3vv3si7u4vs2@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: > How for example would this excerpt from my website better be rendered > as XML or is this or another non-XML approach better? I=E2=80=99d much prefer XML here. One reason is that I find it very hard t= o understand the syntax and how it is processed in your example. Even after looking at the example for some time, it=E2=80=99s still difficult to understand. You have non-translatable tags that end on an underscore, but the number of pipe characters is not clear to me. How is the sentence with =E2=80=9Cregister_=E2=80=9D parsed? Which parts are bound to =E2=80=9Cbefore-link=E2=80=9D, =E2=80=9Clink-text=E2=80=9D, and =E2=80=9Caf= ter-link=E2=80=9D? > (p ,@(__ "Thank you for your interest in my workshop \ > =E2=80=9CGUI Programming with GTK+=E2=80=9D. ||register_|To register plea= se go |here|. ||For \ > more information see ||link_|here||." > `(("register_" . > ,(lambda (before-link link-text after-link) > (if enable-registration > `(span > ,before-link > ,(a-href > "/gui-prog-anmelden/" > link-text) > ,after-link) > ""))) > ("link_" . > ,(lambda (text) > (a-href > (poster-url-for-lingua current-lingua) > text)))))) 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). The first = one is easy: "Thank you for your interest in my workshop =E2=80=9CGUI Programming with= GTK+=E2=80=9D." The second one might be: "To register please go here." The third: "For more information see here." (Whatever tag name is used is arbitrary and only has to be unique within the context of a single translatable string.) Or they could all be one big XML snippet. 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. Here=E2=80=99s a trivial example of such a transform: --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") ;; 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 URL = 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)))) =3D> (*TOP* (translation "Click " (a (@ (href "http://gnu.org")) "here"))) --8<---------------cut here---------------end--------------->8--- Using =E2=80=9Cpre-post-order=E2=80=9D directly is verbose as you need to s= pecify 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. --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))))) (foo "Click here" `(link . ,(lambda (tag . contents) `(a (@ (href "/help")) ,@contents)))) --8<---------------cut here---------------end--------------->8--- -- Ricardo GPG: BCA6 89B6 3655 3801 C3C6 2150 197A 5888 235F ACAC https://elephly.net