compile-mo-files.sh 2.25 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
  if [ -d "$HOME/repositories/civicrm-l10n-core/po" ]; then
42
    cd $HOME/repositories/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 68

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

  if [ "$user" = "l10n" ]; then
69 70
    for i in $(cat conf/distributed_languages.txt); do
      mkdir -p workdir/l10n/$i/LC_MESSAGES
71
      cp workdir/mo/$i/civicrm.mo workdir/l10n/$i/LC_MESSAGES/
72 73 74
    done

    pushd workdir
75
    tar cfz civicrm-l10n-daily.tar.gz l10n
76 77
    md5sum civicrm-l10n-daily.tar.gz > civicrm-l10n-daily.tar.gz.MD5SUMS

78 79 80 81 82
    echo -n "Rsync civicrm-l10n-daily.tar.gz to download.civicrm.org ... "
    rsync civicrm-l10n-daily.tar.gz l10n@download.civicrm.org:/var/www/download.civicrm.org/public/civicrm-l10n-core/archives/
    rsync civicrm-l10n-daily.tar.gz.MD5SUMS l10n@download.civicrm.org:/var/www/download.civicrm.org/public/civicrm-l10n-core/archives/

    echo -n "Rsync all .mo files to download.civicrm.org ... "
83 84
    rsync --delete -ra mo l10n@download.civicrm.org:/var/www/download.civicrm.org/public/civicrm-l10n-core/
    echo "done!"
85 86 87

    rm civicrm-l10n-daily.tar.gz*
    popd
88
  fi
89
fi