all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "pelzflorian (Florian Pelz)" <pelzflorian@pelzflorian.de>
To: julien lepiller <julien@lepiller.eu>
Cc: guix-devel@gnu.org
Subject: Re: Translating to Chinese, Spanish and Japanese (and more)
Date: Mon, 5 Feb 2018 15:44:30 +0100	[thread overview]
Message-ID: <20180205144429.rza5xovsei6arfeg@floriannotebook> (raw)
In-Reply-To: <20180205094129.efgxn7nucoj3kwsf@floriannotebook>


[-- Attachment #1.1: Type: text/plain, Size: 943 bytes --]

On Mon, Feb 05, 2018 at 10:41:29AM +0100, pelzflorian (Florian Pelz) wrote:
> I thought about making page translations possible by allowing page
> bodies to be lambdas taking a page variant as an argument, e.g. a
> string containing an ietf language code, and returning the body
> S-expression.
> 
> Then the page variants could be specified per site and each page would
> be generated once per variant.
> 
> A site’s post-template and collection-template could then also
> optionally be lambdas returning SHTML instead of SHTML.
> 
> It should also be possible to specify a procedure to transform a base
> page name and a language variant to a new page name.
> 
> I still did not have time to send a patch though…

Basically what I mean is to generate multiple variants of each Haunt
page, e.g. one for each locale.  See the attached patches.  I did not
try them yet neither document nor test them.  Will do so later.

[-- Attachment #1.2: 0001-page-Allow-for-creating-multiple-files-as-variants-f.patch --]
[-- Type: text/plain, Size: 3121 bytes --]

From c8d0fdbfdfaba2e9cab3aa7d3ab7920e317d3735 Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Mon, 5 Feb 2018 13:08:14 +0100
Subject: [PATCH 1/2] page: Allow for creating multiple files as variants for
 each page.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.16.1"

This is a multi-part message in MIME format.
--------------2.16.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


* haunt/page.scm: Adapt write-page to optionally build multiple
                  variants and add helper function to transform file
                  names.
---
 haunt/page.scm | 40 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 37 insertions(+), 3 deletions(-)


--------------2.16.1
Content-Type: text/x-patch; name="0001-page-Allow-for-creating-multiple-files-as-variants-f.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0001-page-Allow-for-creating-multiple-files-as-variants-f.patch"

diff --git a/haunt/page.scm b/haunt/page.scm
index 85b2ae6..796ad24 100644
--- a/haunt/page.scm
+++ b/haunt/page.scm
@@ -32,6 +32,7 @@
             page-file-name
             page-contents
             page-writer
+            variant->file-name
             write-page))
 
 (define-record-type <page>
@@ -41,10 +42,43 @@
   (contents page-contents)
   (writer page-writer))
 
-(define (write-page page output-directory)
-  "Write PAGE to OUTPUT-DIRECTORY."
+(define (variant->file-name variant base-file-name)
+  (let ((variant-as-text
+         (with-output-to-string
+           (lambda ()
+             (display variant))))
+        (period-index
+         (string-rindex base-file-name #\.)))
+    (if period-index
+        (string-append
+         (string-take base-file-name
+                      period-index)
+         "."
+         variant-as-text
+         "."
+         (string-drop base-file-name
+                      (1+ period-index)))
+        (string-append
+         base-file-name
+         "."
+         variant-as-text))))
+
+(define* (write-page page output-directory
+                     #:optional
+                     variants
+                     (variant-file-name-transformer
+                      variant->file-name))
+  "Write PAGE to OUTPUT-DIRECTORY.  If VARIANTS are given, the page
+contents may be a procedure that given a page variant returns SHTML.
+Otherwise the page contents must be SHTML."
   (match page
     (($ <page> file-name contents writer)
      (let ((output (string-append output-directory "/" file-name)))
        (mkdir-p (dirname output))
-       (call-with-output-file output (cut writer contents <>))))))
+       (if (and variants (not (null? variants)) (procedure? contents))
+           (for-each
+            (lambda (variant)
+              (call-with-output-file output
+                (cut writer (contents variant) <>)))
+            variants)
+           (call-with-output-file output (cut writer contents <>)))))))

--------------2.16.1--



[-- Attachment #1.3: 0002-site-Allow-specifying-variants-in-which-to-create-ea.patch --]
[-- Type: text/plain, Size: 3801 bytes --]

From 8ac77740b51e905112129af0d12d2f70fd5b676e Mon Sep 17 00:00:00 2001
From: Florian Pelz <pelzflorian@pelzflorian.de>
Date: Mon, 5 Feb 2018 13:13:14 +0100
Subject: [PATCH 2/2] site: Allow specifying variants in which to create each
 page.
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.16.1"

This is a multi-part message in MIME format.
--------------2.16.1
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit


* haunt/site.scm: Add variants for which to create pages.
---
 haunt/site.scm | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)


--------------2.16.1
Content-Type: text/x-patch; name="0002-site-Allow-specifying-variants-in-which-to-create-ea.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0002-site-Allow-specifying-variants-in-which-to-create-ea.patch"

diff --git a/haunt/site.scm b/haunt/site.scm
index 48573e2..6ce88a5 100644
--- a/haunt/site.scm
+++ b/haunt/site.scm
@@ -44,6 +44,7 @@
             site-make-slug
             site-readers
             site-builders
+            site-variants
             site-post-slug
             build-site
 
@@ -52,7 +53,7 @@
 
 (define-record-type <site>
   (make-site title domain posts-directory file-filter build-directory
-             default-metadata make-slug readers builders)
+             default-metadata make-slug readers builders variants)
   site?
   (title site-title)
   (domain site-domain)
@@ -62,7 +63,9 @@
   (default-metadata site-default-metadata)
   (make-slug site-make-slug)
   (readers site-readers)
-  (builders site-builders))
+  (builders site-builders)
+  (variants site-variants)
+  (variant-file-name-transformer site-variant-file-name-transformer))
 
 (define* (site #:key
                (title "This Place is Haunted")
@@ -73,7 +76,9 @@
                (default-metadata '())
                (make-slug post-slug)
                (readers '())
-               (builders '()))
+               (builders '())
+               (variants '())
+               (variant-file-name-transformer variant->file-name))
   "Create a new site object.  All arguments are optional:
 
 TITLE: The name of the site
@@ -86,9 +91,13 @@ DEFAULT-METADATA: An alist of arbitrary default metadata for posts
 whose keys are symbols
 MAKE-SLUG: A procedure generating a file name slug from a post
 READERS: A list of reader objects for processing posts
-BUILDERS: A list of procedures for building pages from posts"
+BUILDERS: A list of procedures for building pages from posts
+VARIANTS: Variants for which to build the site’s pages
+VARIANT-FILE-NAME-TRANSFORMER: Procedure to convert variant and file
+                               name to a new file name"
   (make-site title domain posts-directory file-filter build-directory
-             default-metadata make-slug readers builders))
+             default-metadata make-slug readers builders variants
+             variant-file-name-transformer))
 
 (define (site-post-slug site post)
   "Return a slug string for POST using the slug generator for SITE."
@@ -109,7 +118,9 @@ BUILDERS: A list of procedures for building pages from posts"
     (for-each (match-lambda
                ((? page? page)
                 (format #t "writing page '~a'~%" (page-file-name page))
-                (write-page page build-dir))
+                (write-page page build-dir
+                            (site-variants site)
+                            (site-variant-file-name-transformer site)))
                ((? asset? asset)
                 (format #t "copying asset '~a' → '~a'~%"
                         (asset-source asset)

--------------2.16.1--



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

  parent reply	other threads:[~2018-02-05 14:44 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-05  9:07 Translating to Chinese, Spanish and Japanese (and more) Pjotr Prins
2018-02-05  9:28 ` julien lepiller
2018-02-05  9:41   ` pelzflorian (Florian Pelz)
2018-02-05 12:26     ` Ricardo Wurmus
2018-02-05 14:47       ` pelzflorian (Florian Pelz)
2018-02-05 17:21         ` Ricardo Wurmus
2018-02-05 14:44     ` pelzflorian (Florian Pelz) [this message]
2018-02-06 10:17       ` pelzflorian (Florian Pelz)
2018-02-06 10:19         ` pelzflorian (Florian Pelz)
2018-03-29 10:22           ` julien lepiller
2018-04-21 15:41             ` pelzflorian (Florian Pelz)
2018-02-05 10:19   ` Ludovic Courtès
2018-02-05 10:49     ` 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=20180205144429.rza5xovsei6arfeg@floriannotebook \
    --to=pelzflorian@pelzflorian.de \
    --cc=guix-devel@gnu.org \
    --cc=julien@lepiller.eu \
    /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.