1
0
mirror of https://github.com/tomahawk-player/tomahawk.git synced 2025-04-21 00:12:06 +02:00

Include Qt translations

This commit is contained in:
Dominik Schmidt 2012-06-12 02:23:38 +02:00
parent eae9194aa8
commit 695feed2b6
3 changed files with 62 additions and 23 deletions

View File

@ -1,25 +1,48 @@
FILE (GLOB TS_FILES ${CMAKE_SOURCE_DIR}/lang/*.ts)
QT4_ADD_TRANSLATION(QM_FILES ${TS_FILES})
macro(add_tomahawk_translations language)
list(APPEND TOMAHAWK_LANGUAGES ${ARGV})
## HACK HACK HACK - around rcc limitations to allow out of source-tree building
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)
set(tomahawk_i18n_qrc_content "<!DOCTYPE RCC><RCC version=\"1.0\">\n")
# 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}
)
# tomahawk and qt language files
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<qresource prefix=\"/lang\">\n")
foreach(lang ${TOMAHAWK_LANGUAGES})
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}<file>tomahawk_${lang}.qm</file>\n")
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)
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}
)
# build explicitly enabled languages
list(APPEND TS_FILES "${CMAKE_SOURCE_DIR}/lang/tomahawk_${lang}.ts")
endforeach()
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}</qresource>\n")
set(tomahawk_i18n_qrc_content "${tomahawk_i18n_qrc_content}</RCC>\n")
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()

View File

@ -145,7 +145,9 @@ INCLUDE(GNUInstallDirs)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Config.h.in
${CMAKE_CURRENT_BINARY_DIR}/config.h)
# translations
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})

View File

@ -141,18 +141,32 @@ TomahawkApp::installTranslator()
if ( locale == "C" )
locale = "en";
// Tomahawk translations
QTranslator* translator = new QTranslator( this );
if ( translator->load( QString( ":/lang/tomahawk_" ) + locale ) )
{
tDebug() << "Using system locale:" << locale;
tDebug() << "Translation: Tomahawk: Using system locale:" << locale;
}
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" ) );
}
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 );
}