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

3 4 5
set -e
set -x

bgm's avatar
bgm committed
6 7
function usage() {
  cat <<EOT
bgm's avatar
bgm committed
8
build-unified-pots.sh - builds .pot files for the last 3 versions of CiviCRM.
bgm's avatar
bgm committed
9 10 11

Usage:

12 13 14
- Prepare a CiviCRM checkout that also has all of the sub-repositories, ex:
  /path/to/repositories/civicrm/{drupal,joomla,wordpress,packages}
  where the 'civicrm' directory corresponds to civicrm-core.git.
15

16
- Make sure your repository is up to date (git fetch --all).
bgm's avatar
bgm committed
17

18 19
- Run this script (where 4.7.12 is the latest version of CiviCRM):
    $ ./bin/build-unified-pots.sh ~/repositories/civicrm po/pot '4.6 4.7.12' 2>&1 | tee pots.log
20 21

  or, for master:
22
    $ ./bin/build-unified-pots.sh ~/repositories/civicrm po/pot '4.6 master' 2>&1 | tee pots.log
23 24

- Use diff-check.php to see if the changes make sense. For example:
25
    $ git diff -U2000 --patience po/pot/admin.pot | ./bin/diff-check.php
bgm's avatar
bgm committed
26 27 28

- Push the new strings to Transifex.

29
NB: We usually build the po files that are compatible for the last 3 versions
30 31
of CiviCRM. For example, as of 4.6, this means the po files will be compatible
with CiviCRM 4.6, 4.5 and 4.4.
bgm's avatar
bgm committed
32 33

For more information:
34
http://wiki.civicrm.org/confluence/display/CRMDOC/Pushing+new+strings+to+Transifex
bgm's avatar
bgm committed
35 36 37 38
EOT

  exit 1;
}
39

bgm's avatar
bgm committed
40
[ "$1" = "--help" ] && usage
bgm's avatar
bgm committed
41 42 43
[ -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
44

45 46 47

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

temp=`mktemp -d`

53
for rel in $releases; do
54 55 56 57 58
  mkdir -p $temp/$rel
  mkdir -p $temp/pot/$rel

  pushd .

59
  # Get fresh codebase
60

61 62 63 64 65 66
  # we use ${rel:1} so that v4.3 => 4.3, except for "master".
  # r=${rel:1}
  # if [ "$rel" = "master" ]; then
  #  r="master"
  # fi

67 68 69
  echo "Copying $root ($rel) to $temp/$rel ..."
  cd $root
  git checkout $rel
70
  git archive $rel | tar -xC $temp/$rel
71

72
  echo "Copying $root/drupal (7x-$rel) to $temp/$rel/drupal ..."
73
  mkdir -p $temp/$rel/drupal
74 75
  cd $root/drupal
  git checkout 7.x-$rel
76 77
  git archive 7.x-$rel | tar -xC $temp/$rel/drupal

78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
  if [ -d $root/joomla ]; then
    echo "Copying $root/joomla ($rel) to $temp/$rel/joomla ..."
    mkdir -p $temp/$rel/joomla
    cd $root/joomla
    git checkout $rel
    git archive $rel | tar -xC $temp/$rel/joomla
  else
    echo "Skipping missing $root/joomla."
    echo "As of CiviCRM 4.6 there aren't any strings in it, but that could change in the future?"
  fi

  if [ -d $root/wordpress ]; then
    echo "Copying $root/wordpress ($rel) to $temp/$rel/wordpress ..."
    mkdir -p $temp/$rel/wordpress
    cd $root/wordpress
    git checkout $rel
    git archive $rel | tar -xC $temp/$rel/wordpress
  else
    echo "Skipping missing $root/wordpress."
    echo "As of CiviCRM 4.6 there aren't any strings in it, but that could change in the future?"
  fi

  echo "Copying $root/packages ($rel) to $temp/$rel/packages ..."
101
  mkdir -p $temp/$rel/packages
102 103
  cd $root/packages
  git checkout $rel
104 105
  git archive $rel | tar -xC $temp/$rel/packages

106 107 108 109
  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

110 111 112 113 114 115
  if [ -f $temp/$rel/composer.json ]; then
    echo "Running composer install ..."
    cd $temp/$rel
    composer install
  fi

bgm's avatar
bgm committed
116
  echo "Running GenCode.php ..."
117
  cd $temp/$rel/xml
bgm's avatar
bgm committed
118
  php GenCode.php schema/Schema.xml | grep -v Generating
119 120 121

  popd

122 123 124 125 126 127 128
  if [ -f $temp/tools/bin/scripts/create-pot-files.sh ]; then
    echo "Executing: $temp/tools/bin/scripts/create-pot-files.sh $temp/$rel $temp/pot/$rel"
    $temp/tools/bin/scripts/create-pot-files.sh $temp/$rel $temp/pot/$rel
  else
    echo "Executing: create-pot-files.sh $temp/$rel $temp/pot/$rel"
    bin/create-pot-files.sh $temp/$rel $temp/pot/$rel
  fi
129 130 131 132 133
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
bgm's avatar
bgm committed
134
echo "Merging pots files of various versions: $pots ..."
135 136
for pot in $pots; do
  echo " * merging $pot.pot files"
137
  msgcat --use-first $temp/pot/*/$pot.pot > $potdir/$pot.pot
138 139 140 141 142 143 144 145
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
146
  msgcomm --unique $potdir/$pot.pot $common | sponge $potdir/$pot.pot
147 148 149 150 151 152 153 154 155 156
  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
157
  msgcomm --unique $potdir/$pot.pot $common | sponge $potdir/$pot.pot
158 159 160 161
  rm $common
done

rm -r $temp
bgm's avatar
bgm committed
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194

cat <<EOT

ALL DONE

Next step is to review the new strings with "git diff".
You are strongly encouraged to use the "patience" algorightm otherwise
the diffs will seem bigger than they actually are:

    $ git status
    $ git diff --patience

If it all looks good, commit the changes:

    $ git add po/pot/*
    $ git tag 4.3.1
    $ git push --tags

After that, you can push the source pot files to Transifex:

    $ tx push -s

If a new component was added to CiviCRM (i.e. you have a new something.pot
that was created), it needs to be added to Transifex. For example:

    $ tx set --auto-local -r civicrm.pcp 'po/<lang>.po' --source-lang en --source-file po/pot/pcp.pot --execute
    $ tx push -s -r civicrm.pcp
    $ tx pull -a -r civicrm.pcp

NB: use the "patience" diff algorithm from git to generate cleaner diffs:
    $ git config --global diff.algorithm patience

EOT