Fix multi-leg promotions
[xboard.git] / po / lng2po.sh
1 #!/bin/bash
2 #  lng2po.sh -- translating .lng files to .po files for XBoard/Winboard,
3 #               part of XBoard GNU project
4 #
5 #  Copyright 2011, 2013, 2014, 2015, 2016 Free Software Foundation, Inc.
6 #  ------------------------------------------------------------------------
7 #
8 #  GNU XBoard is free software: you can redistribute it and/or modify
9 #  it under the terms of the GNU General Public License as published by
10 #  the Free Software Foundation, either version 3 of the License, or (at
11 #  your option) any later version.
12 #
13 #  GNU XBoard is distributed in the hope that it will be useful, but
14 #  WITHOUT ANY WARRANTY; without even the implied warranty of
15 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 #  General Public License for more details.
17 #
18 #  You should have received a copy of the GNU General Public License
19 #  along with this program. If not, see http://www.gnu.org/licenses/.  *
20 #
21 # ------------------------------------------------------------------------
22
23
24 INFO="lng2po.sh (translating .lng files to .po files for XBoard/Winboard)"
25 USAGE="Usage: `basename $0` [-hv] [-o outputfile] [-e encoding] <input.lng>
26                default encoding:    latin-1
27                default output file: ./language.po"
28
29 VERSION="1"
30
31 # default options
32 OUTPUT="language.po"
33 ENCODING="latin-1"
34 INPUT=""
35 TMPFILE=`mktemp lng2poXXXXX`
36
37 # parse command line arguments
38 while getopts hvo:e: OPT; do
39     case "$OPT" in
40         h)  echo $USAGE
41             exit 0
42             ;;
43         v)  echo "`basename $0` version: $VERSION"
44             exit 0
45             ;;
46         o)  OUTPUT=$OPTARG
47             ;;
48         e)  ENCODING=$OPTARG
49             ;;
50         \?) # getopts issues an error message
51             echo $USAGE >&2
52             exit 1
53             ;;
54         :) echo " Error:options -e and -o need an argument"
55             exit 2
56             ;;
57     esac
58 done
59
60 # move past the parsed commands in $@
61 shift `expr $OPTIND - 1`
62
63 # check if an input file was given and if it exists in ./ or winboard/languages
64 # also check if it's a .lng file
65 if [ $# -ne 1 ]; then
66     echo "  Error: Need to specify an input file"
67     exit 3
68 else
69     if [ ${1: -4} == ".lng" ]; then
70         INPUT=$1
71     else
72         echo " Error: Input file needs to be a .lng file"
73         exit 4
74     fi
75 fi
76
77 if [ -e ../winboard/language/$INPUT ]; then
78     INPUT=../winboard/language/$INPUT
79 fi
80
81 if [ -e $INPUT ]; then
82    # do the conversion
83
84    cp $INPUT $TMPFILE
85    recode $ENCODING $TMPFILE
86    ed $TMPFILE < metascript
87    rm $TMPFILE
88    cp xboard.pot $OUTPUT
89    ed $OUTPUT < lng2po-helper-script
90    rm lng2po-helper-script
91    echo "created $OUTPUT"
92 else
93     echo " Error: Couldn't find input file ($INPUT) in current directory or winboard/languages"
94     exit 5
95 fi
96