build-unified-pots.sh 4.19 KB
Newer Older
1
#!/bin/bash
bgm's avatar
bgm committed
2 3 4

function usage() {
  cat <<EOT
bgm's avatar
bgm committed
5
build-unified-pots.sh - builds .pot files for the last 3 versions of CiviCRM.
bgm's avatar
bgm committed
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35

Usage:

- Prepare a directory that has all of the CiviCRM git repositories, ex:
  /path/to/repositories/civicrm-{core,drupal,joomla,wordpress,packages}

  In other words:
    $ mkdir -p ~/repositories/civicrm
    $ cd ~/repositories/civicrm
    $ git clone https://github.com/civicrm/civicrm-core.git
    $ git clone https://github.com/civicrm/civicrm-drupal.git
    $ git clone https://github.com/civicrm/civicrm-joomla.git
    $ git clone https://github.com/civicrm/civicrm-wordpress.git
    $ git clone https://github.com/civicrm/civicrm-packages.git

  WARNING: the script assumes you are tracking "origin",
  the script will "git pull origin $release" for each repo.

- Run this script:
    $ ./bin/build-unified-pots.sh ~/repositories/civicrm po/pot 'v4.1 v4.2 v4.3'
    $ ./bin/build-unified-pots.sh ~/repositories/civicrm po/pot 'v4.1 v4.2 master'

- Push the new strings to Transifex.

NB: since the migration to git, as of 4.3, we hardcode for now that v4.1 and v4.2
are fetched from SVN, and v4.3 from git.
EOT

  exit 1;
}
36 37

SVNROOT="http://svn.civicrm.org/civicrm/branches"
38

bgm's avatar
bgm committed
39
[ "$1" = "--help" ] && usage
bgm's avatar
bgm committed
40 41 42
[ -z "$1" ] || [ -z "$2" ] || [ -z "$3" ] && usage
[ ! -d "$2" ]                             && echo "ERROR: $2: directory not found." && usage
[ -n "$4" ]                               && echo 'ERROR: provide releases as one, space-separated string' && usage
bgm's avatar
bgm committed
43

44 45 46

root="$1"
potdir="$2"
47
releases=`echo "$3" | tr ' ' '\n'`
48 49 50

temp=`mktemp -d`

51
for rel in $releases; do
Mathieu Lutfy's avatar
Mathieu Lutfy committed
52 53 54 55
  ## This can be useful to debug the build process or to test on a trunk checkout
  ## (if you use this, comment out the 'get fresh codebase' block below)
  # cp -r /path/to/civicrm $temp/v4.1

56 57 58 59 60
  mkdir -p $temp/$rel
  mkdir -p $temp/pot/$rel

  pushd .

61 62 63 64 65
  # Get fresh codebase
  # starting 4.3, civicrm is using git
  # assuming that before that, we are fetching from SVN
  # when we drop support for 4.2, we can cleanup this code.
  if [ "$rel" = "v4.2" -o "$rel" = "v4.1" ]; then
66
    svn export --ignore-externals --force "$SVNROOT/$rel" "$temp/$rel"
67
  else
68 69
    cd $root/civicrm-core
    git pull
70
    git archive $rel | tar -xC $temp/$rel
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96

    ## FIXME: will change to 7.x-${rel}
    ## we use ${rel:2} so that v4.3 => 4.3
    mkdir -p $temp/$rel/drupal
    cd $root/civicrm-drupal
    git checkout ${rel:1}-7.x
    git pull
    git archive ${rel:1}-7.x | tar -xC $temp/$rel/drupal

    mkdir -p $temp/$rel/joomla
    cd $root/civicrm-joomla
    git checkout $rel
    git pull
    git archive $rel | tar -xC $temp/$rel/joomla

    mkdir -p $temp/$rel/wordpress
    cd $root/civicrm-wordpress
    git checkout $rel
    git pull
    git archive $rel | tar -xC $temp/$rel/wordpress

    mkdir -p $temp/$rel/packages
    cd $root/civicrm-packages
    git checkout $rel
    git pull
    git archive $rel | tar -xC $temp/$rel/packages
97
  fi
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115

  mkdir $temp/$rel/xml/default
  echo '<?php define("CIVICRM_CONFDIR", ".");' > $temp/$rel/settings_location.php
  echo '<?php define("CIVICRM_UF", "Drupal");' > $temp/$rel/xml/default/civicrm.settings.php

  cd $temp/$rel/xml
  php GenCode.php schema/Schema.xml

  popd

  bin/create-pot-files.sh $temp/$rel $temp/pot/$rel
done

pots=`for pot in $temp/pot/*/*.pot; do basename $pot .pot; done | sort -u | grep -v ^drupal-civicrm$`

# merge per-release files into unified ones
for pot in $pots; do
  echo " * merging $pot.pot files"
116
  msgcat --use-first $temp/pot/*/$pot.pot > $potdir/$pot.pot
117 118 119 120 121 122 123 124
done

# drop strings in common-base.pot from other files
for pot in $pots; do
  [ $pot == 'common-base' ] && continue
  echo " * dropping common-base strings from $pot.pot"
  common=`tempfile`
  msgcomm $potdir/$pot.pot $potdir/common-base.pot > $common
125
  msgcomm --unique $potdir/$pot.pot $common | sponge $potdir/$pot.pot
126 127 128 129 130 131 132 133 134 135
  rm $common
done

# drop strings in common-components.pot from other files
for pot in $pots; do
  [ $pot == 'common-base' ]       && continue
  [ $pot == 'common-components' ] && continue
  echo " * dropping common-components strings from $pot.pot"
  common=`tempfile`
  msgcomm $potdir/$pot.pot $potdir/common-components.pot > $common
136
  msgcomm --unique $potdir/$pot.pot $common | sponge $potdir/$pot.pot
137 138 139 140
  rm $common
done

rm -r $temp