translations.pl 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
  2. # 2004 Tilmann Holst <spam@tholst.de>
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 3 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. use strict;
  17. use v5.10;
  18. AddModuleDescription('translations.pl', 'Translation Extension');
  19. our (@MyRules, $FreeLinkPattern);
  20. push(@MyRules, \&TranslationRule);
  21. sub TranslationRule {
  22. if (m/\G(\&lt;translation +\[\[$FreeLinkPattern\]\] +(\d+)\&gt;[ \t]*)/cg) {
  23. Dirty($1);
  24. print GetTranslationLink($2, $3);
  25. return '';
  26. }
  27. return;
  28. }
  29. sub GetCurrentPageRevision {
  30. my $id = shift;
  31. return ParseData(ReadFileOrDie(GetPageFile($id)))->{revision};
  32. }
  33. sub GetTranslationLink {
  34. my ($id, $revision) = @_;
  35. my $result = "";
  36. my $currentRevision;
  37. $id =~ s/^\s+//; # Trim extra spaces
  38. $id =~ s/\s+$//;
  39. $id = FreeToNormal($id);
  40. $result = Ts('This page is a translation of %s.', GetPageOrEditLink( $id, '', 0, 1));
  41. $result .= ' ';
  42. $currentRevision = GetCurrentPageRevision($id);
  43. if ($currentRevision == $revision) {
  44. $result .= T("The translation is up to date.");
  45. } elsif ( $currentRevision > $revision ) {
  46. $result .= T("The translation is outdated.") . ' '
  47. . ScriptLink("action=browse&diff=1&id=$id&revision=$currentRevision&diffrevision=$revision",
  48. T("(diff)"));
  49. } else {
  50. $result .= T("The page does not exist.");
  51. }
  52. return $result;
  53. }