mirror of
https://github.com/tomahawk-player/tomahawk.git
synced 2025-08-05 05:37:29 +02:00
Include Qt translations
This commit is contained in:
@@ -1,25 +1,48 @@
|
|||||||
FILE (GLOB TS_FILES ${CMAKE_SOURCE_DIR}/lang/*.ts)
|
macro(add_tomahawk_translations language)
|
||||||
QT4_ADD_TRANSLATION(QM_FILES ${TS_FILES})
|
list(APPEND TOMAHAWK_LANGUAGES ${ARGV})
|
||||||
|
|
||||||
## HACK HACK HACK - around rcc limitations to allow out of source-tree building
|
set(tomahawk_i18n_qrc_content "<!DOCTYPE RCC><RCC version=\"1.0\">\n")
|
||||||
SET( trans_file tomahawk_i18n )
|
|
||||||
SET( trans_srcfile ${CMAKE_SOURCE_DIR}/lang/${trans_file}.qrc)
|
|
||||||
SET( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc)
|
|
||||||
SET( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx)
|
|
||||||
|
|
||||||
# Copy the QRC file to the output directory
|
# tomahawk and qt language files
|
||||||
ADD_CUSTOM_COMMAND(
|
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<qresource prefix=\"/lang\">\n")
|
||||||
OUTPUT ${trans_infile}
|
foreach(lang ${TOMAHAWK_LANGUAGES})
|
||||||
COMMAND ${CMAKE_COMMAND} -E copy ${trans_srcfile} ${trans_infile}
|
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<file>tomahawk_${lang}.qm</file>\n")
|
||||||
MAIN_DEPENDENCY ${trans_srcfile}
|
if(NOT lang STREQUAL "en" AND EXISTS ${QT_TRANSLATIONS_DIR}/qt_${lang}.qm)
|
||||||
)
|
file(COPY ${QT_TRANSLATIONS_DIR}/qt_${lang}.qm DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<file>qt_${lang}.qm</file>\n")
|
||||||
|
endif()
|
||||||
|
|
||||||
# Run the resource compiler (rcc_options should already be set)
|
# build explicitly enabled languages
|
||||||
ADD_CUSTOM_COMMAND(
|
list(APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/tomahawk_${lang}.ts")
|
||||||
OUTPUT ${trans_outfile}
|
endforeach()
|
||||||
COMMAND ${QT_RCC_EXECUTABLE}
|
|
||||||
ARGS ${rcc_options} -name ${trans_file} -o ${trans_outfile} ${trans_infile}
|
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}</qresource>\n")
|
||||||
MAIN_DEPENDENCY ${trans_infile}
|
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}</RCC>\n")
|
||||||
DEPENDS ${QM_FILES}
|
|
||||||
)
|
file(WRITE ${CMAKE_BINARY_DIR}/lang/tomahawk_i18n.qrc "${tomahawk_i18n_qrc_content}" )
|
||||||
|
|
||||||
|
QT4_ADD_TRANSLATION(QM_FILES ${TS_FILES})
|
||||||
|
|
||||||
|
## HACK HACK HACK - around rcc limitations to allow out of source-tree building
|
||||||
|
SET( trans_file tomahawk_i18n )
|
||||||
|
SET( trans_srcfile ${CMAKE_BINARY_DIR}/lang/${trans_file}.qrc)
|
||||||
|
SET( trans_infile ${CMAKE_CURRENT_BINARY_DIR}/${trans_file}.qrc)
|
||||||
|
SET( trans_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_${trans_file}.cxx)
|
||||||
|
|
||||||
|
# Copy the QRC file to the output directory
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
OUTPUT ${trans_infile}
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E copy ${trans_srcfile} ${trans_infile}
|
||||||
|
MAIN_DEPENDENCY ${trans_srcfile}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Run the resource compiler (rcc_options should already be set)
|
||||||
|
ADD_CUSTOM_COMMAND(
|
||||||
|
OUTPUT ${trans_outfile}
|
||||||
|
COMMAND ${QT_RCC_EXECUTABLE}
|
||||||
|
ARGS ${rcc_options} -name ${trans_file} -o ${trans_outfile} ${trans_infile}
|
||||||
|
MAIN_DEPENDENCY ${trans_infile}
|
||||||
|
DEPENDS ${QM_FILES}
|
||||||
|
)
|
||||||
|
endmacro()
|
||||||
|
|
||||||
|
@@ -145,7 +145,9 @@ INCLUDE(GNUInstallDirs)
|
|||||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||||
|
|
||||||
|
# translations
|
||||||
include( ${CMAKE_SOURCE_DIR}/lang/translations.cmake )
|
include( ${CMAKE_SOURCE_DIR}/lang/translations.cmake )
|
||||||
|
add_tomahawk_translations(ar bg ca de en es fr ja pl pt_BR ru sv tr zh_CN zh_TW)
|
||||||
|
|
||||||
SET( final_src ${final_src} ${tomahawkMoc} ${tomahawkSources} ${trans_outfile})
|
SET( final_src ${final_src} ${tomahawkMoc} ${tomahawkSources} ${trans_outfile})
|
||||||
|
|
||||||
|
@@ -141,18 +141,32 @@ TomahawkApp::installTranslator()
|
|||||||
if ( locale == "C" )
|
if ( locale == "C" )
|
||||||
locale = "en";
|
locale = "en";
|
||||||
|
|
||||||
|
// Tomahawk translations
|
||||||
QTranslator* translator = new QTranslator( this );
|
QTranslator* translator = new QTranslator( this );
|
||||||
if ( translator->load( QString( ":/lang/tomahawk_" ) + locale ) )
|
if ( translator->load( QString( ":/lang/tomahawk_" ) + locale ) )
|
||||||
{
|
{
|
||||||
tDebug() << "Using system locale:" << locale;
|
tDebug() << "Translation: Tomahawk: Using system locale:" << locale;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
tDebug() << "Using default locale, system locale one not found:" << locale;
|
tDebug() << "Translation: Tomahawk: Using default locale, system locale one not found:" << locale;
|
||||||
translator->load( QString( ":/lang/tomahawk_en" ) );
|
translator->load( QString( ":/lang/tomahawk_en" ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
TOMAHAWK_APPLICATION::installTranslator( translator );
|
TOMAHAWK_APPLICATION::installTranslator( translator );
|
||||||
|
|
||||||
|
// Qt translations
|
||||||
|
translator = new QTranslator( this );
|
||||||
|
if ( translator->load( QString( ":/lang/qt_" ) + locale ) )
|
||||||
|
{
|
||||||
|
tDebug() << "Translation: Qt: Using system locale:" << locale;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tDebug() << "Translation: Qt: Using default locale, system locale one not found:" << locale;
|
||||||
|
}
|
||||||
|
|
||||||
|
TOMAHAWK_APPLICATION::installTranslator( translator );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user