From mboxrd@z Thu Jan 1 00:00:00 1970 From: "pelzflorian (Florian Pelz)" Subject: Re: Website translation Date: Thu, 18 Jul 2019 17:08:36 +0200 Message-ID: <20190718150836.kzf2tmbtng5l42ta@pelzflorian.localdomain> References: <87sgri9b90.fsf@gnu.org> <20190707165722.we3q5jne7a3wnvq4@pelzflorian.localdomain> <878st932e4.fsf@dustycloud.org> <877e8owqkg.fsf@gnu.org> <20190712053539.htszj5w2b2sxws64@pelzflorian.localdomain> <875zo43dt2.fsf@gnu.org> <20190714142625.my2n7ypimctk3vbd@pelzflorian.localdomain> <87ims3o4tm.fsf@gnu.org> <20190715155414.y6lv45rv55ihvzs5@pelzflorian.localdomain> <87muhc8iqi.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="4rmdtqd7osjx7zsr" Content-Transfer-Encoding: 7bit Return-path: Received: from eggs.gnu.org ([2001:470:142:3::10]:41780) by lists.gnu.org with esmtp (Exim 4.86_2) (envelope-from ) id 1ho81R-0007Ep-SH for guix-devel@gnu.org; Thu, 18 Jul 2019 11:08:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ho81P-000647-Jt for guix-devel@gnu.org; Thu, 18 Jul 2019 11:08:41 -0400 Content-Disposition: inline In-Reply-To: <87muhc8iqi.fsf@gnu.org> 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: Ludovic =?utf-8?Q?Court=C3=A8s?= Cc: guix-devel@gnu.org, sirgazil , matias_jose_seco@autoproduzioni.net --4rmdtqd7osjx7zsr Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 17, 2019 at 11:16:21PM +0200, Ludovic Court=C3=A8s wrote: > I think we now have an overview of the possibilities (including maybe > =E2=80=98itstool=E2=80=99 that Ricardo mentions.) I=E2=80=99d say that= whoever is interested > should give it a try with what looks like the most promising approach > and report back with a prototype. :-) >=20 I tried to make gettext usable (not yet implementing any discussed approach), but it is a little rough: I tried using msgctxts. Sadly Guile is missing a pgettext function, I think. Should I use Guile=E2=80=99= s ffi? I think msgctxts could help with fragmentation, as I would prefer format strings with msgctxt over HTML-that-is-not-SHTML with itstool (I may misunderstand itstool though). sirgazil (Cc), long ago at you said you had written an interleave function for format strings. Do you have the code somewhere? I see in the commit log you are still actively working on the Guix website. Also, I believe this discussion is actually . Should I reference this thread there? Regards, Florian --4rmdtqd7osjx7zsr Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="0001-website-Use-needed-modules-in-posts.patch" >From f0bb0180dca729aa2c13f881780b279a08f9ea53 Mon Sep 17 00:00:00 2001 From: Florian Pelz Date: Thu, 18 Jul 2019 10:22:44 +0200 Subject: [PATCH 1/2] website: Use needed modules in posts. * website/posts/back-from-seagl-2018.sxml: Use needed modules. * website/posts/guix-at-libreplanet-2016.sxml: Use needed modules. --- website/posts/back-from-seagl-2018.sxml | 3 ++- website/posts/guix-at-libreplanet-2016.sxml | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/website/posts/back-from-seagl-2018.sxml b/website/posts/back-from-seagl-2018.sxml index c5ad0a9..958369f 100644 --- a/website/posts/back-from-seagl-2018.sxml +++ b/website/posts/back-from-seagl-2018.sxml @@ -1,6 +1,7 @@ (begin (use-modules (apps base templates components) - (srfi srfi-19)) + (apps base utils) + (srfi srfi-19)) `((title . "Back from SeaGL 2018") (author . "Chris Marusich") (date . ,(make-date 0 0 0 0 10 12 2018 -28800)) diff --git a/website/posts/guix-at-libreplanet-2016.sxml b/website/posts/guix-at-libreplanet-2016.sxml index 8581be4..252def3 100644 --- a/website/posts/guix-at-libreplanet-2016.sxml +++ b/website/posts/guix-at-libreplanet-2016.sxml @@ -1,5 +1,6 @@ (begin - (use-modules (srfi srfi-19)) + (use-modules (srfi srfi-19) + (apps base templates components)) `((title . "Guix at LibrePlanet 2016") (author . "David Thompson") (date unquote (make-date 0 0 0 0 15 3 2016 3600)) -- 2.22.0 --4rmdtqd7osjx7zsr Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: attachment; filename="0002-wip-website-Add-some-gettext-support.patch" Content-Transfer-Encoding: quoted-printable >From 5b84fb9d20668eb777832f88ad9bc0c8549e92d2 Mon Sep 17 00:00:00 2001 From: Florian Pelz Date: Thu, 18 Jul 2019 16:39:00 +0200 Subject: [PATCH 2/2] [wip] website: Add some gettext support. * website/apps/base/templates/home.scm (home-t): Mark two messages with G_ for testing. * website/po/POTFILES: New file; list the above file here. * website/po/guix-website.pot: New file; generated from the above. * website/po/de.po: New file. * website/po/LINGUAS: New file. Add linguas for testing. Currently their country code has to be specified too. * website/apps/i18n.scm: New file. Add utility functions. * website/haunt.scm: Load linguas and call each builder with each. * website/wip-howto-test-translation: New file with unfinished instructions. --- website/apps/base/templates/home.scm | 7 ++- website/apps/i18n.scm | 89 ++++++++++++++++++++++++++++ website/haunt.scm | 24 ++++++-- website/po/LINGUAS | 2 + website/po/POTFILES | 1 + website/po/de.po | 30 ++++++++++ website/po/guix-website.pot | 30 ++++++++++ website/wip-howto-test-translation | 27 +++++++++ 8 files changed, 201 insertions(+), 9 deletions(-) create mode 100644 website/apps/i18n.scm create mode 100644 website/po/LINGUAS create mode 100644 website/po/POTFILES create mode 100644 website/po/de.po create mode 100644 website/po/guix-website.pot create mode 100644 website/wip-howto-test-translation diff --git a/website/apps/base/templates/home.scm b/website/apps/base/tem= plates/home.scm index 5cb3bf5..0eb25a3 100644 --- a/website/apps/base/templates/home.scm +++ b/website/apps/base/templates/home.scm @@ -8,6 +8,7 @@ #:use-module (apps base types) #:use-module (apps base utils) #:use-module (apps blog templates components) + #:use-module (apps i18n) #:export (home-t)) =20 =20 @@ -37,9 +38,9 @@ (h2 (@ (class "a11y-offset")) "Summary") (ul (li - (b "Liberating.") - " Guix is an advanced - distribution of the " + (b (G_ "Liberating." "featured content")) + (G_ " Guix is an advanced + distribution of the " "featured content") ,(link-yellow #:label "GNU operating system" #:url (gnu-url "gnu/about-gnu.html")) diff --git a/website/apps/i18n.scm b/website/apps/i18n.scm new file mode 100644 index 0000000..54a975f --- /dev/null +++ b/website/apps/i18n.scm @@ -0,0 +1,89 @@ +;;; GNU Guix web site +;;; Copyright =A9 2019 Florian Pelz +;;; +;;; This file is part of the GNU Guix web site. +;;; +;;; The GNU Guix web site is free software; you can redistribute it and/= or modify it +;;; under the terms of the GNU Affero General Public License as publishe= d by +;;; the Free Software Foundation; either version 3 of the License, or (a= t +;;; your option) any later version. +;;; +;;; The GNU Guix web site is distributed in the hope that it will be use= ful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU Affero General Public License for more details. +;;; +;;; You should have received a copy of the GNU Affero General Public Lic= ense +;;; along with the GNU Guix web site. If not, see . + +(define-module (apps i18n) + #:use-module (haunt page) + #:use-module (haunt utils) + #:use-module (ice-9 match) + #:use-module (srfi srfi-1) + #:export (G_ + %current-lingua + builder->localized-builder + builders->localized-builders)) + +(define %gettext-domain + "guix-website") + +(bindtextdomain %gettext-domain (getcwd)) +(bind-textdomain-codeset %gettext-domain "UTF-8") +(textdomain %gettext-domain) + +(define* (G_ msg msgctxt) + (if msgctxt + (gettext (string-append msgctxt "|" msg) %gettext-domain) + (gettext msg %gettext-domain))) + +(define + (@@ (haunt page) )) + +(define %current-lingua + (make-fluid "en_US")) + +(define (first-value arg) + "For some reason the builder returned by static-directory returns +multiple values. This procedure is used to retain only the first +return value. TODO THIS SHOULD NOT BE NECESSARY I THINK" + arg) + +(define (builder->localized-builder builder lingua) + (compose + (lambda (pages) + (map + (lambda (page) + (match page + (($ file-name contents writer) + (if (string-suffix? ".html" file-name) + (let* ((base (string-drop-right + file-name + (string-length ".html"))) + (new-name (string-append base + "." + lingua + ".html"))) + (make-page new-name contents writer)) + page)) + (else page))) + pages)) + (lambda (site posts) + (begin + (setlocale LC_ALL (string-append lingua ".utf8")) + (with-fluid* + %current-lingua lingua + (lambda _ + (begin + (first-value (builder site posts))))))))) + +(define (builders->localized-builders builders linguas) + (flatten + (map-in-order + (lambda (builder) + (map-in-order + (lambda (lingua) + (builder->localized-builder builder lingua)) + linguas)) + builders))) diff --git a/website/haunt.scm b/website/haunt.scm index d29c0d4..eb0eafe 100644 --- a/website/haunt.scm +++ b/website/haunt.scm @@ -5,13 +5,23 @@ (use-modules ((apps base builder) #:prefix base:) ((apps blog builder) #:prefix blog:) ((apps download builder) #:prefix download:) + (apps i18n) ((apps packages builder) #:prefix packages:) (haunt asset) (haunt builder assets) (haunt reader) (haunt reader commonmark) - (haunt site)) + (haunt site) + (ice-9 rdelim) + (srfi srfi-1)) =20 +(define linguas + (with-input-from-file "po/LINGUAS" + (lambda _ + (let loop ((line (read-line))) + (if (eof-object? line) + '() + (cons line (loop (read-line)))))))) =20 (site #:title "GNU=A0Guix" #:domain (if (getenv "GUIX_WEB_SITE_INFO") @@ -19,8 +29,10 @@ "https://gnu.org/software/guix") #:build-directory "/tmp/gnu.org/software/guix" #:readers (list sxml-reader html-reader commonmark-reader) - #:builders (list base:builder - blog:builder - download:builder - packages:builder - (static-directory "static"))) + #:builders (builders->localized-builders + (list base:builder + blog:builder + download:builder + packages:builder + (static-directory "static")) + linguas)) diff --git a/website/po/LINGUAS b/website/po/LINGUAS new file mode 100644 index 0000000..782116d --- /dev/null +++ b/website/po/LINGUAS @@ -0,0 +1,2 @@ +de_DE +en_US diff --git a/website/po/POTFILES b/website/po/POTFILES new file mode 100644 index 0000000..0007797 --- /dev/null +++ b/website/po/POTFILES @@ -0,0 +1 @@ +apps/base/templates/home.scm diff --git a/website/po/de.po b/website/po/de.po new file mode 100644 index 0000000..3add92e --- /dev/null +++ b/website/po/de.po @@ -0,0 +1,30 @@ +# German translations for guix-website package. +# Copyright (C) 2019 Ludovic Court=E8s +# This file is distributed under the same license as the guix-website pa= ckage. +# Automatically generated, 2019. +# +msgid "" +msgstr "" +"Project-Id-Version: guix-website\n" +"Report-Msgid-Bugs-To: ludo@gnu.org\n" +"POT-Creation-Date: 2019-07-18 16:31+0200\n" +"PO-Revision-Date: 2019-07-18 16:33+0200\n" +"Last-Translator: Automatically generated\n" +"Language-Team: none\n" +"Language: de\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=3DUTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Plural-Forms: nplurals=3D2; plural=3D(n !=3D 1);\n" + +#: apps/base/templates/home.scm:41 +msgctxt "featured content" +msgid "Liberating." +msgstr "Befreiend." + +#: apps/base/templates/home.scm:42 +msgctxt "featured content" +msgid "" +" Guix is an advanced\n" +" distribution of the " +msgstr "Guix ist eine fortgeschrittene Distribution des " diff --git a/website/po/guix-website.pot b/website/po/guix-website.pot new file mode 100644 index 0000000..709077a --- /dev/null +++ b/website/po/guix-website.pot @@ -0,0 +1,30 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR Ludovic Court=E8s +# This file is distributed under the same license as the guix-website pa= ckage. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: guix-website\n" +"Report-Msgid-Bugs-To: ludo@gnu.org\n" +"POT-Creation-Date: 2019-07-18 16:31+0200\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"Language: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=3DUTF-8\n" +"Content-Transfer-Encoding: 8bit\n" + +#: apps/base/templates/home.scm:41 +msgctxt "featured content" +msgid "Liberating." +msgstr "" + +#: apps/base/templates/home.scm:42 +msgctxt "featured content" +msgid "" +" Guix is an advanced\n" +" distribution of the " +msgstr "" diff --git a/website/wip-howto-test-translation b/website/wip-howto-test-= translation new file mode 100644 index 0000000..f2f319b --- /dev/null +++ b/website/wip-howto-test-translation @@ -0,0 +1,27 @@ +To create a pot file: + +xgettext -f po/POTFILES -o po/guix-website.pot --from-code=3DUTF-8 --cop= yright-holder=3D"Ludovic Court=E8s" --package-name=3D"guix-website" --msg= id-bugs-address=3D"ludo@gnu.org" --keyword=3DG_:1,2c + +To create a po file from a pot file, do the usual: + +cd po +msginit -l de --no-translator + +To merge an existing po file with a new pot file: + +cd po +msgmerge -U de.po guix-website.pot + +To update mo files: + +mkdir -p de/LC_MESSAGES +cd po +msgfmt de.po +cd .. +mv po/messages.mo de/LC_MESSAGES/guix-website.mo + +To test: + +guix environment --ad-hoc haunt +GUILE_LOAD_PATH=3D$(guix build guile-syntax-highlight)/share/guile/site/= 2.2:$GUILE_LOAD_PATH GUIX_WEB_SITE_LOCAL=3Dyes haunt build +GUILE_LOAD_PATH=3D$(guix build guile-syntax-highlight)/share/guile/site/= 2.2:$GUILE_LOAD_PATH haunt serve --=20 2.22.0 --4rmdtqd7osjx7zsr--