Thursday, January 29, 2009

Makefile for translating page templates using i18ndude

# Makefile for creating translation files (.pot and .po) in Plone products.
# Kees Hink , 2009.
# Place this inside the 'i18n' directory in you Product (which should be empty
# otherwise). Adjust the definitions, and run 'make'.
# A .pot file will be created. Edit it, and run 'make xx-translation' to create
# a translation file for language xx.
# I have chosen to not rebuild the .pot-file, but to merge it with a newly
# created temporary file. This assures the settings (author, e-mail, package
# etc.) are kept.

# Modify these to suit your product.
# The base name for your .pot and .po files.
# Beware of trailing whitespace!
FILENAMEBASE = yourproduct_here
TEMPORARY = temp.pot
# The i18n domain should match the i18n.domain="" statement in your .pt,
# .cpt, etc. files.
I18NDOMAIN = yourproduct
# Where to find the translatable strings.
# For a typical Plone 2.5 product, this will be skins/{product}_templates/
# For Plone 3, it will be browser/templates/ or just browser/
TEMPLATE_DIRECTORY = '../browser/templates'

# Update the main translations file.
# This is run by default when you run 'make'.
# Create temporary .pot file.
# We only search the browser/templates directory.
i18ndude rebuild-pot --pot ${TEMPORARY} \
# Check if the .pot file exists:
# - If it exists, create a backup.
# - If no, this must be the first run. Use a copy of the temporary .pot file
# as basis. Edit the .pot file after the first run.
if [ -e ${POTFILE} ]; \
then cp ${POTFILE} ${POTFILE}.backup; \
else cp ${TEMPORARY} ${POTFILE}; \
# Merge temporary into the .pot.
# Merging will print a warning 'Merge-Warning: Key is already in
# target-catalog' for each string that is in both the temporary and the real
# .pot file (almost all strings, in effect).
# You can safely ignore these warnings.
i18ndude merge --pot ${POTFILE} --merge ${TEMPORARY}

# Update a specific translation file.
# Call as 'make xx-translation', replace xx with your country code.
# Create backup, or else create initial file.
if [ ! -e ${FILENAMEBASE}-$*.po ]; \
then touch ${FILENAMEBASE}-$*.po;\
else cp ${FILENAMEBASE}-$*.po ${FILENAMEBASE}-$*.po.backup;\
# Sync translation strings in translation file with .pot
# This may delete translations. If you see something like '0 added, 531
# removed, consider re-examining the backup.
i18ndude sync --pot ${POTFILE} ${FILENAMEBASE}-$*.po

No comments: