58216ea19c47fe766aa5540e0b73160a22d27e79
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

1) #!/usr/bin/wml
2) 
3) <:
4) 
5) sub getMetadata($) {
6) 	my ($file) = @_;
7) 
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

8) 	die ("File $file is not a regular file") unless (-f $file);
9) 
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

10) 	open(F, "$file") or die ("Cannot open $file: $!\n");
11) 	my $found_metadata = 0;
12) 	while (<F>) {
13) 		chomp;
Peter Palfrader Make translation metadata t...

Peter Palfrader authored 18 years ago

14) 		s/\r$//;
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

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;
Peter Palfrader Make translation metadata t...

Peter Palfrader authored 18 years ago

24) 		s/\r$//;
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

25) 		if (/^#\s*(\S*):\s*(.*?)\s*$/) {
26) 			$data{$1} = $2;
27) 		} else {
28) 			last;
29) 		};
30) 	};
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

31) 	return \%data;
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

32) };
33) 
Peter Palfrader Update translation status

Peter Palfrader authored 18 years ago

34) sub translation_get_masterrevision_file($$) {
35) 	my ($dir, $page) = @_;
36) 	my $master = getMetadata("$dir/en/$page");
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

37) 
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

38) 	die ("Cannot find 'Revision' header in master's translation metadata of en/$page") unless exists $master->{'Revision'};
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

39) 
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

40) 	my ($rev) = $master->{'Revision'} =~ m/([0-9.]+)/;
Peter Palfrader Revert mistaken commit

Peter Palfrader authored 19 years ago

41) 	if ($rev eq '') { $rev = '(Revision not a valid number)'; };
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

42) 
43) 	return $rev;
44) };
Peter Palfrader Add translation-status page

Peter Palfrader authored 19 years ago

45) sub translation_get_masterrevision() {
Peter Palfrader Update translation status

Peter Palfrader authored 18 years ago

46) 	translation_get_masterrevision_file('.', $WML_SRC_FILENAME);
Peter Palfrader Add translation-status page

Peter Palfrader authored 19 years ago

47) };
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

48) 
Peter Palfrader Update translation status

Peter Palfrader authored 18 years ago

49) sub translation_get_basedonrevision_langfile($$$) {
50) 	my ($dir, $lang, $page) = @_;
51) 	my $translation = getMetadata("$dir/$lang/$page");
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

52) 
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

53) 	die ("Cannot find 'Based-On-Revision' header in translations's translation metadata of $lang/$page") unless exists $translation->{'Based-On-Revision'};
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

54) 
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

55) 	my ($rev) = $translation->{'Based-On-Revision'};
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

56) 	if ($rev eq '') { $rev = '(unknown)'; };
57) 
58) 	return $rev
59) };
Peter Palfrader Add translation-status page

Peter Palfrader authored 19 years ago

60) sub translation_get_basedonrevision() {
Peter Palfrader Update translation status

Peter Palfrader authored 18 years ago

61) 	translation_get_basedonrevision_langfile(".", "$(LANG)", $WML_SRC_FILENAME);
Peter Palfrader Add translation-status page

Peter Palfrader authored 19 years ago

62) };
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

63) 
64) 
65) sub translation_current() {
66) 	return (translation_get_masterrevision() eq translation_get_basedonrevision());
67) };
68) 
Peter Palfrader Update translation status

Peter Palfrader authored 18 years ago

69) sub file_is_obsolete($$$) {
70) 	my ($dir, $lang, $page) = @_;
71) 	my $translation = getMetadata("$dir/$lang/$page");
Peter Palfrader Make translation status mor...

Peter Palfrader authored 19 years ago

72) 	return (exists $translation->{'Status'} && ($translation->{'Status'} eq 'obsolete'))
Peter Palfrader Do not mark missing transla...

Peter Palfrader authored 19 years ago

73) };
74) 
Peter Palfrader More languages in the top r...

Peter Palfrader authored 18 years ago

75) sub list_translations() {
76)   my @links = ();
77)   my $page = $WML_SRC_FILENAME;
78)   my $numlangs = 0;
79)   $page =~ s/\.wml//;
80)   for my $dir (sort {$LANGUAGES{$a} cmp $LANGUAGES{$b}} @LANGUAGES) {
81)     if (-e "$dir/$WML_SRC_FILENAME") {
82)       if ($dir ne '$(LANG)') {
83)         push @links, sprintf('<a href="%s.html.%s">%s</a>', $page, $dir, $LANGUAGES{$dir});
84)       };
85)     };
86)   };
87)   return join(', ', @links);
88) };
89) 
90) sub has_translations() {
91)   return list_translations() ne '';
92) };
93)