Changeset 2757 for vidalia/trunk/cmake

Show
Ignore:
Timestamp:
06/18/08 23:58:57 (5 months ago)
Author:
edmanm
Message:

Build our translations from .po files rather than .ts files. Also use "zh_CN"
and "zh_TW" instead of "zh-cn" and "zh-tw" so we don't look quite so silly.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vidalia/trunk/cmake/VidaliaMacros.cmake

    r2438 r2757  
    1111## 
    1212 
     13## Tool used to convert Qt's .ts files to GNU gettext .po format 
     14set(VIDALIA_TS2PO_EXECUTABLE ${Vidalia_BINARY_DIR}/src/tools/ts2po/ts2po) 
     15if (WIN32) 
     16  set(VIDALIA_TS2PO_EXECUTABLE ${VIDALIA_TS2PO_EXECUTABLE}.exe) 
     17endif(WIN32) 
     18 
     19## Tool used to convert GNU gettext .po files to Qt's .ts format 
     20set(VIDALIA_PO2TS_EXECUTABLE ${Vidalia_BINARY_DIR}/src/tools/po2ts/po2ts) 
     21if (WIN32) 
     22  set(VIDALIA_PO2TS_EXECUTABLE ${VIDALIA_PO2TS_EXECUTABLE}.exe) 
     23endif(WIN32) 
     24     
    1325 
    1426## Search for lrelease 
     
    4456endif(WIN32) 
    4557 
    46  
    47 ## Wraps the supplied .ts files in lrelease commands 
    48 macro(QT4_ADD_TRANSLATIONS outfiles) 
     58## Adds custom commands to the specified target that will update each of the 
     59## supplied .po files  
     60macro(VIDALIA_UPDATE_PO TARGET) 
     61  ## Gather a list of all the files that might contain translated strings 
     62  FILE(GLOB_RECURSE translate_SRCS ${Vidalia_SOURCE_DIR}/*.cpp) 
     63  FILE(GLOB_RECURSE translate_HDRS ${Vidalia_SOURCE_DIR}/*.h) 
     64  FILE(GLOB_RECURSE translate_UIS  ${Vidalia_SOURCE_DIR}/*.ui) 
     65  set(translate_SRCS ${translate_SRCS} ${translate_HDRS} ${translate_UIS}) 
     66  
    4967  foreach (it ${ARGN}) 
    50     get_filename_component(it ${it} ABSOLUTE) 
     68    get_filename_component(po ${it} ABSOLUTE) 
     69    get_filename_component(podir ${it} PATH) 
    5170    get_filename_component(outfile ${it} NAME_WE) 
    5271 
    53     ## XXX: Ideally we would output the .qm files to CMAKE_CURRENT_BINARY_DIR, 
    54     ##      but then RCC can't find them when doing out-of-source builds. Is 
    55     ##      there an easy fix for this? 
    56     set(outfile ${CMAKE_CURRENT_SOURCE_DIR}/${outfile}.qm) 
    57     add_custom_command(OUTPUT ${outfile} 
     72    set(ts ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.ts) 
     73    add_custom_command(TARGET ${TARGET} 
     74      # Convert the current .po files to .ts 
     75      COMMAND ${VIDALIA_PO2TS_EXECUTABLE} 
     76      ARGS -q -i ${po} -o ${ts} 
     77      # Update the .ts files 
     78      COMMAND ${QT_LUPDATE_EXECUTABLE} 
     79      ARGS -silent -noobsolete ${translate_SRCS} -ts ${ts} 
     80      # Convert the updated .ts files back to .po 
     81      COMMAND ${VIDALIA_TS2PO_EXECUTABLE} 
     82      ARGS -q -i ${ts} -o ${po} 
     83      DEPENDS ${VIDALIA_TS2PO_EXECUTABLE} ${VIDALIA_PO2TS_EXECUTABLE} 
     84      COMMENT "Updating translation ${it}" 
     85    ) 
     86  endforeach(it) 
     87  add_dependencies(${TARGET} ts2po) 
     88  add_dependencies(${TARGET} po2ts) 
     89endmacro(VIDALIA_UPDATE_PO) 
     90 
     91 
     92## Wraps the supplied .po files with commands to convert them to Qt's .qm 
     93## format 
     94macro(VIDALIA_ADD_PO outfiles) 
     95  foreach (it ${ARGN}) 
     96    get_filename_component(po ${it} ABSOLUTE) 
     97    get_filename_component(outfile ${it} NAME_WE) 
     98     
     99    ## Create the .po -> .ts conversion step 
     100    set(ts ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.ts) 
     101    set(qm ${CMAKE_CURRENT_BINARY_DIR}/${outfile}.qm) 
     102    add_custom_command(OUTPUT ${qm} 
     103      COMMAND ${VIDALIA_PO2TS_EXECUTABLE} 
     104      ARGS -q -i ${po} -o ${ts} 
    58105      COMMAND ${QT_LRELEASE_EXECUTABLE} 
    59       ARGS -compress -silent -nounfinished ${it} -qm ${outfile} 
    60       MAIN_DEPENDENCY ${it} 
     106      ARGS -compress -silent -nounfinished ${ts} -qm ${qm} 
     107      MAIN_DEPENDENCY ${po} 
     108      DEPENDS ${VIDALIA_PO2TS_EXECUTABLE} 
     109      COMMENT "Generating ${outfile}.qm" 
    61110    ) 
    62     set(${outfiles} ${${outfiles}} ${outfile}) 
     111    set(${outfiles} ${${outfiles}} ${qm}) 
    63112  endforeach(it) 
    64 endmacro(QT4_ADD_TRANSLATIONS) 
     113endmacro(VIDALIA_ADD_PO) 
    65114 
    66115