File: extract-tr-strings

package info (click to toggle)
uranium 3.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 5,876 kB
  • sloc: python: 22,349; sh: 111; makefile: 11
file content (73 lines) | stat: -rwxr-xr-x 1,851 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/bin/sh
#
# This script extracts strings from a set of files using Qt's translation system.
# It then converts the extracted .ts file in a .po file that can be used with
# tools that expect Gettext's po file format.
#
# This script was adapted from extract-tr-strings from KDE's translation scripts.
# extract-tr-strings is Copyright 2014 Aurélien Gateau <agateau@kde.org>
set -e

OLD_PWD=$PWD
cd $(dirname $0)
SCRIPTS_DIR=$PWD
cd $OLD_PWD

LUPDATE=${LUPDATE:-lupdate}
LCONVERT=${LCONVERT:-lconvert}

die() {
    echo "ERROR: $*" >&2
    exit 1
}

usage() {
    cat <<EOF
Usage: $(basename $0) [src_files]... -o [pot_file]

Creates a .pot file for code translated using Qt translation system.
EOF
    exit 1
}

src_files=""
pot_file=""
while [ $# -gt 0 ] ; do
    case "$1" in
    -h|--help)
        usage
        ;;
    -o|--output)
        pot_file="$2"
        shift 2
        ;;
    -*)
        die "Unknown option $1"
        ;;
    *)
        src_files="$src_files $1"
        shift
        ;;
    esac
done

if [ -z "$src_files" ] ; then
    die "No source files provided"
fi
if [ -z "$pot_file" ] ; then
    die "No pot file provided, please provide one with the -o option"
fi

# "Reserve" a name for a temporary .ts file where lupdate can store its output.
# The .ts file is created in the directory where Messages.sh is to ensure
# lupdate creates file paths relative to this directory.
# lupdate fails if we pass it an existing but empty file, so we have to rm the
# temporary file we just created. It is not completely safe, but since this
# script is always running in a trusted environment we can assume it is OK.
tmp_ts=$(mktemp $PWD/extract-tr-strings-XXXXXX.ts)
trap "rm -rf $tmp_ts" 0
trap "exit 2" 1 2 3 13 15
rm $tmp_ts

$LUPDATE -silent $src_files -ts $tmp_ts
$LCONVERT $tmp_ts --sort-contexts --output-format pot -o $pot_file