Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a cmake function to update .pot files?

Tags:

cmake

I am migrating a project from autotools to cmake. I have a question about gettext support.

There is an existing FindGettext.cmake modules that provides a nice function :

GETTEXT_CREATE_TRANSLATIONS(foo.pot ALL fr.po de.po)

where you provide a pot file and translated po fil ; the function takes care of turning the po files into gmo files, and add the proper installation targets to make sure the files can be found at runtime. All good and well.

Now comes the question : how do you update your pot files and you po files when you add new messages ?

For this, autotools would generate a "update-po" target, that (from what I understand), reads a POTFILES.in with the lists of all files containing translated strings, mixes it with other info, and ends up calling xgetext to generate the po. I think the coresponding Makefile task is the one that contains something like :

case `$(XGETTEXT) --version | sed 1q | sed -e 's,^[^0-9]*,,'` in \
  '' | 0.[0-9] | 0.[0-9].* | 0.1[0-5] | 0.1[0-5].* | 0.16 | 0.16.[0-1]*) \
 $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
   --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS)  \
   --files-from=$(srcdir)/POTFILES.in \
   --copyright-holder='$(COPYRIGHT_HOLDER)' \
   --msgid-bugs-address="$$msgid_bugs_address" \
 ;; \
*) \
 $(XGETTEXT) --default-domain=$(DOMAIN) --directory=$(top_srcdir) \
   --add-comments=TRANSLATORS: $(XGETTEXT_OPTIONS)  \
   --files-from=$(srcdir)/POTFILES.in \
   --copyright-holder='$(COPYRIGHT_HOLDER)' \
   --package-name="$${package_gnu}ube" \
   --package-version='0.4.0-dev' \
   --msgid-bugs-address="$$msgid_bugs_address" \
 ;; \
 esac

So, before I reinvent the wheel, is there an existing cmake function to do the same thing ? Or do I have to find the xgettext executable, lists the files, and do this by hand ? THe makefile version seems quite complicated (although it seems to handle lots of cases) ; I would not mind not having to write the cmake equivalent ;)

Thanks

PH

like image 208
phtrivier Avatar asked Apr 22 '10 21:04

phtrivier


2 Answers

Don't let the autotool bloat scare you. :-)

You can use the following code:

SET(_potFile ${PROJECT_NAME}.pot)
ADD_CUSTOM_COMMAND(OUTPUT ${_potFile}
    COMMAND ${XGETTEXT_CMD} ${_xgettext_option_list} -o ${_potFile} ${_src_list}
    DEPENDS ${_src_list}
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMENT "Extract translatable messages to ${_potFile}"
)

ADD_CUSTOM_TARGET(pot_file ${_all}
DEPENDS ${_potFile}
)

For C programs, I am using following as _xgettext_option_list

--language=C --keyword=_ --keyword=N_ --keyword=C_:1c,2 --keyword=NC_:1c,2 -s
--package-name=${PROJECT_NAME} --package-version=${PRJ_VER}

I did reinvented the wheel when the FindGettext did not have the option ALL (when it was cmake-2.4) :-)

like image 174
Ding-Yi Chen Avatar answered Oct 06 '22 00:10

Ding-Yi Chen


According to this kde wiki page, using cmake for editing sources is not a good idea. Better use standalone script for updating translations.

In fact, the extraction and merging of messages does not map well onto the CMake concept of out-of-source builds, and CMake can't provide too much help for this step, either.

Hence, in this tutorial, we will handle the first step with a standalone shell script, and only the second step will be handled by CMake.

like image 28
Ashark Avatar answered Oct 06 '22 01:10

Ashark