rotatef/gettext

Feedback and thanks

vindarel opened this issue · 0 comments

Hi, thanks for the library. After a few attempts, we got i18n support in our web app, integrated with Djula templates.

Since it was difficult for me to do, I'd like to give a feedback and an example.

The PR is visible here: https://gitlab.com/myopenbookstore/openbookstore/-/merge_requests/19

Utilities: https://gitlab.com/myopenbookstore/openbookstore/-/blob/master/src/i18n.lisp for instance:

  • clear the catalogue for development
  • see the list of loaded message for a specific locale
  • list loaded locales
  • set the locale (with a couple checks)
  • with-locale macro

credit goes to @fstamour

I'll write more about the process if and when I can.

Best,


(defun list-loaded-locales ()
  "Get the list of locales loaded in gettext's cache."
  (remove-duplicates
   (mapcar #'first
           (alexandria:hash-table-keys
            gettext::*catalog-cache*))
   :test #'string=))


;; Only preload the translations into the image if we're not deployed yet.
(unless (deploy:deployed-p)
  (format *debug-io* "~%Reading all *.mo files...")
  (gettext:preload-catalogs
   ;; Tell gettext where to find the .mo files
   #.(asdf:system-relative-pathname :bookshops "locale/")))


;; Run this when developping to reload the translations
#+ (or)
(progn
  ;; Clear gettext's cache
  (clrhash gettext::*catalog-cache*)
  (gettext:preload-catalogs
   ;; Tell gettext where to find the .mo files
   #.(asdf:system-relative-pathname :bookshops "locale/")))


;; Run this to see the list of loaded message for a specific locale
#+ (or)
(gettext::catalog-messages
 (gethash '("fr_fr" :LC_MESSAGES "bookshops")
	  gettext::*catalog-cache*))


;; Test the translation of a string
#+ (or)
(with-locale ("fr_fr")
  (_ "Please login to continue"))