This repository has been archived by the owner on Oct 30, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
No LXQt dependency is added. It remains a Qt only app. To update the translations set the CMake command line option UPDATE_TRANSLATIONS to true. Ex: cmake -DUPDATE_TRASNLATIONS=ON .. The translations will be extracted and also compiled. To return to the compilation only mode just set the UPDATE_TRANSLATIONS option to false. Ex: cmake -DCMAKE_UPDATE_TRANSLATIONS=OFF .. Warning: When UPDATE_TRANSLATIONS is enabled a clean command will also clean the generated .ts files. The CLEAN_NO_CUSTOM property should solve that problem. But it didn't, at least for now. So, after updating the translations, disable UPDATE_TRANSLATIONS right away. The .desktop files translatable bits are now split by language in the translations directory. screengrab.desktop.in holds the non-common, not translatable parts. The LXQtTranslateDesktop.cmake module glues it all, so only one file (screengrab.desktop) is installed. The Qt5TranslationLoader.cmake module takes care of automatically produce code to load the translations.
- Loading branch information
1 parent
2f59a23
commit f20cbb4
Showing
11 changed files
with
364 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
#============================================================================= | ||
# The lxqt_translate_desktop() function was copied from the the | ||
# LXQt LxQtTranste.cmake | ||
# | ||
# Original Author: Alexander Sokolov <sokoloff.a@gmail.com> | ||
# | ||
#============================================================================= | ||
|
||
function(lxqt_translate_desktop _RESULT) | ||
set(_translationDir "translations") | ||
|
||
# Parse arguments *************************************** | ||
set(_state "") | ||
foreach (_arg ${ARGN}) | ||
if ( | ||
("${_arg}_I_HATE_CMAKE" STREQUAL "SOURCES_I_HATE_CMAKE") OR | ||
("${_arg}_I_HATE_CMAKE" STREQUAL "TRANSLATION_DIR_I_HATE_CMAKE") | ||
) | ||
|
||
set(_state ${_arg}) | ||
|
||
else() | ||
if("${_state}" STREQUAL "SOURCES") | ||
get_filename_component (__file ${_arg} ABSOLUTE) | ||
set(_sources ${_sources} ${__file}) | ||
#set(_sources ${_sources} ${_arg}) | ||
|
||
elseif("${_state}" STREQUAL "TRANSLATION_DIR") | ||
set(_translationDir ${_arg}) | ||
set(_state "") | ||
|
||
else() | ||
MESSAGE(FATAL_ERROR | ||
"Unknown argument '${_arg}'.\n" | ||
"See ${CMAKE_CURRENT_LIST_FILE} for more information.\n" | ||
) | ||
endif() | ||
endif() | ||
endforeach(_arg) | ||
|
||
get_filename_component (_translationDir ${_translationDir} ABSOLUTE) | ||
|
||
foreach (_inFile ${_sources}) | ||
get_filename_component(_inFile ${_inFile} ABSOLUTE) | ||
get_filename_component(_fileName ${_inFile} NAME_WE) | ||
#Extract the real extension ............ | ||
get_filename_component(_fileExt ${_inFile} EXT) | ||
string(REPLACE ".in" "" _fileExt ${_fileExt}) | ||
#....................................... | ||
set(_outFile "${CMAKE_CURRENT_BINARY_DIR}/${_fileName}${_fileExt}") | ||
|
||
file(GLOB _translations | ||
${_translationDir}/${_fileName}_*${_fileExt} | ||
${_translationDir}/local/${_fileName}_*${_fileExt} | ||
) | ||
|
||
set(_pattern "'\\[.*]\\s*='") | ||
if (_translations) | ||
add_custom_command(OUTPUT ${_outFile} | ||
COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile} | ||
COMMAND grep --no-filename ${_pattern} ${_translations} >> ${_outFile} | ||
COMMENT "Generating ${_fileName}${_fileExt}" | ||
) | ||
else() | ||
add_custom_command(OUTPUT ${_outFile} | ||
COMMAND grep -v "'#TRANSLATIONS_DIR='" ${_inFile} > ${_outFile} | ||
COMMENT "Generating ${_fileName}${_fileExt}" | ||
) | ||
endif() | ||
|
||
set(__result ${__result} ${_outFile}) | ||
|
||
|
||
# TX file *********************************************** | ||
set(_txFile "${CMAKE_BINARY_DIR}/tx/${_fileName}${_fileExt}.tx.sh") | ||
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _tx_translationDir ${_translationDir}) | ||
string(REPLACE "${CMAKE_SOURCE_DIR}/" "" _tx_inFile ${_inFile}) | ||
string(REPLACE "." "" _fileType ${_fileExt}) | ||
|
||
file(WRITE ${_txFile} | ||
"[ -f ${_inFile} ] || exit 0\n" | ||
"echo '[lxde-qt.${_fileName}_${_fileType}]'\n" | ||
"echo 'type = DESKTOP'\n" | ||
"echo 'source_lang = en'\n" | ||
"echo 'source_file = ${_tx_inFile}'\n" | ||
"echo 'file_filter = ${_tx_translationDir}/${_fileName}_<lang>${_fileExt}'\n" | ||
"echo ''\n" | ||
) | ||
|
||
endforeach() | ||
|
||
set(${_RESULT} ${__result} PARENT_SCOPE) | ||
endfunction(lxqt_translate_desktop) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
#============================================================================= | ||
# Copyright 2014 Luís Pereira <luis.artur.pereira@gmail.com> | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# 1. Redistributions of source code must retain the copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# 3. The name of the author may not be used to endorse or promote products | ||
# derived from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
#============================================================================= | ||
# | ||
# funtion lxqt_translate_ts(qmFiles | ||
# [USE_QT5 [Yes | No]] | ||
# [UPDATE_TRANSLATIONS [Yes | No]] | ||
# SOURCES <sources> | ||
# [TEMPLATE] translation_template | ||
# [TRANSLATIONS_DIRECTORY] translation_directory | ||
# [INSTALL_DIR] install_directory | ||
# ) | ||
# Output: | ||
# qmFiles The generated compiled translations (.qm) files | ||
# | ||
# Input: | ||
# USE_QT5 Optional flag to choose between Qt4 and Qt5. Defaults to Qt5 | ||
# | ||
# UPDATE_TRANSLATIONS Optional flag. Setting it to Yes, extracts and | ||
# compiles the translations. Setting it No, only | ||
# compiles them. | ||
# | ||
# TEMPLATE Optional translations files base name. Defaults to | ||
# ${PROJECT_NAME}. An .ts extensions is added. | ||
# | ||
# TRANSLATIONS_DIR Optional path to the directory with the .ts files, | ||
# relative to the CMakeList.txt. Defaults to | ||
# "translations". | ||
# | ||
# INSTALL_DIR Optional destination of the file compiled files (qmFiles). | ||
# If not present no installation is performed | ||
|
||
|
||
|
||
# CMake v2.8.3 needed to use the CMakeParseArguments module | ||
cmake_minimum_required(VERSION 2.8.3 FATAL_ERROR) | ||
|
||
|
||
function(lxqt_translate_ts qmFiles) | ||
set(oneValueArgs USE_QT5 UPDATE_TRANSLATIONS TEMPLATE TRANSLATION_DIR INSTALL_DIR) | ||
set(multiValueArgs SOURCES) | ||
cmake_parse_arguments(TR "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) | ||
|
||
if (NOT DEFINED TR_UPDATE_TRANSLATIONS) | ||
set(TR_UPDATE_TRANSLATIONS "No") | ||
endif() | ||
|
||
if (NOT DEFINED TR_USE_QT5) | ||
set(TR_USE_QT5 "Yes") | ||
endif() | ||
|
||
if(NOT DEFINED TR_TEMPLATE) | ||
set(TR_TEMPLATE "${PROJECT_NAME}") | ||
endif() | ||
|
||
if (NOT DEFINED TR_TRANSLATION_DIR) | ||
set(TR_TRANSLATION_DIR "translations") | ||
endif() | ||
|
||
file(GLOB tsFiles "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}_*.ts") | ||
set(templateFile "${TR_TRANSLATION_DIR}/${TR_TEMPLATE}.ts") | ||
|
||
if(TR_USE_QT5) | ||
# Qt5 | ||
if (TR_UPDATE_TRANSLATIONS) | ||
qt5_create_translation(QMS | ||
${TR_SOURCES} | ||
${templateFile} | ||
OPTIONS -locations absolute | ||
) | ||
qt5_create_translation(QM | ||
${TR_SOURCES} | ||
${tsFiles} | ||
OPTIONS -locations absolute | ||
) | ||
else() | ||
qt5_add_translation(QM ${tsFiles}) | ||
endif() | ||
else() | ||
# Qt4 | ||
if(TR_UPDATE_TRANSLATIONS) | ||
qt4_create_translation(QMS | ||
${TR_SOURCES} | ||
${templateFile} | ||
OPTIONS -locations absolute | ||
) | ||
qt4_create_translation(QM | ||
${TR_SOURCES} | ||
${tsFiles} | ||
OPTIONS -locations absolute | ||
) | ||
else() | ||
qt4_add_translation(QM ${tsFiles}) | ||
endif() | ||
endif() | ||
|
||
if(TR_UPDATE_TRANSLATIONS) | ||
add_custom_target("update_${TR_TEMPLATE}_ts" ALL DEPENDS ${QMS}) | ||
endif() | ||
|
||
if(DEFINED TR_INSTALL_DIR) | ||
install(FILES ${QM} DESTINATION ${TR_INSTALL_DIR}) | ||
endif() | ||
|
||
set(${qmFiles} ${QM} PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#============================================================================= | ||
# Copyright 2014 Luís Pereira <luis.artur.pereira@gmail.com> | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# 1. Redistributions of source code must retain the copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# 3. The name of the author may not be used to endorse or promote products | ||
# derived from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
#============================================================================= | ||
# | ||
# These functions enables "automatic" translation loading in Qt5 apps | ||
# and libs. They generate a .cpp file that takes care of everything. The | ||
# user doesn't have to do anything in the source code. | ||
# | ||
# qt5_translation_loader(<source_files> <translations_dir> <catalog_name>) | ||
# | ||
# Output: | ||
# <source_files> Appends the generated file to this variable. | ||
# | ||
# Input: | ||
# <translations_dir> Full path name to the translations dir. | ||
# <catalog_name> Translation catalog to be loaded. | ||
|
||
set(__CURRENT_DIR ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
function(qt5_translation_loader source_files translations_dir catalog_name) | ||
configure_file( | ||
${__CURRENT_DIR}/Qt5TranslationLoader.cpp.in | ||
Qt5TranslationLoader.cpp @ONLY | ||
) | ||
set(${source_files} ${${source_files}} ${CMAKE_CURRENT_BINARY_DIR}/Qt5TranslationLoader.cpp PARENT_SCOPE) | ||
endfunction() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* This file has been generated by the CMake qt_translation_loader(). | ||
* It loads Qt application translations. | ||
* | ||
* Attention: All changes will be overwritten!!! | ||
*/ | ||
|
||
#include <QCoreApplication> | ||
#include <QLocale> | ||
#include <QTranslator> | ||
#include <QLibraryInfo> | ||
|
||
static void loadQtTranslation() | ||
{ | ||
QString locale = QLocale::system().name(); | ||
QTranslator *qtTranslator = new QTranslator(qApp); | ||
|
||
if (qtTranslator->load("qt_" + locale, QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { | ||
qApp->installTranslator(qtTranslator); | ||
} else { | ||
delete qtTranslator; | ||
} | ||
|
||
QTranslator *appTranslator = new QTranslator(qApp); | ||
if (appTranslator->load(QString("@translations_dir@/@catalog_name@_%1.qm").arg(locale))) { | ||
QCoreApplication::installTranslator(appTranslator); | ||
} else if (locale == QLatin1String("C") || | ||
locale.startsWith(QLatin1String("en"))) { | ||
// English is the default. It's translated anyway. | ||
delete appTranslator; | ||
} | ||
} | ||
|
||
Q_COREAPP_STARTUP_FUNCTION(loadQtTranslation) |
Oops, something went wrong.