Browse code

switch to Goldstein's idea of $lang/$dir/$page to keep all languages in their own subdir, rather than spread throughout the site.

Andrew Lewman authored on14/07/2010 21:39:08
Showing1 changed files
... ...
@@ -48,7 +48,7 @@ sub translation_get_masterrevision() {
48 48
 
49 49
 sub translation_get_basedonrevision_langfile($$$) {
50 50
 	my ($dir, $lang, $page) = @_;
51
-	my $translation = getMetadata("$dir/$lang/$page");
51
+	my $translation = getMetadata("$lang/$dir/$page");
52 52
 
53 53
 	if (exists $translation->{'Based-On-Revision'}) {
54 54
 		return $translation->{'Based-On-Revision'};
... ...
@@ -67,7 +67,7 @@ sub translation_current() {
67 67
 
68 68
 sub file_is_obsolete($$$) {
69 69
 	my ($dir, $lang, $page) = @_;
70
-	my $translation = getMetadata("$dir/$lang/$page");
70
+	my $translation = getMetadata("$lang/$dir/$page");
71 71
 	return (exists $translation->{'Status'} && ($translation->{'Status'} eq 'obsolete'))
72 72
 };
73 73
 
Browse code

first cut of the new, shiny tor website as wml.

Andrew Lewman authored on09/07/2010 03:55:22
Showing1 changed files
1 1
new file mode 100644
... ...
@@ -0,0 +1,92 @@
1
+#!/usr/bin/wml
2
+
3
+<:
4
+
5
+sub getMetadata($) {
6
+	my ($file) = @_;
7
+
8
+	die ("File $file is not a regular file") unless (-f $file);
9
+
10
+	open(F, "$file") or die ("Cannot open $file: $!\n");
11
+	my $found_metadata = 0;
12
+	while (<F>) {
13
+		chomp;
14
+		s/\r$//;
15
+		if ($_ eq '## translation metadata') {
16
+			$found_metadata = 1;
17
+			last;
18
+		};
19
+	};
20
+	die ("Did not find translation metadata in $file") unless $found_metadata;
21
+	my %data;
22
+	while (<F>) {
23
+		chomp;
24
+		s/\r$//;
25
+		if (/^#\s*(\S*):\s*(.*?)\s*$/) {
26
+			$data{$1} = $2;
27
+		} else {
28
+			last;
29
+		};
30
+	};
31
+	return \%data;
32
+};
33
+
34
+sub translation_get_masterrevision_file($$) {
35
+	my ($dir, $page) = @_;
36
+	my $master = getMetadata("$dir/en/$page");
37
+
38
+	die ("Cannot find 'Revision' header in master's translation metadata of en/$page") unless exists $master->{'Revision'};
39
+
40
+	my ($rev) = $master->{'Revision'} =~ m/([0-9.]+)/;
41
+	if ($rev eq '') { $rev = '(Revision not a valid number)'; };
42
+
43
+	return $rev;
44
+};
45
+sub translation_get_masterrevision() {
46
+	translation_get_masterrevision_file('.', $WML_SRC_FILENAME);
47
+};
48
+
49
+sub translation_get_basedonrevision_langfile($$$) {
50
+	my ($dir, $lang, $page) = @_;
51
+	my $translation = getMetadata("$dir/$lang/$page");
52
+
53
+	if (exists $translation->{'Based-On-Revision'}) {
54
+		return $translation->{'Based-On-Revision'};
55
+	} else {
56
+		 return '(unknown)';
57
+	}
58
+};
59
+sub translation_get_basedonrevision() {
60
+	translation_get_basedonrevision_langfile(".", "$(LANG)", $WML_SRC_FILENAME);
61
+};
62
+
63
+
64
+sub translation_current() {
65
+	return (translation_get_masterrevision() eq translation_get_basedonrevision());
66
+};
67
+
68
+sub file_is_obsolete($$$) {
69
+	my ($dir, $lang, $page) = @_;
70
+	my $translation = getMetadata("$dir/$lang/$page");
71
+	return (exists $translation->{'Status'} && ($translation->{'Status'} eq 'obsolete'))
72
+};
73
+
74
+sub list_translations() {
75
+  my @links = ();
76
+  my $page = $WML_SRC_FILENAME;
77
+  $page =~ s/\.wml//;
78
+  for my $dir (@LANGUAGES) {
79
+    if (-e "$dir/$WML_SRC_FILENAME") {
80
+      if ($dir ne '$(LANG)') {
81
+        push @links, sprintf('<a href="%s.html.%s">%s</a>', $page, $dir, $LANGUAGES{$dir});
82
+      };
83
+    };
84
+  };
85
+  return join(', ', @links);
86
+};
87
+
88
+sub has_translations() {
89
+  return list_translations() ne '';
90
+};
91
+
92
+:>