(in-package :cl-smoke.qt.core) (defun qt: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 qt:with-translator ((base-name &rest paths) &body body) "Loads the translations in the BASE-NAME_LANGCODE.qm file; searching PATHS. Must be in a WITH-APP." (let ((translator (gensym))) `(let ((,translator (make-instance 'qt:translator))) (unless (find-if #'(lambda (path) (cxx:load ,translator (format nil "~A_~A" ,base-name (cxx:name (qt:locale.system))) (namestring path))) (list ,@paths)) (cerror "Ignore" "Loading the translations ~A for ~A failed." ,base-name (cxx:name (qt:locale.system)))) (with-installed-translator ,translator ,@body)))) (defmacro qt: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 'qt: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)))) (defun qt:search-file (name &rest paths) "Searches the file NAME in PATHS and returns its path." (let ((file-path (find-if #'(lambda (path) (probe-file (merge-pathnames name path))) paths))) (unless file-path (error "The file ~S not found in the paths ~S" name paths)) (merge-pathnames name file-path)))