initial import
src/i18n.lisp
Sun Apr 5 19:56:16 CEST 2009 Tobias Rautenkranz <tobias@rautenkranz.ch>
* initial import
--- old-qt.core/src/i18n.lisp 1970-01-01 01:00:00.000000000 +0100
+++ new-qt.core/src/i18n.lisp 2014-11-11 13:36:44.000000000 +0100
@@ -0,0 +1,42 @@
+(in-package :qt)
+
+(defun tr (message &optional context)
+ "Returns the translated MESSAGE for CONTEXT or
+a string STRING-EQUAL to MESSAGE when no translation was found.
+
+Translations can be loaded with WITH-TRANSLATOR."
+ (qt:core-application.translate (or context "") message))
+
+(defmacro with-installed-translator (translator &body body)
+ `(unwind-protect
+ (progn
+ (cxx:install-translator (qt:app) ,translator)
+ ,@body)
+ (cxx:remove-translator (qt:app) ,translator)))
+
+(defmacro with-translator (base-name &body body)
+ "Loads the translations in the BASE-NAME_LANGCODE.qm file.
+
+Must be in a WITH-APP."
+ (let ((translator (gensym)))
+ `(let ((,translator (make-instance 'translator)))
+ (unless (cxx:load ,translator (format nil "~A_~A"
+ ,base-name
+ (cxx:name (qt:locale.system))))
+ (cerror "Ignore" "Loading the translations ~A for ~A failed."
+ ,base-name (cxx:name (qt:locale.system))))
+ (with-installed-translator ,translator
+ ,@body))))
+
+(defmacro with-libqt-translator (&body body)
+ "Loads the translations for the Qt library.
+
+Must be in a WITH-APP."
+ (let ((translator (gensym)))
+ `(let ((,translator (make-instance 'translator)))
+ (unless (cxx:load ,translator (format nil "qt_~A"
+ (cxx:name (qt:locale.system)))
+ (qt:library-info.location qt:library-info.+translations-path+))
+ (cerror "Ignore" "Loading the Qt library translations failed."))
+ (with-installed-translator ,translator
+ ,@body))))