guix-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Translating to Chinese, Spanish and Japanese (and more)


From: Ricardo Wurmus
Subject: Re: Translating to Chinese, Spanish and Japanese (and more)
Date: Mon, 05 Feb 2018 13:26:04 +0100
User-agent: mu4e 1.0-alpha3; emacs 25.3.1

pelzflorian (Florian Pelz) <address@hidden> writes:

> How do you plan to do the translation with Haunt?

Looking at the current implementation of the website, we’re dealing with
abstractions like this:

--8<---------------cut here---------------start------------->8---
(define (download dnd)
  "Return an SHTML representation of the given download object.

   DND (<download>)
     A download object as defined in (apps download types)."
  `(div
    (@ (class "download-box"))
    (img (@ (src ,(download-image dnd)) (alt "")))
    (h3 ,(download-title dnd))
    ,(download-description dnd)
    (p "Download options:")
    ,@(map (lambda (variant)
             `(a
               (@ (class "download-btn")
                  (download "")
                  (href ,(string-append
                          (download-base-url dnd)
                          (variant-file variant))))
               ,(variant-label variant)
               " ")) ; Force a space for readability in non-CSS browsers.
          (download-variants dnd))

    (p
     "Signatures: "
     ,@(map (lambda (variant)
             `(a
               (@ (class "signature-btn")
                  (download "")
                  (href ,(string-append
                          (download-base-url dnd)
                          (variant-file variant) ".sig")))
               ,(variant-label variant)
               " ")) ; Force a space for readability in non-CSS browsers.
            (download-variants dnd)))

    (p (a (@ (href ,(download-manual dnd))) "Installation instructions")
    ".")))
--8<---------------cut here---------------end--------------->8---

We could use the usual Gettext wrapping to provide a list of strings:
"Download options:", "Signatures: ", and "Installation instructions".
But there are two problems:

1) chopped up strings like the link label “Installation instructions”
and the trailing “.” that is outside of the link label.  Some systems
implement a DSL and present the string to translators as “%aInstallation
instructions%b.” where “%a” and “%b” are assumed to be replaced by the
anchor tags.  This is bad because it is ad-hoc and intended to be used
by gluing together strings.

Simple XML might be a better candidate for a DSL.  Translators would get
a string like “<link>Installation instructions</link>.” and give us back
a translated string such as “<link>安装说明</link>。” On the haunt side
we would have a procedure that parses the XML to SXML and we could
operate on the S-expression.  So instead of this:

    (p (a (@ (href ,(download-manual dnd))) "Installation instructions")
        ".")

we would have

    (let ((tr (G_* "<link>Installation instructions</link>.")))
     (p (sx-until '(link) tr)
        (a (@ (href ,(download-manual dnd)))
           (sx '(link *text*) tr))
        (sx-after '(link) tr)))

The procedure “G_*” would get the gettext translation for the given
string and parse the XML.  Then in haunt we can operate on the SXML with
the (sxml xpath) module, and with helpers that are built around it.

“sx”, “sxuntil”, and “sxafter” don’t exist yet, but they could be
procedures to extract the appropriate built on top of sxpath.  “sx” is
essentially this:

    (define (sx path sxml)
      (let ((match ((sxpath path) sxml)))
        (if (null? match) "OOPS"
            (car match))))


2) procedure calls like “(variant-label variant)”

The translatable output in these cases is generated SXML.  Maybe it is
sufficient to treat this as code and translate it like any other
procedure with Gettext.

--
Ricardo

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]