From: Vivien Kraus <vivien@planete-kraus.eu>
To: Guile User <guile-user@gnu.org>
Subject: Static, pure Scheme internationalization
Date: Sat, 21 Dec 2024 10:30:16 +0100 [thread overview]
Message-ID: <a841daffe1287658fd73e447af16739294889176.camel@planete-kraus.eu> (raw)
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’t
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’t support plurals. However, I believe it
can be useful!
https://labo.planete-kraus.eu/guile-static-i18n.git
Best regards,
Vivien
next reply other threads:[~2024-12-21 9:30 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-21 9:30 Vivien Kraus [this message]
2024-12-21 11:18 ` Static, pure Scheme internationalization Nala Ginrut
2024-12-21 11:46 ` Vivien Kraus
2024-12-21 12:14 ` Nala Ginrut
2024-12-21 12:36 ` Nala Ginrut
2024-12-21 14:15 ` Vivien Kraus
2024-12-21 14:18 ` Nala Ginrut
2024-12-21 14:31 ` Vivien Kraus
2024-12-21 18:27 ` Nala Ginrut
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
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a841daffe1287658fd73e447af16739294889176.camel@planete-kraus.eu \
--to=vivien@planete-kraus.eu \
--cc=guile-user@gnu.org \
/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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).