Skip to content

Commit

Permalink
embedded translation file in executable
Browse files Browse the repository at this point in the history
  • Loading branch information
MickaelG committed Mar 18, 2014
1 parent 3d7f7fa commit 055cc41
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
30 changes: 29 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

cmake_minimum_required(VERSION 2.8.9)

project(tomate)
Expand All @@ -22,7 +23,9 @@ file(GLOB WIDGETS_SRC src/gui/gui_widgets/*.cpp)
file(GLOB GUI_SRC src/gui/*.cpp)
file(GLOB CORE_SRC src/core/*.cpp lib/pugixml.cpp)

add_executable(tomate_gui ${CORE_SRC} ${GUI_SRC} ${WIDGETS_SRC} src/main.cpp)
set( qrc_outfile ${CMAKE_CURRENT_BINARY_DIR}/qrc_tomate.cxx)

add_executable(tomate_gui ${CORE_SRC} ${GUI_SRC} ${WIDGETS_SRC} src/main.cpp ${qrc_outfile})
#qt4_use_modules(tomate_gui Widgets)
target_link_libraries(tomate_gui boost_date_time)
target_link_libraries(tomate_gui ${QT_LIBRARIES})
Expand All @@ -35,6 +38,31 @@ target_link_libraries(test_gui boost_unit_test_framework boost_date_time)
target_link_libraries(test_gui ${QT_LIBRARIES})
#qt4_use_modules(test_gui Widgets)

#Translation files
add_custom_command(OUTPUT ${CMAKE_BINARY_DIR}/tomate_fr.qm
COMMAND lrelease ${CMAKE_SOURCE_DIR}/tomate_fr.ts -qm ${CMAKE_BINARY_DIR}/tomate_fr.qm
MAIN_DEPENDENCY ${CMAKE_SOURCE_DIR}/tomate_fr.ts)

set(qm_files ${CMAKE_BINARY_DIR}/tomate_fr.qm)
set(qrc_srcfile ${CMAKE_CURRENT_SOURCE_DIR}/tomate.qrc)
set(qrc_infile ${CMAKE_CURRENT_BINARY_DIR}/tomate.qrc)
# Copy the QRC file to the output directory, because the files listed in the
# qrc file are relative to that directory.
add_custom_command(
OUTPUT ${qrc_infile}
COMMAND ${CMAKE_COMMAND} -E copy ${qrc_srcfile} ${qrc_infile}
MAIN_DEPENDENCY ${qrc_srcfile}
)
# Run the resource compiler (rcc_options should already be set). We can't
# use QT4_ADD_RESOURCES because the qrc file may not exist yet.
add_custom_command(
OUTPUT ${qrc_outfile}
COMMAND ${QT_RCC_EXECUTABLE}
ARGS ${rcc_options} -name tomate -o ${qrc_outfile} ${qrc_infile}
MAIN_DEPENDENCY ${qrc_infile}
DEPENDS ${qm_files}
)

#Installation
install(TARGETS tomate_gui RUNTIME DESTINATION bin)
install(PROGRAMS tomate.desktop DESTINATION share/applications/)
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ int main(int argc, char *argv[])
QApplication a(argc, argv);

QTranslator translator;
translator.load("tomate_" + QLocale::system().name());
translator.load("tomate_" + QLocale::system().name(), ":/lang/");
a.installTranslator(&translator);

//TODO: make it cross platform
Expand Down
6 changes: 6 additions & 0 deletions tomate.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<!DOCTYPE RCC>
<RCC>
<qresource prefix="/lang">
<file>tomate_fr.qm</file>
</qresource>
</RCC>
12 changes: 6 additions & 6 deletions tomate_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,18 @@
<translation>Note</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="35"/>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="87"/>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="38"/>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="92"/>
<source>Edit</source>
<translation>Modifier</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="36"/>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="39"/>
<source>Cancel</source>
<translation>Annuler</translation>
</message>
<message>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="90"/>
<location filename="src/gui/gui_widgets/EditCropDialog.cpp" line="95"/>
<source>Add</source>
<translation>Ajouter</translation>
</message>
Expand Down Expand Up @@ -167,12 +167,12 @@
<translation>Supprimer la plante</translation>
</message>
<message>
<location filename="src/gui/gui_plants.cpp" line="113"/>
<location filename="src/gui/gui_plants.cpp" line="114"/>
<source>Add a variety</source>
<translation>Ajouter une variété</translation>
</message>
<message>
<location filename="src/gui/gui_plants.cpp" line="130"/>
<location filename="src/gui/gui_plants.cpp" line="131"/>
<source>Color</source>
<translation>Couleur</translation>
</message>
Expand Down
2 changes: 0 additions & 2 deletions translation.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

lupdate src/main.cpp src/gui/gui_*.cpp src/gui/*/*.cpp -ts tomate_fr.ts
linguist tomate_fr.ts
lrelease tomate_fr.ts
mv tomate_fr.qm build/

0 comments on commit 055cc41

Please sign in to comment.