Wednesday, February 10, 2010

Makefile for generating translation files in i18n folder

# Makefile for creating translation files (.pot and .po) in Plone products.
# Kees Hink, 2009-2010
#
# Place this inside the 'i18n' directory in your package.
# Adjust the definitions.
# When you run 'make', a .pot file will be created.
# Run 'make xx-translation' to create a translation file for language xx.

# Definitions
DOMAIN = 'Products.MyProduct'
# The definitions below are derived from the definitions above.
# You could also override them.
GENERATED := ${DOMAIN}-generated.pot
MANUAL := ${DOMAIN}-manual.pot
POTFILE := ${DOMAIN}.pot

default: generate merge

generate:
@echo "Extracting strings from templates, putting them in generated potfile"
i18ndude rebuild-pot --pot ${GENERATED} --create ${DOMAIN} ../

merge:
@echo "Merging generated and manual string files into potfile"
i18ndude merge --pot ${POTFILE} --merge ${MANUAL} --merge2 ${GENERATED}

%-translation:
@echo "Making backup of translation file"
if [ ! -e ${DOMAIN}-$*.po ]; \
then touch ${DOMAIN}-$*.po;\
else cp ${DOMAIN}-$*.po ${DOMAIN}-$*.po.backup;\
fi
@echo "Syncing translation file"
i18ndude sync --pot ${POTFILE} ${DOMAIN}-$*.po


Beware:
* Makefiles are always indented with tabs
* You may require a space at the end of a line after a backslash

No comments: