49eca30550d51d4fdc9fd3c6d5005d1044653d1d
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) 
Bogdan Drozdowski Translation/mainetance upda...

Bogdan Drozdowski authored 17 years ago

55) #	my ($rev) = $translation->{'Based-On-Revision'};
56) 	my ($rev) = $translation->{'Based-On-Revision'} =~ m/([0-9.]+)/;
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

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

Peter Palfrader authored 19 years ago

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

Peter Palfrader authored 18 years ago

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

Peter Palfrader authored 19 years ago

63) };
Peter Palfrader Move website to wml

Peter Palfrader authored 19 years ago

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

Peter Palfrader authored 18 years ago

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

Peter Palfrader authored 19 years ago

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

Peter Palfrader authored 19 years ago

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

Peter Palfrader authored 18 years ago

76) sub list_translations() {
77)   my @links = ();
78)   my $page = $WML_SRC_FILENAME;
79)   $page =~ s/\.wml//;
Peter Palfrader Add russian translation

Peter Palfrader authored 18 years ago

80)   for my $dir (@LANGUAGES) {
Peter Palfrader More languages in the top r...

Peter Palfrader authored 18 years ago

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)