diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b0f11c8..ec276758 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ install(DIRECTORY textures DESTINATION ${COLOBOT_INSTALL_DATA_DIR}) install(DIRECTORY DESTINATION ${COLOBOT_INSTALL_DATA_DIR}/mods) # Empty directory set(DATA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) +set(DATA_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}) add_subdirectory(help) add_subdirectory(levels) diff --git a/help/CMakeLists.txt b/help/CMakeLists.txt index b9d54928..d30f0848 100644 --- a/help/CMakeLists.txt +++ b/help/CMakeLists.txt @@ -12,7 +12,10 @@ function(add_help_category help_category_dir) file(GLOB help_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${help_category_dir}/E/*.txt) list(SORT help_files) if(PO4A AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${help_category_dir}/po/) - generate_help_i18n(translated_help_dirs "${help_files}" ${help_category_dir}/po) + generate_help_i18n(translated_help_dirs + "${help_files}" + ${help_category_dir}/po + ${DATA_BINARY_DIR}/help-po/${help_category_dir}) else() set(translated_help_dirs "") endif() diff --git a/i18n-tools/HelpI18N.cmake b/i18n-tools/HelpI18N.cmake index bc33c2af..cef6e901 100644 --- a/i18n-tools/HelpI18N.cmake +++ b/i18n-tools/HelpI18N.cmake @@ -13,26 +13,28 @@ set(HELP_I18N_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/help-po) ## # Generate translated help files in separate directories per language ## -function(generate_help_i18n result_generated_help_dirs source_help_files po_dir) - get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) +function(generate_help_i18n + result_generated_help_dirs # output variable to return names of directories with translated files + source_help_files # input help files + po_dir # directory with translations + work_dir) # directory where to save generated files + # generated config file for po4a - set(po4a_cfg_file ${HELP_I18N_WORK_DIR}/${po_dir}/help_po4a.cfg) + set(po4a_cfg_file ${work_dir}/help_po4a.cfg) # get translations from po directory + get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n") - set(output_help_dir ${HELP_I18N_WORK_DIR}/${po_dir}/help) - set(output_help_subdirs "") - # prepare output directories + set(output_help_subdirs "") file(GLOB po_files ${po_dir}/*.po) foreach(po_file ${po_files}) get_filename_component(po_file_name ${po_file} NAME) # get language letter e.g. "de.po" -> "d" string(REGEX REPLACE ".\\.po" "" language_char ${po_file_name}) string(TOUPPER ${language_char} language_char) - set(language_help_subdir ${output_help_dir}/${language_char}) - file(MAKE_DIRECTORY ${language_help_subdir}) + set(language_help_subdir ${work_dir}/${language_char}) list(APPEND output_help_subdirs ${language_help_subdir}) endforeach() @@ -50,18 +52,20 @@ function(generate_help_i18n result_generated_help_dirs source_help_files po_dir) string(REGEX REPLACE ".\\.po" "" language_char ${po_file_name}) string(TOUPPER ${language_char} language_char) # generated file for single language - set(generated_help_file ${output_help_dir}/${language_char}/${help_file_name}) + set(generated_help_file ${work_dir}/${language_char}/${help_file_name}) file(APPEND ${po4a_cfg_file} " \\\n ${language_code}:${generated_help_file}") endforeach() endforeach() # dummy files to signal that scripts have finished running - set(translation_signalfile ${HELP_I18N_WORK_DIR}/${po_dir}/translations) - set(po_clean_signalfile ${HELP_I18N_WORK_DIR}/${po_dir}/po_clean) + set(translation_signalfile ${work_dir}/translations) + set(po_clean_signalfile ${work_dir}/po_clean) # script to run po4a and generate translated files add_custom_command(OUTPUT ${translation_signalfile} - COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/run_po4a.sh ${po4a_cfg_file} ${translation_signalfile} + COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/run_po4a.sh + ${po4a_cfg_file} + ${translation_signalfile} DEPENDS ${po_files}) file(GLOB pot_file ${po_dir}/*.pot) @@ -70,13 +74,19 @@ function(generate_help_i18n result_generated_help_dirs source_help_files po_dir) # script to do some cleanups in updated *.po and *.pot files string(REPLACE ";" ":" escaped_po_files "${po_files}") add_custom_command(OUTPUT ${po_clean_signalfile} - COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh ${escaped_po_files} ${translation_signalfile} ${po_clean_signalfile} + COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh + ${escaped_po_files} + ${translation_signalfile} + ${po_clean_signalfile} DEPENDS ${translation_signalfile} ) - # generate some unique string for target name + # generate some unique string for target name string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir}) - add_custom_target(level_i18n-${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile}) + message(STATUS ${target_suffix}) + + # target to run both scripts + add_custom_target(i18n_${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile}) # return the translated files set(${result_generated_help_dirs} ${output_help_subdirs} PARENT_SCOPE) diff --git a/i18n-tools/LevelsI18N.cmake b/i18n-tools/LevelsI18N.cmake index d3593c77..be623b0a 100644 --- a/i18n-tools/LevelsI18N.cmake +++ b/i18n-tools/LevelsI18N.cmake @@ -8,33 +8,38 @@ if(NOT PO4A) message(WARNING "PO4A not found, level files will NOT be translated!") endif() -set(LEVELS_I18N_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/levels-po) - ## # Generate translated chaptertitle files using po4a ## -function(generate_chaptertitles_i18n result_translated_chaptertitle_files source_chaptertitle_files po_dir) - get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) - # generated config file for po4a - set(po4a_cfg_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/chaptertitles_po4a.cfg) - # generated dummy file for translation of "E", "D", "F", "P", etc. language letters - set(langchar_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/chaptertitles_langchar.txt) +function(generate_chaptertitles_i18n + result_translated_chaptertitle_files # output variable to return names of translated chaptertitle files + source_chaptertitle_prefix_dir # prefix directory for chaptertitle files + source_chaptertitle_files # input chaptertitle files relative to prefix dir + po_dir # directory with translations (*.po, *.pot files) + work_dir) # directory where to save generated files + # generated dummy file for translation of "E", "D", "F", "P", etc. language letters + # TODO find a better way to provide translations than this hack + set(langchar_file ${work_dir}/chaptertitles_langchar.txt) file(WRITE ${langchar_file} "E") + # generated config file for po4a + set(po4a_cfg_file ${work_dir}/chaptertitles_po4a.cfg) + # get translations from po directory + get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n") + # add content of dummy language file to translation file(APPEND ${po4a_cfg_file} "[type:text] ${langchar_file}") set(abs_source_chaptertitle_files "") set(translated_chaptertitle_files "") - file(GLOB po_files ${po_dir}/*.po) foreach(source_chaptertitle_file ${source_chaptertitle_files}) - get_filename_component(abs_source_chaptertitle_file ${source_chaptertitle_file} ABSOLUTE) - set(output_chaptertitle_file ${LEVELS_I18N_WORK_DIR}/${source_chaptertitle_file}) + get_filename_component(abs_source_chaptertitle_file ${source_chaptertitle_prefix_dir}/${source_chaptertitle_file} ABSOLUTE) + set(output_chaptertitle_file ${work_dir}/${source_chaptertitle_file}) # translation rule for chaptertitle file file(APPEND ${po4a_cfg_file} "\n[type:colobotlevel] ${abs_source_chaptertitle_file}") @@ -53,15 +58,18 @@ function(generate_chaptertitles_i18n result_translated_chaptertitle_files source endforeach() # dummy files to signal that scripts have finished running - set(translation_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/translations) - set(po_clean_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/po_clean) + set(translation_signalfile ${work_dir}/translations) + set(po_clean_signalfile ${work_dir}/po_clean) # script to run po4a and consolidate the translations string(REPLACE ";" ":" escaped_abs_source_chaptertitle_files "${abs_source_chaptertitle_files}") string(REPLACE ";" ":" escaped_translated_chaptertitle_files "${translated_chaptertitle_files}") add_custom_command(OUTPUT ${translation_signalfile} COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/run_po4a.sh ${po4a_cfg_file} - COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/create_level_translations.sh ${escaped_abs_source_chaptertitle_files} ${escaped_translated_chaptertitle_files} ${translation_signalfile} + COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/create_level_translations.sh + ${escaped_abs_source_chaptertitle_files} + ${escaped_translated_chaptertitle_files} + ${translation_signalfile} DEPENDS ${po_files}) file(GLOB pot_file ${po_dir}/*.pot) @@ -70,13 +78,18 @@ function(generate_chaptertitles_i18n result_translated_chaptertitle_files source # script to do some cleanups in updated *.po and *.pot files string(REPLACE ";" ":" escaped_po_files "${po_files}") add_custom_command(OUTPUT ${po_clean_signalfile} - COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh ${escaped_po_files} ${translation_signalfile} ${po_clean_signalfile} + COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh + ${escaped_po_files} + ${translation_signalfile} + ${po_clean_signalfile} DEPENDS ${translation_signalfile} ) # generate some unique string for target name string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir}) - add_custom_target(level_i18n-${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile}) + + # target to run both scripts + add_custom_target(i18n_${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile}) # return the translated files set(${result_translated_chaptertitle_files} ${translated_chaptertitle_files} PARENT_SCOPE) @@ -85,26 +98,36 @@ endfunction() ## # Generate translated level and help files using po4a ## -function(generate_level_i18n result_translated_level_file result_translated_help_files source_level_file source_help_files po_dir) - get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) - # generated config file for po4a - set(po4a_cfg_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/scene_po4a.cfg) - # generated dummy file for translation of "E", "D", "F", "P", etc. language letters - set(langchar_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/scene_langchar.txt) +function(generate_level_i18n + result_translated_level_file # output variable to return names of translaed level files + result_translated_help_files # output variable to return names of translated help files + source_level_file # input scene.txt files + source_help_files # input help files + po_dir # directory with translations (*.po, *.pot files) + work_dir) # directory where to save generated files + # generated dummy file for translation of "E", "D", "F", "P", etc. language letters + # TODO find a better way to provide translations than this hack + set(langchar_file ${work_dir}/scene_langchar.txt) file(WRITE ${langchar_file} "E") + # generated config file for po4a + set(po4a_cfg_file ${work_dir}/scene_po4a.cfg) + # get translations from po directory + get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n") + # add content of dummy language file to translation file(APPEND ${po4a_cfg_file} "[type:text] ${langchar_file}") - get_filename_component(abs_source_level_file ${source_level_file} ABSOLUTE) - set(output_level_file ${LEVELS_I18N_WORK_DIR}/${source_level_file}) - # translation rule for scene file + get_filename_component(abs_source_level_file ${source_level_file} ABSOLUTE) file(APPEND ${po4a_cfg_file} "\n[type:colobotlevel] ${abs_source_level_file}") + get_filename_component(source_level_file_name ${source_level_file} NAME) + set(output_level_file ${work_dir}/${source_level_file_name}) + file(GLOB po_files ${po_dir}/*.po) foreach(po_file ${po_files}) get_filename_component(po_file_name ${po_file} NAME) @@ -116,7 +139,7 @@ function(generate_level_i18n result_translated_level_file result_translated_help endforeach() # translation rules for help files - set(output_help_dir ${LEVELS_I18N_WORK_DIR}/${po_dir}/help) + set(output_help_dir ${work_dir}/help) set(translated_help_files "") foreach(source_help_file ${source_help_files}) @@ -140,13 +163,16 @@ function(generate_level_i18n result_translated_level_file result_translated_help endforeach() # dummy files to signal that scripts have finished running - set(translation_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/translations) - set(po_clean_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/po_clean) + set(translation_signalfile ${work_dir}/translations) + set(po_clean_signalfile ${work_dir}/po_clean) # script to run po4a and consolidate the translations add_custom_command(OUTPUT ${translation_signalfile} COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/run_po4a.sh ${po4a_cfg_file} - COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/create_level_translations.sh ${abs_source_level_file} ${output_level_file} ${translation_signalfile} + COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/create_level_translations.sh + ${abs_source_level_file} + ${output_level_file} + ${translation_signalfile} DEPENDS ${po_files}) file(GLOB pot_file ${po_dir}/*.pot) @@ -155,13 +181,18 @@ function(generate_level_i18n result_translated_level_file result_translated_help # script to do some cleanups in updated *.po and *.pot files string(REPLACE ";" ":" escaped_po_files "${po_files}") add_custom_command(OUTPUT ${po_clean_signalfile} - COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh ${escaped_po_files} ${translation_signalfile} ${po_clean_signalfile} + COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh + ${escaped_po_files} + ${translation_signalfile} + ${po_clean_signalfile} DEPENDS ${translation_signalfile} ) # generate some unique string for target name string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir}) - add_custom_target(level_i18n-${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile}) + + # target to run both scripts + add_custom_target(i18n_${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile}) # return the translated files set(${result_translated_level_file} ${output_level_file} PARENT_SCOPE) diff --git a/levels/CMakeLists.txt b/levels/CMakeLists.txt index a2541475..d01043f1 100644 --- a/levels/CMakeLists.txt +++ b/levels/CMakeLists.txt @@ -8,10 +8,14 @@ set(LEVEL_INSTALL_DATA_DIR ${COLOBOT_INSTALL_DATA_DIR}/levels) # Add level category directory with all chapters inside ## function(add_level_category level_category_dir) - file(GLOB chaptertitle_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${level_category_dir}/chapter*/chaptertitle.txt) + file(GLOB chaptertitle_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/${level_category_dir} ${level_category_dir}/chapter*/chaptertitle.txt) list(SORT chaptertitle_files) if(PO4A AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${level_category_dir}/po/) - generate_chaptertitles_i18n(translated_chaptertitle_files "${chaptertitle_files}" ${level_category_dir}/po) + generate_chaptertitles_i18n(translated_chaptertitle_files + ${level_category_dir} + "${chaptertitle_files}" + ${level_category_dir}/po + ${DATA_BINARY_DIR}/levels-po/${level_category_dir}) else() set(translated_chaptertitle_files ${chaptertitle_files}) endif() @@ -49,7 +53,12 @@ function(add_level level_dir) file(GLOB original_help_files ${level_dir}/help/*.txt) list(SORT original_help_files) if(PO4A AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${level_dir}/po/) - generate_level_i18n(translated_level_file translated_help_files ${level_dir}/scene.txt "${original_help_files}" ${level_dir}/po) + generate_level_i18n(translated_level_file + translated_help_files + ${level_dir}/scene.txt + "${original_help_files}" + ${level_dir}/po + ${DATA_BINARY_DIR}/levels-po/${level_dir}) else() set(translated_level_file ${level_dir}/scene.txt) endif()