unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* Static, pure Scheme internationalization
@ 2024-12-21  9:30 Vivien Kraus
  2024-12-21 11:18 ` Nala Ginrut
  0 siblings, 1 reply; 9+ messages in thread
From: Vivien Kraus @ 2024-12-21  9:30 UTC (permalink / raw)
  To: Guile User

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



^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-12-21 18:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-21  9:30 Static, pure Scheme internationalization Vivien Kraus
2024-12-21 11:18 ` 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

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).