From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Vivien Kraus Newsgroups: gmane.lisp.guile.user Subject: Static, pure Scheme internationalization Date: Sat, 21 Dec 2024 10:30:16 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="38614"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Evolution 3.48.4 To: Guile User Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Dec 21 10:31:16 2024 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tOvpM-0009u1-8C for guile-user@m.gmane-mx.org; Sat, 21 Dec 2024 10:31:16 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tOvop-0007Lh-MV; Sat, 21 Dec 2024 04:30:43 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tOvob-0007KX-GB for guile-user@gnu.org; Sat, 21 Dec 2024 04:30:36 -0500 Original-Received: from planete-kraus.eu ([2a00:5881:4008:2810::309]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1tOvoZ-0006CT-1X for guile-user@gnu.org; Sat, 21 Dec 2024 04:30:28 -0500 Original-Received: from planete-kraus.eu (localhost.lan [127.0.0.1]) by planete-kraus.eu (OpenSMTPD) with ESMTP id 6933b787 for ; Sat, 21 Dec 2024 09:30:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=planete-kraus.eu; h= message-id:subject:from:to:date:content-type :content-transfer-encoding:mime-version; s=albinoniB; bh=DkMVcsV vAvuSI5O+Ta/OAw3NIyo=; b=P+ymhCEh6hbkax82JNhf1ttHmqchBSxhGKVdF8e 5oe1rCPiblIz+y+yYJ+/wZ2KhlYQPU3rzrID/X664nYJAuRm600+uwsmijmbUwtn NX8HuZXtqdEnN+fb3Spw5Bh4gFp7IN7aRZ2FuTiZpgntEIQ/kJN2dkdPeFz4fCYi JeY0ozXCKhcwg8wIHKPs3XyD0qPzlPj02ELVVmmHSHUHQQALDv08JyCp4O8YWNt7 TXzgAFl34ffJTQ+0jif4OCQsThptwMT+ZdDm8wGveWYaRMI86QYhl7ZyD3MmeGdJ PG7Vp4U9JnNSnky31HfeXUvrtDimqmg0EU52vtuVNy8fAMg== Original-Received: by planete-kraus.eu (OpenSMTPD) with ESMTPSA id 6edd829e (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO) for ; Sat, 21 Dec 2024 09:30:18 +0000 (UTC) Received-SPF: pass client-ip=2a00:5881:4008:2810::309; envelope-from=vivien@planete-kraus.eu; helo=planete-kraus.eu X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.lisp.guile.user:20022 Archived-At: Dear Guile users, I am very excited about Hoot, but there is one aspect I was not satisfied with: internationalization. Since it is usually done with gettext, it requires a C library at run-time. Hoot programs can=E2=80=99t unfortunately use that. With your help, I managed to understand how I could rewrite code with macros. Thanks to this knowledge, I was able to create a small library for static and pure Scheme internationalization. It works like this (https://labo.planete-kraus.eu/guile-static-i18n.git/tree/example.scm): (define-module (example) #:use-module (static-i18n) #:declarative? #t #:export (main)) ;; We have to tell where the pot file lives at expansion time. (eval-when (expand) (project-pot-file (string-append (dirname (current-filename)) "/example.pot")) (project-po-directory (string-append (dirname (current-filename)) "/example-po"))) ;; collect-strings updates a PO template file, regenerates PO files, ;; and use them to provide translations for any calls to G_. (collect-strings ;; This is defined at the top-level. (define (main args) ;; current-locale-order is parameterized by a list of locale names ;; to try in order. (parameterize ((current-locale-order '("de" "fr" "en"))) ;; Note how you can use (G_ context message) to register a new ;; record, without having to call xgettext. (format #t (G_ "GREETING" "Hello, world!~%"))))) (main (command-line)) Once expanded, every call to G_ will have all possible translations compiled in, and the correct one will be chosen according to a list of preference for the user (a run-time Guile parameter). The big downside is, it doesn=E2=80=99t support plurals. However, I believe= it can be useful! https://labo.planete-kraus.eu/guile-static-i18n.git Best regards, Vivien