compile-mo-files.sh 2.21 KB
Newer Older
1 2
#!/bin/bash

3 4 5 6
function usage() {
  cat <<EOT
compile-mo-files.sh - compiles the .po files to binary .mo format
At runtime, gettext uses the compiled .mo format to translate strings (faster).
7

8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
Usage:

  ./bin/compile-mo-files.sh [locale]

Example:

  ./bin/compile-mo-files.sh
  ./bin/compile-mo-files.sh fr

EOT

  exit 1;
}

function compile_po () {
  lang=$1

25 26
  if [ ! -d "workdir/mo/$lang" ]; then
    mkdir -p workdir/mo/$lang
27 28
  fi

29
  echo -n "compiling $lang ... "
30
  msgcat --use-first po/$lang/*.po | msgfmt -o workdir/mo/$lang/civicrm.mo -
31 32 33 34 35 36 37
  echo "done"
}

if [ "$1" = "--help" -o "$1" = "-h" ]; then
  usage
fi

38 39 40
# This makes it easier to configure crons on civi infrastructure,
# while still making it possible to use this script in other places.
if [ ! -d "po" ]; then
41 42
  if [ -d "$HOME/l10n/civicrm-l10n-core/po" ]; then
    cd $HOME/l10n/civicrm-l10n-core
43 44 45 46 47 48 49
  else
    echo "ERROR: Could not find the location of the civicrm-l10n repository."
    echo ""
    usage
  fi
fi

50 51 52 53 54 55 56 57 58 59 60 61 62
if [ -n "$1" ]; then
  if [ -d "po/$1" ]; then
    compile_po $1
  else
    echo "Error: $1: invalid locale (not found in the ./po/ directory)."
    exit 1
  fi
else
  langs=`ls -1d po/?? po/??_?? | cut -d/ -f2`
  
  for lang in $langs; do
    compile_po $lang
  done
63 64 65 66 67

  # To avoid annoying people who may be using this script,
  # check that we are running as the l10n user.
  user=`whoami`

68
  if [ "$user" = "jenkins" -o "$user" = "publisher" ]; then
69 70 71
    mkdir -p $WORKSPACE/publish

    # Copy over the .mo files included in the daily tar.gz
72 73
    for i in $(cat conf/distributed_languages.txt); do
      mkdir -p workdir/l10n/$i/LC_MESSAGES
74
      cp workdir/mo/$i/civicrm.mo workdir/l10n/$i/LC_MESSAGES/
75 76 77
    done

    pushd workdir
78 79 80
    mkdir -p $WORKSPACE/publish/archives
    tar cfz $WORKSPACE/publish/archives/civicrm-l10n-daily.tar.gz l10n
    md5sum $WORKSPACE/publish/archives/civicrm-l10n-daily.tar.gz > $WORKSPACE/publish/archives/civicrm-l10n-daily.tar.gz.MD5SUMS
81
    popd
82 83

    # Copy over the .mo files to publish on gcloud
84
    # The jenkins job picks up the files in this directory and takes care of pushing.
85 86
    for lang in $langs; do
      mkdir -p $WORKSPACE/publish/mo/$lang
87
      cp workdir/mo/$lang/civicrm.mo $WORKSPACE/publish/mo/$lang/civicrm.mo
88
    done
89
  fi
90
fi