a directory for the translated manpages with a template wml and a script
Runa A. Sandvik

Runa A. Sandvik commited on 2010-05-27 19:25:58
Zeige 2 geänderte Dateien mit 136 Einfügungen und 0 Löschungen.

... ...
@@ -0,0 +1,115 @@
1
+#!/bin/bash
2
+#
3
+# Author: Runa A. Sandvik, <runa.sandvik@gmail.com>
4
+# For The Tor Project, Inc.
5
+#
6
+# This is Free Software (GPLv3)
7
+# http://www.gnu.org/licenses/gpl-3.0.txt
8
+#
9
+# This script will convert translated po files back to manpages. Before
10
+# running the script, checkout the translation directory from
11
+# https://svn.torproject.org, and clone the tor repository from
12
+# git.torproject.org.
13
+#	
14
+
15
+### Start config ###
16
+
17
+# Location of the translated manpages
18
+translated="$PWD"
19
+
20
+# Location of the website directory
21
+wml="`dirname $translated`"
22
+
23
+# Location of the English manpages. Assuming that the git clone of the
24
+# tor repository is relative to the website
25
+mandir="`dirname $wml`/tor/doc"
26
+
27
+# Location of the po files. Assuming that the translation directory is
28
+# relative to the website
29
+podir="`dirname $wml`/translation/projects/manpages"
30
+
31
+### End config ###
32
+
33
+# Find po files to convert
34
+po=`find $podir -type f -name \*.1.po`
35
+
36
+# For every po found, create and/or update the translated manpage.
37
+for file in $po ; do
38
+
39
+	# Get the basename of the file we are dealing with
40
+	pofile=`basename $file`
41
+
42
+	# Strip the file for its original extension and add .txt
43
+	manfile="${pofile%.*}.txt"
44
+
45
+	# Figure out which language we are dealing with.
46
+	lang=`dirname $file | sed "s#$podir/##"`
47
+
48
+	# The translated document is written if 80% or more of the po
49
+	# file has been translated. Also, po4a-translate will only write
50
+	# the translated document if 80% or more has been translated.
51
+	# However, it will delete the translated txt if less than 80%
52
+	# has been translated. To avoid having our current, translated
53
+	# txt files deleted, convert the po to a temp txt first. If this
54
+	# file was actually written, rename it to txt.
55
+
56
+	# Convert translated po files back to manpages.
57
+	function convert {
58
+		po4a-translate -f text -m "$mandir/$manfile" -p "$file"  -l "$translated/$lang/tmp-$manfile" --master-charset utf-8 -L utf-8
59
+
60
+		# Check to see if the file was written. If yes, rename
61
+		# it.
62
+		if [ -e "$translated/$lang/tmp-$manfile" ]
63
+		then
64
+			mv "$translated/$lang/tmp-$manfile" "$translated/$lang/$manfile"
65
+
66
+			# If tor.1.po has been translated, we need to
67
+			# create tor-manual-dev.wml in the correct
68
+			# language directory.
69
+			if [ $manfile = "tor.1.txt" ]
70
+			then
71
+				if [ ! -e "$wml/$lang/tor-manual.wml" ]
72
+				then
73
+					# Copy template file for
74
+					# tor-manual-dev.wml, and
75
+					# replace "lang" with the
76
+					# correct name of the language
77
+					# directory.
78
+					cp "$translated/tor-manual-dev.wml" "$wml/$lang"
79
+				       	sed -i "0,/lang/ s/lang/"$lang"/" "$wml/$lang/tor-manual-dev.wml"	
80
+				fi
81
+			fi
82
+		fi
83
+	}
84
+
85
+	# We have a few cases where the name of the language directory
86
+	# in the translations module is not equal the name of the
87
+	# language directory in the website module.
88
+
89
+	# For "zh_CN" use "zh-cn" instead
90
+	if [ $lang = "zh_CN" ]
91
+	then
92
+		lang="zh-cn"
93
+		convert
94
+	fi
95
+
96
+	# For "nb" use "no" instead
97
+	if [ $lang = "nb" ]
98
+	then
99
+		lang="no"
100
+		convert
101
+	fi
102
+
103
+	# For "sv" use "se" instead
104
+	if [ $lang = "sv" ]
105
+	then
106
+		lang="se"
107
+		convert
108
+	fi
109
+
110
+	# Convert everything else
111
+	if [[ $lang != "zh_CN" && $lang != "nb" && $lang != "sv" ]]
112
+	then
113
+		convert
114
+	fi
115
+done
... ...
@@ -0,0 +1,21 @@
1
+## translation metadata
2
+# Revision: $Revision: 21567 $
3
+
4
+#include "head.wmi" TITLE="Tor: manual"
5
+
6
+# Translators shouldn't translate this file, unless they want
7
+# to translate the whole man page too.
8
+
9
+<div class="main-column">
10
+
11
+<:
12
+	die "Missing git clone" unless -d "$(TORGIT)";
13
+	my $man = `cat manpages/lang/tor.1.txt | asciidoc -d manpage -s -o - -`;
14
+	die "No manpage because of asciidoc error or file not available from git" unless $man;
15
+
16
+	print $man;
17
+:>
18
+
19
+</div><!-- #main -->
20
+
21
+#include <foot.wmi>
0 22