all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de>
To: Ricardo Wurmus <rekado@elephly.net>
Cc: guix-devel@gnu.org, davet@gnu.org
Subject: Re: Web site i18n with Haunt
Date: Sun, 11 Feb 2018 14:52:30 +0100	[thread overview]
Message-ID: <20180211135230.eowx3yvvm3fll3i6@floriannotebook> (raw)
In-Reply-To: <877erl7o31.fsf@elephly.net>

[-- Attachment #1: Type: text/plain, Size: 3408 bytes --]

On Sat, Feb 10, 2018 at 12:14:26AM +0100, Ricardo Wurmus wrote:
> pelzflorian (Florian Pelz) <pelzflorian@pelzflorian.de> 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’d 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.  […]

I agree.

> The translatable text could be written as two or more strings (it
> doesn’t matter that they end up in the same paragraph).  […]

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.
> 
> Here’s 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 "<translation>Click <link>here</link></translation>")
> 
> ;; Convert to SXML, then transform it.
> (pre-post-order (xml->sxml tr)
>  ;; When we find the tag “link” 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))))
> 
> => (*TOP* (translation "Click " (a (@ (href "http://gnu.org")) "here")))
> --8<---------------cut here---------------end--------------->8---
> 
> Using “pre-post-order” 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’t
> 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 "<translation>" str "</translation>"))
>   `(,@handlers
>     (*default*  . ,(lambda (tag . kids) `(,tag ,@kids)))
>     (*text*     . ,(lambda (_ txt) txt)))))
> 
> (foo "Click <link>here</link>"
>  `(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=77e1c30532f0bf834ddc6709c7883c17bb46740f

I did not use SXPath.  This one still looks ugly:

(div (@ (id "powered-by"))
     ,@(__ "Powered by <link \
url=\"https://www.gnu.org/software/guile/\">GNU Guile</link> and \
<link url=\"https://haunt.dthompson.us/\">Haunt</link>."
           `(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 "…")) attribute?

Thank you all so much for your code and your help.

Regards,
Florian

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2018-02-11 13:52 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20171223125116.33r6kjnu2zze7f2o@floriannotebook>
2018-02-08 17:12 ` Haunt patches pelzflorian (Florian Pelz)
2018-02-09 13:18   ` Ludovic Courtès
2018-02-09 13:39     ` pelzflorian (Florian Pelz)
2018-02-09 17:02       ` Web site i18n with Haunt Ludovic Courtès
2018-02-09 17:47         ` pelzflorian (Florian Pelz)
2018-02-09 23:14           ` Ricardo Wurmus
2018-02-11 13:52             ` pelzflorian (Florian Pelz) [this message]
2018-02-11 14:45               ` Ricardo Wurmus
2018-02-11 16:04                 ` pelzflorian (Florian Pelz)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180211135230.eowx3yvvm3fll3i6@floriannotebook \
    --to=pelzflorian@pelzflorian.de \
    --cc=davet@gnu.org \
    --cc=guix-devel@gnu.org \
    --cc=rekado@elephly.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.