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

Reply via email to