1#!/bin/bash
2# Dirty-convert a hard-coded translation to a proper external .po file
3#
4# Copyright (C) 2008 Sylvain Beucler
5#
6# This file is part of GNU FreeDink
7#
8# GNU FreeDink 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
11# (at your option) any later version.
12#
13# GNU FreeDink 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
20# <http://www.gnu.org/licenses/>.
21
22(
23    echo 'msgid ""'
24    echo 'msgstr ""'
25    echo '"Project-Id-Version: dmod 1.0\n"'
26    echo '"POT-Creation-Date: 2008-12-07 15:19+0100\n"'
27    echo '"PO-Revision-Date: 2008-12-07 15:18+0100\n"'
28    echo '"Last-Translator: you <email@domain.tld>\n"'
29    echo '"Language-Team: XX <xx@li.org>\n"'
30    echo '"MIME-Version: 1.0\n"'
31    echo '"Content-Type: text/plain; charset=UTF-8\n"'
32    echo '"Content-Transfer-Encoding: 8bit\n"'
33    echo
34
35    (
36	a=0
37	b=0
38	i=0
39	j=0
40	diff -bwBur islandstory islandstoryfr/ \
41	    | grep -E '^(\+|-)[^+-]' \
42	    | grep -vE '//' \
43	    | grep -vE '^(\+|-)[[:space:]]*$' \
44	    | grep -ivE 'debug\("' \
45	    | sed 's/\r//' \
46	    | iconv -f latin1 -t utf-8 \
47	    | while read line; do
48	    if echo "$line" | grep -i -E 'say[a-zA-Z_]*\(' > /dev/null; then
49		if [ -n "$msgids" ]; then
50		    k=0
51		    while [ $k -lt $i ]; do
52			echo "${msgids[$k]}"
53			echo "${msgstrs[$k]}"
54			echo
55			((k++))
56		    done
57		    i=0
58		    j=0
59		fi
60		str=$( echo -n "$line" \
61		    | sed -e 's/.*say[a-zA-Z_]*("\?\(.*\)".*/\1/i' -e 's/^`.//' );
62		echo "$line" | grep '^-' > /dev/null
63		if [ $? = 0 ]; then # "-"
64		    k=0
65		    if [ $b -gt 0 ]; then
66			while [ $k -lt $a ]; do
67			    echo "${smsgids[k]}"
68			    echo "msgstr \"${smsgstrs[k]}\""
69			    echo
70			    ((k++))
71			done
72			a=0
73			b=0
74		    fi
75		    smsgids[a]="msgid \"$str\""
76		    ((a++))
77		else # "+"
78		    if [ $b -eq $a ]; then
79			smsgstrs[b-1]="${smsgstrs[a]} $str"
80		    else
81			smsgstrs[b]="$str"
82			((b++))
83		    fi
84		fi
85	    else
86		# dialogs
87		str=$(echo "$line" | sed -e 's/^.//' -e 's/^[[:space:]]*\(.*\)[[:space:]]*$/\1/' \
88		                         -e 's/^([^"]*)[[:space:]]*"/"/' -e 's/^[^"].*$/"&"/')
89		if echo "$line" | grep '^-' > /dev/null; then
90		    msgids[i]="msgid $str"
91		    ((i++))
92		else
93		    msgstrs[j]="msgstr $str"
94		    ((j++))
95		fi
96	    fi
97	done
98    )  | tail -n+3  # skip first empty entry
99) > t.po
100
101# Remove duplicates
102msguniq t.po > t2.po
103
104msgmerge t2.po island.pot > fr.po
105msgfmt -c --statistics fr.po
106
107exit
108
109
110TODO: dialog choices:
111
112  choice_start();
113  title_start();
114
115  My title
116  title_end();
117  "Freak out"
118  "Stay calm"
119  choice_end();
120
121
122Sample .po:
123
124  msgid "Error: Invalid .dmod file selected!"
125  msgstr "Erreur: fichier .dmod sélectionné invalide!"
126