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


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.  Even
after looking at the example for some time, it’s 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 “register_” parsed?  Which parts are bound to
“before-link”, “link-text”, and “after-link”?

> (p ,@(__ "Thank you for your interest in my workshop \
> “GUI Programming with GTK+”. ||register_|To register please 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’t matter that they end up in the same paragraph).  The first one
is easy:

  "Thank you for your interest in my workshop “GUI Programming with GTK+”."

The second one might be:

  "To register please go <register-link>here</register-link>."

The third:

  "For more information see <link>here</link>."

(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’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---

--
Ricardo

GPG: BCA6 89B6 3655 3801 C3C6  2150 197A 5888 235F ACAC
https://elephly.net

  reply	other threads:[~2018-02-09 23:15 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 [this message]
2018-02-11 13:52             ` pelzflorian (Florian Pelz)
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=877erl7o31.fsf@elephly.net \
    --to=rekado@elephly.net \
    --cc=davet@gnu.org \
    --cc=guix-devel@gnu.org \
    --cc=pelzflorian@pelzflorian.de \
    /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.