File: make_docs

package info (click to toggle)
album 4.18-1
  • links: PTS, VCS
  • area: non-free
  • in suites: forky, sid
  • size: 3,324 kB
  • sloc: perl: 5,506; makefile: 2
file content (138 lines) | stat: -rwxr-xr-x 3,483 bytes parent folder | download | duplicates (3)
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/perl

my $proj = "/data/proj/languages";
my $flags = "$proj/flags";
#my $langs = "$proj/iso-639-1";
#my $langs = "$proj/iso-639-2";
#my $langs = "/data/proj/album/Language/LIST";
my $langs = "$proj/all_languages";

#########################
# Read the language codes
#########################
open(LANGS,"<$langs") || die("Couldn't read $langs");
print "READING: $langs\n";
my $curr;
while (<LANGS>) {
	# iso-639-2
	#$lang{$1} = $2 if /^(...); (.+?)(; |$)/;

	# iso-639-1
	#$lang{$1} = $2 if /^(..)\s+(.+?)(; |$)/;

	# Language/LIST
	$lang{$1} = $2 if /^(..)=(.+)/;

	# all_languages";
	$curr=$1 if /^\[(\S+)\]$/;
	$lang{$curr}=$1 if /^Name\[$curr\]=(.*)/;
}
$lang{en} = "English";
close LANGS;

#########################
# What other languages do we have docs for?
#########################
opendir(DOC,".") || die("Couldn't opendir(.)");
my @lang = grep(!/^\.{1,2}$/ && -d $_ && !-l $_ && $lang{$_}, readdir(DOC));
@lang = grep($_ ne "Pics", @lang);
closedir(DOC);

#########################
# What txt_ files do we need?
#########################
my @txt = <txt_*>;

#########################
# Create the language menu
#########################
sub url {
	my ($from, $to) = @_;
	return undef if $from eq $to;
	my $url = $to eq "en" ? "" : $to;
	$url = "../$url" unless $from eq "en";
	return $url;
}
sub href {
	my ($from, $to) = @_;
	my $url = url($from,$to);
	return $url ? "<a href=\"$url\">$lang{$to}</a>" : $lang{$to};
}
sub flag {
	my ($from, $to) = @_;
	my $p = url($from,$to);
	return $p ? "$p/flag.png" : "flag.png";
}
sub langline {
	my ($from,$to) = @_;
	my $iso639_1 = iso639_1($to);
	my $flag = flag($from,$to);
	system("cp $flags/$to.png $flag ; chmod ugo+r $flag") if -f "$flags/$to.png" && ! -f $flag;
	$flag = -f $flag ? "<img src=\"$flag\">" : "-";
	my $href=href($from,$to);
	my $url=url($from,$to);

	print LANGMENU "<br><span lang='$iso639_1'>&nbsp;&nbsp; $flag &nbsp;&nbsp;$href</span>\n";

	# We should use translations of "album documentation" here:
	my $urlOUT = $url;
	$urlOUT .= '/' unless $url =~ /\/$/;
	$urlOUT .= '$OUT';
	print LANGHTML "\t<link rel='alternate' type='text/html' href='$urlOUT' hreflang='$iso639_1' lang='$iso639_1' title='album documentation'>\n"
	  unless $from eq $to;
	print LANGHTML "\t<meta http-equiv='Content-Language' content='$iso639_1'>\n"
		if $from eq $to;
}

sub iso639_1 {
	my ($iso639_2) = @_;
	# This substr is hokey bullshit.  ISO 639-1 is obsolete, but it's
	# what the web uses!  List: http://www.loc.gov/standards/iso639-2/englangn.html
	substr($iso639_2,0,2);
}

sub langmenu {
	my ($from) = @_;
	open(LANGMENU,">langmenu") || die("Can't write langmenu");
	open(LANGHTML,">langhtml") || die("Can't write langhtml");

	my $iso639_1 = iso639_1($from);
	#print LANGHTML "<html lang='$iso639_1'>\n<head>\n";
	print LANGHTML "<html>\n<head>\n";
	print LANGHTML <<STYLE if $from ne "en";
	<style>
	<!--
	:lang($iso639_1) { color: green; }
	-->
	</style>
STYLE

	foreach my $to ( "en", @lang ) {
		langline($from,$to);
	}
	close LANGMENU;
}

#########################
# Make docs for english
#########################
langmenu("en");
system("make_faq");

#########################
# Make docs for other languages
#########################
foreach my $lang ( @lang ) {
	print "Language: $lang - $lang{$lang}\n";
	chdir $lang;
	foreach my $txt ( @txt ) {
		symlink("../$txt",$txt);
	}
	symlink("../conf","conf");
	langmenu($lang);
	system("make_faq");
	chdir "..";
}

unlink("langmenu");
unlink("langhtml");