Nicer generated directory structure

dev-hd-graphics
Piotr Dziwinski 2014-09-21 11:46:28 +02:00
parent c3c458eeca
commit a34aa40525
5 changed files with 104 additions and 50 deletions

View File

@ -19,6 +19,7 @@ install(DIRECTORY textures DESTINATION ${COLOBOT_INSTALL_DATA_DIR})
install(DIRECTORY DESTINATION ${COLOBOT_INSTALL_DATA_DIR}/mods) # Empty directory install(DIRECTORY DESTINATION ${COLOBOT_INSTALL_DATA_DIR}/mods) # Empty directory
set(DATA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}) set(DATA_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(DATA_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
add_subdirectory(help) add_subdirectory(help)
add_subdirectory(levels) add_subdirectory(levels)

View File

@ -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) file(GLOB help_files RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${help_category_dir}/E/*.txt)
list(SORT help_files) list(SORT help_files)
if(PO4A AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${help_category_dir}/po/) 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() else()
set(translated_help_dirs "") set(translated_help_dirs "")
endif() endif()

View File

@ -13,26 +13,28 @@ set(HELP_I18N_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/help-po)
## ##
# Generate translated help files in separate directories per language # Generate translated help files in separate directories per language
## ##
function(generate_help_i18n result_generated_help_dirs source_help_files po_dir) function(generate_help_i18n
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) 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 # 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 translations from po directory
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE)
file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n") 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 # prepare output directories
set(output_help_subdirs "")
file(GLOB po_files ${po_dir}/*.po) file(GLOB po_files ${po_dir}/*.po)
foreach(po_file ${po_files}) foreach(po_file ${po_files})
get_filename_component(po_file_name ${po_file} NAME) get_filename_component(po_file_name ${po_file} NAME)
# get language letter e.g. "de.po" -> "d" # get language letter e.g. "de.po" -> "d"
string(REGEX REPLACE ".\\.po" "" language_char ${po_file_name}) string(REGEX REPLACE ".\\.po" "" language_char ${po_file_name})
string(TOUPPER ${language_char} language_char) string(TOUPPER ${language_char} language_char)
set(language_help_subdir ${output_help_dir}/${language_char}) set(language_help_subdir ${work_dir}/${language_char})
file(MAKE_DIRECTORY ${language_help_subdir})
list(APPEND output_help_subdirs ${language_help_subdir}) list(APPEND output_help_subdirs ${language_help_subdir})
endforeach() 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(REGEX REPLACE ".\\.po" "" language_char ${po_file_name})
string(TOUPPER ${language_char} language_char) string(TOUPPER ${language_char} language_char)
# generated file for single language # 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}") file(APPEND ${po4a_cfg_file} " \\\n ${language_code}:${generated_help_file}")
endforeach() endforeach()
endforeach() endforeach()
# dummy files to signal that scripts have finished running # dummy files to signal that scripts have finished running
set(translation_signalfile ${HELP_I18N_WORK_DIR}/${po_dir}/translations) set(translation_signalfile ${work_dir}/translations)
set(po_clean_signalfile ${HELP_I18N_WORK_DIR}/${po_dir}/po_clean) set(po_clean_signalfile ${work_dir}/po_clean)
# script to run po4a and generate translated files # script to run po4a and generate translated files
add_custom_command(OUTPUT ${translation_signalfile} 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}) DEPENDS ${po_files})
file(GLOB pot_file ${po_dir}/*.pot) 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 # script to do some cleanups in updated *.po and *.pot files
string(REPLACE ";" ":" escaped_po_files "${po_files}") string(REPLACE ";" ":" escaped_po_files "${po_files}")
add_custom_command(OUTPUT ${po_clean_signalfile} 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} DEPENDS ${translation_signalfile}
) )
# generate some unique string for target name # generate some unique string for target name
string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir}) 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 # return the translated files
set(${result_generated_help_dirs} ${output_help_subdirs} PARENT_SCOPE) set(${result_generated_help_dirs} ${output_help_subdirs} PARENT_SCOPE)

View File

@ -8,33 +8,38 @@ if(NOT PO4A)
message(WARNING "PO4A not found, level files will NOT be translated!") message(WARNING "PO4A not found, level files will NOT be translated!")
endif() endif()
set(LEVELS_I18N_WORK_DIR ${CMAKE_CURRENT_BINARY_DIR}/levels-po)
## ##
# Generate translated chaptertitle files using po4a # Generate translated chaptertitle files using po4a
## ##
function(generate_chaptertitles_i18n result_translated_chaptertitle_files source_chaptertitle_files po_dir) function(generate_chaptertitles_i18n
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) result_translated_chaptertitle_files # output variable to return names of translated chaptertitle files
# generated config file for po4a source_chaptertitle_prefix_dir # prefix directory for chaptertitle files
set(po4a_cfg_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/chaptertitles_po4a.cfg) source_chaptertitle_files # input chaptertitle files relative to prefix dir
# generated dummy file for translation of "E", "D", "F", "P", etc. language letters po_dir # directory with translations (*.po, *.pot files)
set(langchar_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/chaptertitles_langchar.txt) 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") 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 translations from po directory
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE)
file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n") file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n")
# add content of dummy language file to translation # add content of dummy language file to translation
file(APPEND ${po4a_cfg_file} "[type:text] ${langchar_file}") file(APPEND ${po4a_cfg_file} "[type:text] ${langchar_file}")
set(abs_source_chaptertitle_files "") set(abs_source_chaptertitle_files "")
set(translated_chaptertitle_files "") set(translated_chaptertitle_files "")
file(GLOB po_files ${po_dir}/*.po) file(GLOB po_files ${po_dir}/*.po)
foreach(source_chaptertitle_file ${source_chaptertitle_files}) foreach(source_chaptertitle_file ${source_chaptertitle_files})
get_filename_component(abs_source_chaptertitle_file ${source_chaptertitle_file} ABSOLUTE) get_filename_component(abs_source_chaptertitle_file ${source_chaptertitle_prefix_dir}/${source_chaptertitle_file} ABSOLUTE)
set(output_chaptertitle_file ${LEVELS_I18N_WORK_DIR}/${source_chaptertitle_file}) set(output_chaptertitle_file ${work_dir}/${source_chaptertitle_file})
# translation rule for chaptertitle file # translation rule for chaptertitle file
file(APPEND ${po4a_cfg_file} "\n[type:colobotlevel] ${abs_source_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() endforeach()
# dummy files to signal that scripts have finished running # dummy files to signal that scripts have finished running
set(translation_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/translations) set(translation_signalfile ${work_dir}/translations)
set(po_clean_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/po_clean) set(po_clean_signalfile ${work_dir}/po_clean)
# script to run po4a and consolidate the translations # script to run po4a and consolidate the translations
string(REPLACE ";" ":" escaped_abs_source_chaptertitle_files "${abs_source_chaptertitle_files}") string(REPLACE ";" ":" escaped_abs_source_chaptertitle_files "${abs_source_chaptertitle_files}")
string(REPLACE ";" ":" escaped_translated_chaptertitle_files "${translated_chaptertitle_files}") string(REPLACE ";" ":" escaped_translated_chaptertitle_files "${translated_chaptertitle_files}")
add_custom_command(OUTPUT ${translation_signalfile} 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/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}) DEPENDS ${po_files})
file(GLOB pot_file ${po_dir}/*.pot) 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 # script to do some cleanups in updated *.po and *.pot files
string(REPLACE ";" ":" escaped_po_files "${po_files}") string(REPLACE ";" ":" escaped_po_files "${po_files}")
add_custom_command(OUTPUT ${po_clean_signalfile} 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} DEPENDS ${translation_signalfile}
) )
# generate some unique string for target name # generate some unique string for target name
string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir}) 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 # return the translated files
set(${result_translated_chaptertitle_files} ${translated_chaptertitle_files} PARENT_SCOPE) set(${result_translated_chaptertitle_files} ${translated_chaptertitle_files} PARENT_SCOPE)
@ -85,26 +98,36 @@ endfunction()
## ##
# Generate translated level and help files using po4a # 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) function(generate_level_i18n
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE) result_translated_level_file # output variable to return names of translaed level files
# generated config file for po4a result_translated_help_files # output variable to return names of translated help files
set(po4a_cfg_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/scene_po4a.cfg) source_level_file # input scene.txt files
# generated dummy file for translation of "E", "D", "F", "P", etc. language letters source_help_files # input help files
set(langchar_file ${LEVELS_I18N_WORK_DIR}/${po_dir}/scene_langchar.txt) 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") 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 translations from po directory
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE)
file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n") file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n")
# add content of dummy language file to translation # add content of dummy language file to translation
file(APPEND ${po4a_cfg_file} "[type:text] ${langchar_file}") 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 # 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}") 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) file(GLOB po_files ${po_dir}/*.po)
foreach(po_file ${po_files}) foreach(po_file ${po_files})
get_filename_component(po_file_name ${po_file} NAME) 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() endforeach()
# translation rules for help files # 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 "") set(translated_help_files "")
foreach(source_help_file ${source_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() endforeach()
# dummy files to signal that scripts have finished running # dummy files to signal that scripts have finished running
set(translation_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/translations) set(translation_signalfile ${work_dir}/translations)
set(po_clean_signalfile ${LEVELS_I18N_WORK_DIR}/${po_dir}/po_clean) set(po_clean_signalfile ${work_dir}/po_clean)
# script to run po4a and consolidate the translations # script to run po4a and consolidate the translations
add_custom_command(OUTPUT ${translation_signalfile} 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/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}) DEPENDS ${po_files})
file(GLOB pot_file ${po_dir}/*.pot) 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 # script to do some cleanups in updated *.po and *.pot files
string(REPLACE ";" ":" escaped_po_files "${po_files}") string(REPLACE ";" ":" escaped_po_files "${po_files}")
add_custom_command(OUTPUT ${po_clean_signalfile} 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} DEPENDS ${translation_signalfile}
) )
# generate some unique string for target name # generate some unique string for target name
string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir}) 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 # return the translated files
set(${result_translated_level_file} ${output_level_file} PARENT_SCOPE) set(${result_translated_level_file} ${output_level_file} PARENT_SCOPE)

View File

@ -8,10 +8,14 @@ set(LEVEL_INSTALL_DATA_DIR ${COLOBOT_INSTALL_DATA_DIR}/levels)
# Add level category directory with all chapters inside # Add level category directory with all chapters inside
## ##
function(add_level_category level_category_dir) 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) list(SORT chaptertitle_files)
if(PO4A AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${level_category_dir}/po/) 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() else()
set(translated_chaptertitle_files ${chaptertitle_files}) set(translated_chaptertitle_files ${chaptertitle_files})
endif() endif()
@ -49,7 +53,12 @@ function(add_level level_dir)
file(GLOB original_help_files ${level_dir}/help/*.txt) file(GLOB original_help_files ${level_dir}/help/*.txt)
list(SORT original_help_files) list(SORT original_help_files)
if(PO4A AND EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/${level_dir}/po/) 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() else()
set(translated_level_file ${level_dir}/scene.txt) set(translated_level_file ${level_dir}/scene.txt)
endif() endif()