From mboxrd@z Thu Jan 1 00:00:00 1970 From: "pelzflorian (Florian Pelz)" Subject: Re: Translating to Chinese, Spanish and Japanese (and more) Date: Mon, 5 Feb 2018 15:44:30 +0100 Message-ID: <20180205144429.rza5xovsei6arfeg@floriannotebook> References: <20180205090716.GB10165@thebird.nl> <30df6bb24a385c945d261feb5f2f99d2@lepiller.eu> <20180205094129.efgxn7nucoj3kwsf@floriannotebook> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="ans5sheupsci6goz" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:41572) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eii0a-0003QC-NM for guix-devel@gnu.org; Mon, 05 Feb 2018 09:44:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eii0W-0003fW-M1 for guix-devel@gnu.org; Mon, 05 Feb 2018 09:44:36 -0500 Received: from pelzflorian.de ([5.45.111.108]:49514 helo=mail.pelzflorian.de) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eii0W-0003eX-4v for guix-devel@gnu.org; Mon, 05 Feb 2018 09:44:32 -0500 Content-Disposition: inline In-Reply-To: <20180205094129.efgxn7nucoj3kwsf@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: julien lepiller Cc: guix-devel@gnu.org --ans5sheupsci6goz Content-Type: multipart/mixed; boundary="ve6txew4c6z4ngfu" Content-Disposition: inline --ve6txew4c6z4ngfu Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > Then the page variants could be specified per site and each page would > be generated once per variant. >=20 > A site=E2=80=99s post-template and collection-template could then also > optionally be lambdas returning SHTML instead of SHTML. >=20 > It should also be possible to specify a procedure to transform a base > page name and a language variant to a new page name. >=20 > I still did not have time to send a patch though=E2=80=A6 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. --ve6txew4c6z4ngfu Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-page-Allow-for-creating-multiple-files-as-variants-f.patch" Content-Transfer-Encoding: quoted-printable =46rom c8d0fdbfdfaba2e9cab3aa7d3ab7920e317d3735 Mon Sep 17 00:00:00 2001 =46rom: Florian Pelz 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=3D"------------2.16.1" This is a multi-part message in MIME format. --------------2.16.1 Content-Type: text/plain; charset=3DUTF-8; format=3Dfixed 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=3D"0001-page-Allow-for-creating-multiple-f= iles-as-variants-f.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename=3D"0001-page-Allow-for-creating-m= ultiple-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)) =20 (define-record-type @@ -41,10 +42,43 @@ (contents page-contents) (writer page-writer)) =20 -(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 (($ 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-- --ve6txew4c6z4ngfu Content-Type: text/plain; charset=utf-8 Content-Disposition: attachment; filename="0002-site-Allow-specifying-variants-in-which-to-create-ea.patch" Content-Transfer-Encoding: quoted-printable =46rom 8ac77740b51e905112129af0d12d2f70fd5b676e Mon Sep 17 00:00:00 2001 =46rom: Florian Pelz 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=3D"------------2.16.1" This is a multi-part message in MIME format. --------------2.16.1 Content-Type: text/plain; charset=3DUTF-8; format=3Dfixed 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=3D"0002-site-Allow-specifying-variants-in-= which-to-create-ea.patch" Content-Transfer-Encoding: 8bit Content-Disposition: attachment; filename=3D"0002-site-Allow-specifying-var= iants-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 =20 @@ -52,7 +53,7 @@ =20 (define-record-type (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)) =20 (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: =20 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=E2=80=99s 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)) =20 (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' =E2=86=92 '~a'~%" (asset-source asset) --------------2.16.1-- --ve6txew4c6z4ngfu-- --ans5sheupsci6goz Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEwRjGsqAMqXB4uw3y3T6EbElHBVsFAlp4bc0ACgkQ3T6EbElH BVu15xAAtnJ2BGXo0IGon1a2Nq304ebekCbGWs4Khl+ioEIHoLzMk+eYLmPBneYu 6v6y11SZdU/RF6xlppsE9ZC1AWMeKCP9lsvaHrmgIf0QUiqTOvGsAzniAZtxqsqq 1ycIJ96QuhzK1c3dh9ohSGevZR6Ds6f8s6OVp5gQMskmF6jjP42agpny8QvdAgTB gZbJOCrOgW0RFCY0tdPca42HKEQf/mocV73SV21cGknWKglXDCKekGr3+KCUxBA1 4BRtdPftKwBv1PrBNoh/Ut7yI3rK3D0zB/NiLZtEKIfbrU+YhPI3suOM23FvxqR9 AFPpkqvpTS1ibGQNnAjXJRXdWyXNQcDN/skA1se0b/Hyxj9x/9c30gihjys7kDGA b08W22gw90VRSgSyF4bMmfvfik5qCiKWTB4Gi/4FZrS1Gv/1N7vGWnhaEw+UW0ga GCFpIhOrqyijAkx04ek9ScozBRGa2y6wis8FgQBcWLXNadnrbgzuty5loXRYfWaC 5+VQlQB/aPNmQhsDViyfHeld+bNU4KXApuI13YzYKPfkCED98OFohPn4SXiHrDtt bZMft87ugRGvZvLiXFByiW3f88QNqhBjLV+GA8GZ7xjV+CuR0Nm8BB0u9nVZpqDm VQSDVC2X9Cyc9n/Y95QsOWekl9ExBBhjLsvSGFXwp1bF8bNT2PY= =d1ge -----END PGP SIGNATURE----- --ans5sheupsci6goz--