2014-09-20 22:07:52 +00:00
|
|
|
##
|
|
|
|
# Meta-infrastructure to allow po-based translation of Colobot help files
|
|
|
|
##
|
|
|
|
|
|
|
|
find_program(PO4A po4a)
|
|
|
|
|
|
|
|
if(NOT PO4A)
|
|
|
|
message(WARNING "PO4A not found, help files will NOT be translated!")
|
|
|
|
endif()
|
|
|
|
|
|
|
|
##
|
|
|
|
# Generate translated help files in separate directories per language
|
|
|
|
##
|
2014-09-21 09:46:28 +00:00
|
|
|
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
|
|
|
|
|
2014-09-20 22:07:52 +00:00
|
|
|
# generated config file for po4a
|
2014-09-21 09:46:28 +00:00
|
|
|
set(po4a_cfg_file ${work_dir}/help_po4a.cfg)
|
2014-09-20 22:07:52 +00:00
|
|
|
|
|
|
|
# get translations from po directory
|
2014-09-21 09:46:28 +00:00
|
|
|
get_filename_component(abs_po_dir ${po_dir} ABSOLUTE)
|
2014-09-20 22:07:52 +00:00
|
|
|
file(WRITE ${po4a_cfg_file} "[po_directory] ${abs_po_dir}\n")
|
|
|
|
|
|
|
|
# prepare output directories
|
2014-09-21 09:46:28 +00:00
|
|
|
set(output_help_subdirs "")
|
2014-09-20 22:07:52 +00:00
|
|
|
file(GLOB po_files ${po_dir}/*.po)
|
|
|
|
foreach(po_file ${po_files})
|
2014-09-21 10:59:50 +00:00
|
|
|
get_language_char(language_char ${po_file})
|
2014-09-21 09:46:28 +00:00
|
|
|
set(language_help_subdir ${work_dir}/${language_char})
|
2014-09-20 22:07:52 +00:00
|
|
|
list(APPEND output_help_subdirs ${language_help_subdir})
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# add translation rules for help files
|
|
|
|
foreach(source_help_file ${source_help_files})
|
|
|
|
get_filename_component(abs_source_help_file ${source_help_file} ABSOLUTE)
|
|
|
|
get_filename_component(help_file_name ${source_help_file} NAME)
|
|
|
|
|
|
|
|
file(APPEND ${po4a_cfg_file} "\n[type:colobothelp] ${abs_source_help_file}")
|
|
|
|
foreach(po_file ${po_files})
|
|
|
|
# generated file for single language
|
2014-09-21 10:59:50 +00:00
|
|
|
get_language_code(language_code ${po_file})
|
|
|
|
get_language_char(language_char ${po_file})
|
2014-09-21 09:46:28 +00:00
|
|
|
set(generated_help_file ${work_dir}/${language_char}/${help_file_name})
|
2014-09-20 22:07:52 +00:00
|
|
|
file(APPEND ${po4a_cfg_file} " \\\n ${language_code}:${generated_help_file}")
|
|
|
|
endforeach()
|
|
|
|
endforeach()
|
|
|
|
|
|
|
|
# dummy files to signal that scripts have finished running
|
2014-09-21 09:46:28 +00:00
|
|
|
set(translation_signalfile ${work_dir}/translations)
|
|
|
|
set(po_clean_signalfile ${work_dir}/po_clean)
|
2014-09-20 22:07:52 +00:00
|
|
|
|
|
|
|
# script to run po4a and generate translated files
|
|
|
|
add_custom_command(OUTPUT ${translation_signalfile}
|
2014-09-21 09:46:28 +00:00
|
|
|
COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/run_po4a.sh
|
|
|
|
${po4a_cfg_file}
|
|
|
|
${translation_signalfile}
|
2014-09-20 22:07:52 +00:00
|
|
|
DEPENDS ${po_files})
|
|
|
|
|
|
|
|
file(GLOB pot_file ${po_dir}/*.pot)
|
|
|
|
set(po_files ${po_files} ${pot_file})
|
|
|
|
|
|
|
|
# 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}
|
2014-09-21 09:46:28 +00:00
|
|
|
COMMAND ${DATA_SOURCE_DIR}/i18n-tools/scripts/clean_po_files.sh
|
|
|
|
${escaped_po_files}
|
|
|
|
${translation_signalfile}
|
|
|
|
${po_clean_signalfile}
|
2014-09-20 22:07:52 +00:00
|
|
|
DEPENDS ${translation_signalfile}
|
|
|
|
)
|
|
|
|
|
2014-09-21 09:46:28 +00:00
|
|
|
# generate some unique string for target name
|
2014-09-20 22:07:52 +00:00
|
|
|
string(REGEX REPLACE "[/\\]" "_" target_suffix ${po_dir})
|
2014-09-21 09:46:28 +00:00
|
|
|
message(STATUS ${target_suffix})
|
|
|
|
|
|
|
|
# target to run both scripts
|
|
|
|
add_custom_target(i18n_${target_suffix} ALL DEPENDS ${translation_signalfile} ${po_clean_signalfile})
|
2014-09-20 22:07:52 +00:00
|
|
|
|
|
|
|
# return the translated files
|
|
|
|
set(${result_generated_help_dirs} ${output_help_subdirs} PARENT_SCOPE)
|
|
|
|
endfunction()
|