Commit 4d6f5b34 authored by Albert  Babí Oller's avatar Albert Babí Oller Committed by Amin Bandali

translations: revise access to translations for GNU/Linux

- correct translations (.qm) install path for cmake
- use JAMI_INSTALL_PREFIX to fetch translations
- create "share/ring/translations" inside build dir to store .qm files

Change-Id: I127cbad1d4b00a628d79e9654ed471f456a550e8
parent af14a4a8
......@@ -209,7 +209,7 @@ add_executable(${PROJECT_NAME}
${QML_RESOURCES_QML}
${LRC_SRC_PATH}/webresource.qrc)
set(JAMI_DATA_PATH "${CMAKE_INSTALL_PREFIX}/share/${PROJECT_NAME}")
set(JAMI_DATA_PREFIX "${CMAKE_INSTALL_PREFIX}/share")
find_library(ringclient ringclient ${LRCLIBDIR} NO_DEFAULT_PATH)
find_library(qrencode qrencode)
......@@ -233,13 +233,13 @@ install(TARGETS jami-qt
# install .desktop in XDG desktop dir so that it is recognized by the system
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/applications)
DESTINATION ${JAMI_DATA_PREFIX}/applications)
# install .desktop in the jami-qt data dir, so that it can be copied to the
# autostart dir by the client
install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
DESTINATION
${JAMI_DATA_PATH}
"${JAMI_DATA_PREFIX}/${PROJECT_NAME}"
PERMISSIONS
WORLD_READ
OWNER_WRITE
......@@ -247,16 +247,16 @@ install(FILES ${PROJECT_SOURCE_DIR}/jami-qt.desktop
GROUP_READ
)
# adjust JAMI_DATA_PATH for snap package
# adjust JAMI_DATA_PREFIX for snap package
# (this must come after all 'install' commands that refer to
# JAMI_DATA_PATH; the following value is not meant to be used for
# JAMI_DATA_PREFIX; the following value is not meant to be used for
# any install destinations)
if(DEFINED ENV{SNAPCRAFT_PROJECT_NAME})
set(JAMI_DATA_PATH "/snap/$ENV{SNAPCRAFT_PROJECT_NAME}/current/usr/share/${PROJECT_NAME}")
set(JAMI_DATA_PREFIX "/snap/$ENV{SNAPCRAFT_PROJECT_NAME}/current/usr/share")
endif()
# (this must come after the above adjustment to JAMI_DATA_PATH)
target_compile_definitions(jami-qt PRIVATE JAMI_DATA_DIR="${JAMI_DATA_PATH}")
# (this must come after the above adjustment to JAMI_DATA_PREFIX)
target_compile_definitions(jami-qt PRIVATE JAMI_INSTALL_PREFIX="${JAMI_DATA_PREFIX}")
# logos
install(FILES images/jami.svg
......@@ -309,11 +309,13 @@ endif()
# translations
if(Qt5LinguistTools_FOUND)
message("Releasing and copying translation files")
file(MAKE_DIRECTORY "${CMAKE_BINARY_DIR}/share/ring/translations/")
file(GLOB TS_FILES ${PROJECT_SOURCE_DIR}/translations/*.ts)
set_source_files_properties(${TS_FILES} PROPERTIES OUTPUT_LOCATION "share/ring/translations")
qt5_add_translation(QM_FILES ${TS_FILES})
add_custom_target(translations ALL DEPENDS ${QM_FILES})
install(FILES ${QM_FILES}
DESTINATION "${CMAKE_INSTALL_PREFIX}/share/libringclient/translations")
install(DIRECTORY "${CMAKE_BINARY_DIR}/share/ring/translations/"
DESTINATION ${CMAKE_INSTALL_PREFIX}/share/ring/translations)
endif()
# uninstall
......
......@@ -218,9 +218,14 @@ MainApplication::init()
void
MainApplication::loadTranslations()
{
auto appDir = qApp->applicationDirPath() + "/";
const auto locale_name = QLocale::system().name();
const auto locale_lang = locale_name.split('_')[0];
#if defined(Q_OS_LINUX) && defined(JAMI_INSTALL_PREFIX)
QString appDir = JAMI_INSTALL_PREFIX;
#else
QString appDir = qApp->applicationDirPath() + QDir::separator() + "share";
#endif
QString locale_name = QLocale::system().name();
QString locale_lang = locale_name.split('_')[0];
QTranslator* qtTranslator_lang = new QTranslator(this);
QTranslator* qtTranslator_name = new QTranslator(this);
......@@ -236,22 +241,40 @@ MainApplication::loadTranslations()
QTranslator* lrcTranslator_lang = new QTranslator(this);
QTranslator* lrcTranslator_name = new QTranslator(this);
if (locale_name != locale_lang) {
if (lrcTranslator_lang->load(appDir + "share/libringclient/translations/lrc_" + locale_lang))
if (lrcTranslator_lang->load(appDir
+ QDir::separator() + "libringclient"
+ QDir::separator() + "translations"
+ QDir::separator() + "lrc_"
+ locale_lang)) {
installTranslator(lrcTranslator_lang);
}
}
if (lrcTranslator_name->load(appDir + "share/libringclient/translations/lrc_" + locale_name))
if (lrcTranslator_name->load(appDir
+ QDir::separator() + "libringclient"
+ QDir::separator() + "translations"
+ QDir::separator() + "lrc_"
+ locale_name)) {
installTranslator(lrcTranslator_name);
}
QTranslator* mainTranslator_lang = new QTranslator(this);
QTranslator* mainTranslator_name = new QTranslator(this);
if (locale_name != locale_lang) {
if (mainTranslator_lang->load(appDir + "share/ring/translations/ring_client_windows_"
+ locale_lang))
if (mainTranslator_lang->load(appDir
+ QDir::separator() + "ring"
+ QDir::separator() + "translations"
+ QDir::separator() + "ring_client_windows_"
+ locale_lang)) {
installTranslator(mainTranslator_lang);
}
}
if (mainTranslator_name->load(appDir + "share/ring/translations/ring_client_windows_"
+ locale_name))
if (mainTranslator_name->load(appDir
+ QDir::separator() + "ring"
+ QDir::separator() + "translations"
+ QDir::separator() + "ring_client_windows_"
+ locale_name)) {
installTranslator(mainTranslator_name);
}
}
void
......
......@@ -70,15 +70,15 @@ Utils::CreateStartupLink(const std::wstring& wstrAppName)
return Utils::CreateLink(programPath.c_str(), linkPath.c_str());
#else
QString desktopPath;
/* cmake should set JAMI_DATA_DIR, otherwise it checks the following dirs
/* cmake should set JAMI_INSTALL_PREFIX, otherwise it checks the following dirs
* - /usr/<data dir>
* - /usr/local/<data dir>
* - default install data dir
*/
#ifdef JAMI_DATA_DIR
desktopPath = JAMI_DATA_DIR;
desktopPath += "/jami-qt.desktop";
#ifdef JAMI_INSTALL_PREFIX
desktopPath = JAMI_INSTALL_PREFIX;
desktopPath += "/jami-qt/jami-qt.desktop";
#else
desktopPath = "share/jami-qt/jami-qt.desktop";
QStringList paths = {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment