Jonathan Riboux – Technical Blog Python, Zope, Plone and more

5Aug/090

Generate pot files for all development eggs

With the following script, you can generate pot files for each egg in development in your Zope/Plone project.

It creates three pot files per egg

  • [EGG_NAME]-generated.pot : generated from the egg sources using i18ndude
  • [EGG_NAME]-extra.pot : empty pot generated if it doesn't exist, you can put your extra msgid/msgstr
  • [EGG_NAME].pot : merged from generated and extra

Requirements

  • egg must have a locales subdirectory
  • i18n domain used in the egg must have the same name as the egg
  • i18ndude must be installed

generate_i18n.sh

#!/bin/sh
 
# Change this to the path containing your
SRC="src"
 
for EGG_NAME in `ls $SRC`
do
  EGG_SUBDIR=`echo $EGG_NAME|sed "s/\./\//g"`
  EGG_DIR=`echo $SRC/$EGG_NAME/$EGG_SUBDIR`
  LOC_DIR=`echo $EGG_DIR/locales`
 
  if [ -d $LOC_DIR ]; then
    echo "========================================"
    echo "Found locales in $EGG_DIR"
    echo "Generating pot..."
    # Make sure pot files exist, create them if not
    touch $LOC_DIR/$EGG_NAME-generated.pot
    touch $LOC_DIR/$EGG_NAME-extra.pot
    # Create pot generated from sources
    i18ndude rebuild-pot --pot $LOC_DIR/$EGG_NAME-generated.pot --create $EGG_NAME $SRC/$EGG_NAME
    # Merge it with the extra pot (manual one) and create the final pot
    cp $LOC_DIR/$EGG_NAME-generated.pot $LOC_DIR/$EGG_NAME.pot
    i18ndude merge --pot $LOC_DIR/$EGG_NAME.pot --merge $LOC_DIR/$EGG_NAME-extra.pot
  fi
done