Updates translations installation and search paths
authorLuís Pereira <luis.artur.pereira@gmail.com>
Thu, 9 Oct 2014 15:31:09 +0000 (08:31 -0700)
committerLuís Pereira <luis.artur.pereira@gmail.com>
Thu, 9 Oct 2014 15:31:09 +0000 (08:31 -0700)
liblxqt translations paths are relative to ${LXQT_TRANSLATIONS_DIR}.
liblxqt translations are installed to liblxqt/

Translations base search paths are:
LXQT_SHARE_TRANSLATIONS_DIR
        XdgDirs::dataDirs(LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR)
in that order.

For each directory in the base search path, the translation file, is first
searched inside a directory with the name of the app or library (without
version suffix) then in the base search path directory. Ex:
/usr/share/lxqt-qt5/translations/liblxqt/
/usr/share/lxqt-qt5/translations

LxQt::Translator class can be used to load the applications translations.
That would ditch the TRANSLATE_APP macro, that we use in each executable,
thus reducing resource consumption.

CMakeLists.txt
cmake/lxqtX-config.cmake.in
cmake/lxqt_use.cmake.in
lxqttranslator.cpp

index 6d02a99..7f409d8 100644 (file)
@@ -205,8 +205,10 @@ include(GNUInstallDirs)
 
 set(LXQT_VERSION ${LXQT_MAJOR_VERSION}.${LXQT_MINOR_VERSION}.${LXQT_PATCH_VERSION})
 set(LXQT_LIBRARY_NAME "lxqt${LXQT_QT_VERSION_SUFFIX}")
-set(LXQT_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/share/${LXQT_LIBRARY_NAME})
-set(LXQT_TRANSLATIONS_DIR ${LXQT_SHARE_DIR}/translations)
+set(LXQT_RELATIVE_SHARE_DIR "${LXQT_LIBRARY_NAME}")
+set(LXQT_SHARE_DIR ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_DATAROOTDIR}/${LXQT_RELATIVE_SHARE_DIR})
+set(LXQT_RELATIVE_TRANSLATIONS_DIR "${LXQT_LIBRARY_NAME}/translations")
+set(LXQT_TRANSLATIONS_DIR "${LXQT_SHARE_DIR}/translations")
 
 set(LXQT_INTREE_INCLUDE_DIR     ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/include)
 set(LXQT_INTREE_TARGETS_FILE    ${CMAKE_BINARY_DIR}/${LXQT_LIBRARY_NAME}-targets.cmake)
@@ -359,7 +361,7 @@ endif()
 
 install(FILES ${INTREE_PORTABLE_HEADERS} DESTINATION ${LXQT_INSTALL_INCLUDE_DIR}/LXQt)
 
-install(FILES ${QM_FILES} DESTINATION ${LXQT_TRANSLATIONS_DIR})
+install(FILES ${QM_FILES} DESTINATION ${LXQT_TRANSLATIONS_DIR}/liblxqt)
 
 #************************************************
 # Create pkgconfig file
index 2b12071..fb74275 100644 (file)
@@ -58,7 +58,9 @@ set(LXQT_MINOR_VERSION      @LXQT_MINOR_VERSION@)
 set(LXQT_PATCH_VERSION      @LXQT_PATCH_VERSION@)
 set(LXQT_VERSION            @LXQT_VERSION@)
 
+set(LXQT_RELATIVE_SHARE_DIR @LXQT_RELATIVE_SHARE_DIR@)
 set(LXQT_SHARE_DIR          @LXQT_SHARE_DIR@)
+set(LXQT_RELATIVE_TRANSLATIONS_DIR   @LXQT_RELATIVE_TRANSLATIONS_DIR@)
 set(LXQT_TRANSLATIONS_DIR   @LXQT_TRANSLATIONS_DIR@)
 set(LXQT_ETC_XDG_DIR        @LXQT_ETC_XDG_DIR@)
 
index bd26f24..dabc604 100644 (file)
@@ -55,7 +55,10 @@ include_directories(${LXQT_INCLUDE_DIRS})
 link_directories(${LXQT_LIBRARY_DIRS})
 
 #cmake_policy(SET CMP0005 NEW)
+add_definitions(-DLXQT_RELATIVE_SHARE_DIR=\"${LXQT_RELATIVE_SHARE_DIR}\")
 add_definitions(-DLXQT_SHARE_DIR=\"${LXQT_SHARE_DIR}\")
+add_definitions(-DLXQT_RELATIVE_SHARE_TRANSLATIONS_DIR=\"${LXQT_RELATIVE_TRANSLATIONS_DIR}\")
+add_definitions(-DLXQT_SHARE_TRANSLATIONS_DIR=\"${LXQT_TRANSLATIONS_DIR}\")
 add_definitions(-DLXQT_ETC_XDG_DIR=\"${LXQT_ETC_XDG_DIR}\")
 add_definitions(-DLXQT_VERSION=\"${LXQT_VERSION}\")
 
index d7c6502..1a76c9e 100644 (file)
@@ -5,6 +5,7 @@
 #include <QCoreApplication>
 #include <QLibraryInfo>
 #include <QStringList>
+#include <QStringBuilder>
 #include <QFileInfo>
 
 #include <XdgDirs>
@@ -21,10 +22,9 @@ QStringList *getSearchPaths()
     if (searchPath == 0)
     {
         searchPath = new QStringList();
-        *searchPath << XdgDirs::dataHome(false) + "/lxqt/translations";
-        *searchPath << XdgDirs::dataDirs("/lxqt/translations");
-        *searchPath << "/usr/local/share/lxqt/translations";
-        *searchPath << "/usr/share/lxqt/translations";
+        *searchPath << QString(LXQT_SHARE_TRANSLATIONS_DIR);
+        *searchPath << XdgDirs::dataDirs(LXQT_RELATIVE_SHARE_TRANSLATIONS_DIR);
+        searchPath->removeDuplicates();
     }
 
     return searchPath;
@@ -62,18 +62,25 @@ bool translate(const QString &name)
     QStringList *paths = getSearchPaths();
     foreach(QString path, *paths)
     {
-        if (appTranslator->load(name + "_" + locale, path))
-        {
-            QCoreApplication::installTranslator(appTranslator);
-            return true;
-        }
-        else if (locale == QLatin1String("C") ||
-                    locale.startsWith(QLatin1String("en")))
+        QStringList subPaths;
+        subPaths << path % QChar('/') % name;
+        subPaths << path;
+
+        foreach(QString p, subPaths)
         {
-            // English is the default. Even if there isn't an translation file,
-            // we return true. It's translated anyway.
-            delete appTranslator;
-            return true;
+            if (appTranslator->load(name + "_" + locale, p))
+            {
+                QCoreApplication::installTranslator(appTranslator);
+                return true;
+            }
+            else if (locale == QLatin1String("C") ||
+                        locale.startsWith(QLatin1String("en")))
+            {
+                // English is the default. Even if there isn't an translation
+                // file, we return true. It's translated anyway.
+                delete appTranslator;
+                return true;
+            }
         }
     }