translations.pl 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 2 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, write to the
  16. # Free Software Foundation, Inc.
  17. # 59 Temple Place, Suite 330
  18. # Boston, MA 02111-1307 USA
  19. use strict;
  20. use v5.10;
  21. AddModuleDescription('translations.pl', 'Translation Extension');
  22. our (@MyRules, $FreeLinkPattern);
  23. push(@MyRules, \&TranslationRule);
  24. sub TranslationRule {
  25. if (m/\G(\&lt;translation +\[\[$FreeLinkPattern\]\] +(\d+)\&gt;[ \t]*)/cg) {
  26. Dirty($1);
  27. print GetTranslationLink($2, $3);
  28. return '';
  29. }
  30. return;
  31. }
  32. sub GetCurrentPageRevision {
  33. my $id = shift;
  34. return ParseData(ReadFileOrDie(GetPageFile($id)))->{revision};
  35. }
  36. sub GetTranslationLink {
  37. my ($id, $revision) = @_;
  38. my $result = "";
  39. my $currentRevision;
  40. $id =~ s/^\s+//; # Trim extra spaces
  41. $id =~ s/\s+$//;
  42. $id = FreeToNormal($id);
  43. $result = Ts('This page is a translation of %s.', GetPageOrEditLink( $id, '', 0, 1));
  44. $result .= ' ';
  45. $currentRevision = GetCurrentPageRevision($id);
  46. if ($currentRevision == $revision) {
  47. $result .= T("The translation is up to date.");
  48. } elsif ( $currentRevision > $revision ) {
  49. $result .= T("The translation is outdated.") . ' '
  50. . ScriptLink("action=browse&diff=1&id=$id&revision=$currentRevision&diffrevision=$revision",
  51. T("(diff)"));
  52. } else {
  53. $result .= T("The page does not exist.");
  54. }
  55. return $result;
  56. }