Skip to content

Commit

Permalink
Modified translation build rules.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andras Mohari committed May 15, 2008
1 parent 008baff commit 54bbc76
Show file tree
Hide file tree
Showing 4 changed files with 150 additions and 55 deletions.
49 changes: 0 additions & 49 deletions cmake/FindGettext.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,6 @@
# GETTEXT_MSGMERGE_EXECUTABLE: the full path to the msgmerge tool.
# GETTEXT_MSGFMT_EXECUTABLE: the full path to the msgfmt tool.
# GETTEXT_FOUND: True if gettext has been found.
#
# Additionally it provides the following macros:
# GETTEXT_CREATE_TRANSLATIONS ( outputFile [ALL] file1 ... fileN )
# This will create a target "translations" which will convert the
# given input po files into the binary output mo file. If the
# ALL option is used, the translations will also be created when
# building the default target.


FIND_PROGRAM(GETTEXT_XGETTEXT_EXECUTABLE xgettext)
Expand All @@ -19,48 +12,6 @@ FIND_PROGRAM(GETTEXT_MSGMERGE_EXECUTABLE msgmerge)

FIND_PROGRAM(GETTEXT_MSGFMT_EXECUTABLE msgfmt)

MACRO(GETTEXT_CREATE_TRANSLATIONS _potFile _firstPoFile)

SET(_gmoFiles)
GET_FILENAME_COMPONENT(_potBaseName ${_potFile} NAME_WE)
GET_FILENAME_COMPONENT(_absPotFile ${_potFile} ABSOLUTE)
GET_FILENAME_COMPONENT(_absPotFileIn POTFILES.in ABSOLUTE)

# Update message strings from the code [TODO: run even if pot file exists!]
ADD_CUSTOM_COMMAND(
OUTPUT ${_absPotFile}
COMMAND ${GETTEXT_XGETTEXT_EXECUTABLE} -o ${_absPotFile} --keyword=_ --keyword=q_ --qt --keyword=N_ --add-comments=TRANSLATORS: --keyword=translate:2 -C --default-domain=${_potBaseName} --directory=${PROJECT_SOURCE_DIR} --directory=${CMAKE_BINARY_DIR} --files-from=${_absPotFileIn} --copyright-holder="Stellarium's team"
DEPENDS POTFILES.in
)

SET(_addToAll)
IF(${_firstPoFile} STREQUAL "ALL")
SET(_addToAll "ALL")
SET(_firstPoFile)
ENDIF(${_firstPoFile} STREQUAL "ALL")

FOREACH (_currentPoFile ${ARGN})
GET_FILENAME_COMPONENT(_absFile ${_currentPoFile} ABSOLUTE)
GET_FILENAME_COMPONENT(_abs_PATH ${_absFile} PATH)
GET_FILENAME_COMPONENT(_lang ${_absFile} NAME_WE)
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)

ADD_CUSTOM_COMMAND(
OUTPUT ${_gmoFile}
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE} --quiet --update -m --backup=none -s ${_absFile} ${_absPotFile}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
DEPENDS ${_absPotFile} ${_absFile}
)

INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_potBaseName}.mo)
SET(_gmoFiles ${_gmoFiles} ${_gmoFile})

ENDFOREACH (_currentPoFile )

ADD_CUSTOM_TARGET(translations ${_addToAll} DEPENDS ${_potFile} ${_gmoFiles})

ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )

IF (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
SET(GETTEXT_FOUND TRUE)
ELSE (GETTEXT_MSGMERGE_EXECUTABLE AND GETTEXT_MSGFMT_EXECUTABLE )
Expand Down
101 changes: 99 additions & 2 deletions po/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,99 @@
ADD_SUBDIRECTORY( stellarium )
ADD_SUBDIRECTORY( stellarium-skycultures )
# Special targets for translations:
#
# translations
# Converts all PO files to GMO files. Note that it does *not* update
# the PO files or the PO templates -- in fact, these files are never
# updated automatically.
#
# generate-pot
# Re-creates all POT files unconditionally.
#
# update-po
# Updates all PO files unconditionally. Note that it takes care of
# updating the POT files.
#
# translations-<DOMAIN>
# generate-pot-<DOMAIN>
# update-po-<DOMAIN>
# Same as above, but only affect the files in the corresponding
# po/<DOMAIN> directory. (DOMAIN is actually the base name of the POT
# file in the subdirectory, but that should match the directory name
# anyway.)

ADD_CUSTOM_TARGET(translations)
ADD_CUSTOM_TARGET(generate-pot)
ADD_CUSTOM_TARGET(update-po)

# GETTEXT_CREATE_TRANSLATIONS(domain [DEFAULT_TARGET] lang1 ... langN)
#
# Creates custom build rules to create and install (G)MO files for the
# specified languages. If the DEFAULT_TARGET option is used, the
# translations will also be created when building the default target.
#
# "domain" is the translation domain, eg. "stellarium". A POT file
# with the name ${domain}.pot must exist in the directory of the
# CMakeLists.txt file invoking the macro.
#
# This macro also creates the "translations-${domain}" and
# "update-po-${domain}" targets (see above for an explanation).
#
MACRO(GETTEXT_CREATE_TRANSLATIONS _domain _firstLang)

SET(_gmoFiles)
GET_FILENAME_COMPONENT(_absPotFile ${_domain}.pot ABSOLUTE)

# Update these PO files when building the "update-po-<DOMAIN>" and
# "update-po" targets.
ADD_CUSTOM_TARGET(update-po-${_domain})
ADD_DEPENDENCIES(update-po update-po-${_domain})

# Make sure the POT file is updated before updating the PO files.
ADD_DEPENDENCIES(update-po-${_domain} generate-pot-${_domain})

SET(_addToAll)
IF(${_firstLang} STREQUAL "DEFAULT_TARGET")
SET(_addToAll "ALL")
SET(_firstLang)
ENDIF(${_firstLang} STREQUAL "DEFAULT_TARGET")

FOREACH (_lang ${ARGN})
GET_FILENAME_COMPONENT(_absFile ${_lang}.po ABSOLUTE)
FILE(RELATIVE_PATH _relFile ${PROJECT_SOURCE_DIR} ${_absFile})
SET(_gmoFile ${CMAKE_CURRENT_BINARY_DIR}/${_lang}.gmo)

# Convert a PO file into a GMO file.
ADD_CUSTOM_COMMAND(
OUTPUT ${_gmoFile}
COMMAND ${GETTEXT_MSGFMT_EXECUTABLE} -o ${_gmoFile} ${_absFile}
DEPENDS ${_absFile}
)

# Update the PO file unconditionally when building the
# "update-po-<DOMAIN>" target. Note that to see the file being
# processed, we have to run "cmake -E echo", because the
# COMMENT is not displayed by cmake...
ADD_CUSTOM_COMMAND(
TARGET update-po-${_domain}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E echo "** Updating ${_relFile}"
COMMAND ${GETTEXT_MSGMERGE_EXECUTABLE}
--quiet --update -m --backup=none -s
${_absFile} ${_absPotFile}
VERBATIM
)

INSTALL(FILES ${_gmoFile} DESTINATION share/locale/${_lang}/LC_MESSAGES RENAME ${_domain}.mo)
SET(_gmoFiles ${_gmoFiles} ${_gmoFile})

ENDFOREACH (_lang)

# Create the GMO files when building the "translations-<DOMAIN>" and
# "translations" targets.
ADD_CUSTOM_TARGET(translations-${_domain} ${_addToAll} DEPENDS ${_gmoFiles})
ADD_DEPENDENCIES(translations translations-${_domain})

ENDMACRO(GETTEXT_CREATE_TRANSLATIONS )


ADD_SUBDIRECTORY(stellarium)
ADD_SUBDIRECTORY(stellarium-skycultures)
23 changes: 21 additions & 2 deletions po/stellarium-skycultures/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,21 @@
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/FindGettext.cmake)
GETTEXT_CREATE_TRANSLATIONS(stellarium-skycultures.pot ALL ar.po bg.po cs.po de.po en_GB.po en_AU.po es.po fa.po fr.po hr.po hw.po it.po kn.po lv.po nb.po nn.po pt_BR.po ro.po sk.po sr.po tr.po vi.po zh_HK.po az.po ca.po da.po el.po en.po et.po fi.po ga.po hu.po id.po ja.po ko.po mt.po nl.po pl.po pt.po ru.po sl.po sv.po uk.po zh_CN.po zh_TW.po th.po ml.po he.po fil.po tl.po eo.po lt.po mk.po)
SET(skycultures_DOMAIN stellarium-skycultures)
SET(skycultures_POT ${skycultures_DOMAIN}.pot)

GETTEXT_CREATE_TRANSLATIONS(${skycultures_DOMAIN} DEFAULT_TARGET ar bg cs de en_GB en_AU es fa fr hr hw it kn lv nb nn pt_BR ro sk sr tr vi zh_HK az ca da el en et fi ga hu id ja ko mt nl pl pt ru sl sv uk zh_CN zh_TW th ml he fil tl eo lt mk)

ADD_CUSTOM_TARGET(
generate-pot-${skycultures_DOMAIN}
${GETTEXT_XGETTEXT_EXECUTABLE}
-o ${skycultures_POT}
--keyword=_
-C
--directory=${PROJECT_SOURCE_DIR}
--files-from=POTFILES.in
--copyright-holder=Stellarium's\ team
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating ${skycultures_POT}"
VERBATIM
)

# Generate this POT file when building the "generate-pot" target.
ADD_DEPENDENCIES(generate-pot generate-pot-${skycultures_DOMAIN})
32 changes: 30 additions & 2 deletions po/stellarium/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,30 @@
INCLUDE(${PROJECT_SOURCE_DIR}/cmake/FindGettext.cmake)
GETTEXT_CREATE_TRANSLATIONS(stellarium.pot ALL ar.po bg.po cs.po de.po en_GB.po en_AU.po es.po fa.po fr.po hr.po hw.po it.po kn.po lv.po nb.po nn.po pt_BR.po ro.po sk.po sr.po tr.po vi.po zh_HK.po az.po ca.po da.po el.po en.po et.po fi.po ga.po hu.po id.po ja.po ko.po mt.po nl.po pl.po pt.po ru.po sl.po sv.po uk.po zh_CN.po zh_TW.po th.po ml.po he.po fil.po tl.po eo.po lt.po mk.po)
SET(stellarium_DOMAIN stellarium)
SET(stellarium_POT ${stellarium_DOMAIN}.pot)

GETTEXT_CREATE_TRANSLATIONS(${stellarium_DOMAIN} DEFAULT_TARGET ar bg cs de en_GB en_AU es fa fr hr hw it kn lv nb nn pt_BR ro sk sr tr vi zh_HK az ca da el en et fi ga hu id ja ko mt nl pl pt ru sl sv uk zh_CN zh_TW th ml he fil tl eo lt mk)

ADD_CUSTOM_TARGET(
generate-pot-${stellarium_DOMAIN}
${GETTEXT_XGETTEXT_EXECUTABLE}
-o ${stellarium_POT}
--keyword=_
--keyword=N_
--keyword=q_
--keyword=translate:2
-C
--qt
--add-comments=TRANSLATORS:
--directory=${PROJECT_SOURCE_DIR}
--directory=${CMAKE_BINARY_DIR}
--files-from=POTFILES.in
--copyright-holder=Stellarium's\ team
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating ${stellarium_POT}"
VERBATIM
)

# Make sure the UI headers are created first.
ADD_DEPENDENCIES(generate-pot-${stellarium_DOMAIN} GenerateUiHeaders)

# Generate this POT file when building the "generate-pot" target.
ADD_DEPENDENCIES(generate-pot generate-pot-${stellarium_DOMAIN})

0 comments on commit 54bbc76

Please sign in to comment.