summaryrefslogtreecommitdiff
path: root/l10n/gen-pot-file
blob: bae78ef96a4a98aabb680e54a3d6f9f3c3bfdbd1 (plain)
1
2
3
4
5
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash

CWD=`pwd`

SCRIPT_DIR=`cd $(dirname ${BASH_SOURCE[0]}) >/dev/null 2>&1 && pwd`
program=`basename $0`

save_new_version() {
  local ifile=${1}
  local ofile=${2}
  local iline=`cat ${ifile} | grep 'Project-Id-Version:'`
  local version=`echo ${iline} | cut -f2 -d':' | tr -s ' ' | sed 's,^[ \t]*,,' | sed 's,[ \t]*$,,' | sed 's,[\]n["]$,,'`

  local oline=`cat ${ofile} | grep -n 'Project-Id-Version:' | cut -f2,3 -d':'`
  local olnum=`cat ${ofile} | grep -n 'Project-Id-Version:' | cut -f1 -d':'`

  if [ ! -z "${oline}" -a -z "`echo ${oline} | grep "${version}"`" ] ; then
    echo "$ifile: Keep new 'Project-Id-Version: ${version}'"
       sed -i "${olnum} c\
\"Project-Id-Version: ${version}\\\n\"" ${ofile}
  fi
}

cd ${SCRIPT_DIR}/..

PACKAGE_VERSION=`cat configure.ac | grep AC_INIT | sed 's,.*\[\([.0-9]*\)\].*,\1,'`

POTFILE=po/libmpu.pot

if [ -f "$POTFILE" ] ; then
  cp -a ${POTFILE} ${POTFILE}~
fi

xgettext --from-code=UTF-8 --keyword=N_ --keyword=_ --keyword=Q_:1,2  \
         --language=C --add-comments --sort-output --no-wrap \
         --msgid-bugs-address="Andrey V.Kosteltsev <support@radix-linux.su>" \
         --package-name=libmpu \
         --package-version=${PACKAGE_VERSION} \
         --copyright-holder="Andrey V.Kosteltsev <kx@radix-linux.su>" \
         --default-domain=libmpu --output=${POTFILE} \
         `find -type f -name "*.c"`

( cd po ;
  _LOCALE=ru_RU.utf8
  _PO_FNAME=ru
  mv ${_PO_FNAME}.po ${_PO_FNAME}.po~
  echo -en "Create new ${_PO_FNAME}.po file:\n.. "
  msginit --no-translator --no-wrap --locale=${_LOCALE} --input=libmpu.pot --output-file=${_PO_FNAME}.po
  echo "Merge translated strings back ${_PO_FNAME}.po:"
  msgmerge --no-wrap ${_PO_FNAME}.po~ ${_PO_FNAME}.po > ${_PO_FNAME}.po.new
  # ======= Save new version: =======
  save_new_version ${_PO_FNAME}.po ${_PO_FNAME}.po.new
  mv ${_PO_FNAME}.po.new ${_PO_FNAME}.po
#  rm -f ${_PO_FNAME}.po~
)

cd l10n