Skip to content
Permalink
Browse files

Copy translation files while packaging and set path to translations

  • Loading branch information...
DamirPorobic committed Mar 24, 2019
1 parent 7ee2122 commit 68418e8641af50ea411620a509bd86e006cadb3a
Showing with 29 additions and 4 deletions.
  1. +8 −2 CMakeLists.txt
  2. +2 −0 ci/scripts/build.sh
  3. +16 −1 src/backend/TranslationLoader.cpp
  4. +3 −1 src/backend/TranslationLoader.h
@@ -7,7 +7,13 @@ endif()

set(KSNIP_VERSION "${PROJECT_VERSION}${KSNIP_VERSION_SUFIX}")

set(KSNIP_LANG_INSTAL_DIR "/usr/share/ksnip/translations")
if (WIN32)
set(KSNIP_LANG_INSTAL_DIR "translations")
elseif (APPLE)
set(KSNIP_LANG_INSTAL_DIR "../Resources")
elseif (UNIX)
set(KSNIP_LANG_INSTAL_DIR "/usr/share/ksnip/translations")
endif ()

configure_file(src/BuildConfig.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/BuildConfig.h)

@@ -23,7 +29,7 @@ set(QT_MIN_VERSION "5.6.1")

find_package(Qt5 ${QT_MIN_VERSION} REQUIRED Widgets Network Xml PrintSupport DBus)

if(WIN32)
if (WIN32)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED WinExtras)
elseif (UNIX AND NOT APPLE)
find_package(Qt5 ${QT_MIN_VERSION} REQUIRED X11Extras)
@@ -20,6 +20,7 @@ elif [[ "${BUILD_TYPE}" == "exe" ]]; then
mkdir packageDir
mv build/src/ksnip*.exe packageDir/ksnip.exe
windeployqt.exe packageDir/ksnip.exe
cp build/translations/ksnip_*.qm ./packageDir/translations/
7z a ksnip-${VERSION}-windows.zip ./packageDir/*
elif [[ "${BUILD_TYPE}" == "app" ]]; then
mkdir build && cd build
@@ -31,5 +32,6 @@ elif [[ "${BUILD_TYPE}" == "app" ]]; then
mkdir packageDir
mv build/src/ksnip*.app packageDir/ksnip.app
macdeployqt packageDir/ksnip.app
cp build/translations/ksnip_*.qm ./packageDir/ksnip.app/Contents/Resources/
sudo hdiutil create ksnip-${VERSION}.dmg -volname "Ksnip" -fs HFS+ -srcfolder packageDir/
fi
@@ -27,7 +27,11 @@ TranslationLoader::TranslationLoader()
void TranslationLoader::load(const QApplication &app) const
{
auto translator = new QTranslator();
auto translationSuccessfullyLoaded = loadTranslation(translator, mPathToTranslation);
auto translationSuccessfullyLoaded = loadTranslationFromAbsolutePath(translator);

if (!translationSuccessfullyLoaded) {
translationSuccessfullyLoaded = loadTranslationFromRelativePath(translator);
}

// Fix for appimages as they need to use relative paths
if (!translationSuccessfullyLoaded) {
@@ -41,6 +45,17 @@ void TranslationLoader::load(const QApplication &app) const
}
}

bool TranslationLoader::loadTranslationFromAbsolutePath(QTranslator *translator) const
{
return loadTranslation(translator, mPathToTranslation);
}

bool TranslationLoader::loadTranslationFromRelativePath(QTranslator *translator) const
{
auto relativePathToAppDir = QCoreApplication::applicationDirPath() + QStringLiteral("/");
return loadTranslation(translator, relativePathToAppDir + mPathToTranslation);
}

bool TranslationLoader::loadTranslationForAppImage(QTranslator *translator) const
{
auto relativePathToAppDir = QCoreApplication::applicationDirPath() + QStringLiteral("/../..");
@@ -35,8 +35,10 @@ class TranslationLoader
private:
QString mPathToTranslation;

bool loadTranslationFromAbsolutePath(QTranslator *translator) const;
bool loadTranslationFromRelativePath(QTranslator *translator) const;
bool loadTranslationForAppImage(QTranslator *translator) const;
bool loadTranslation(QTranslator *translator, const QString &path) const;
bool loadTranslationForAppImage(QTranslator *translator) const;
};

#endif //KSNIP_TRANSLATIONLOADER_H

0 comments on commit 68418e8

Please sign in to comment.
You can’t perform that action at this time.