lang.pl 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
  2. #
  3. # This program is free software; you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation; either version 2 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the
  15. # Free Software Foundation, Inc.
  16. # 59 Temple Place, Suite 330
  17. # Boston, MA 02111-1307 USA
  18. # In your CSS file, use something like this, for example:
  19. # span[lang=en] { background-color:#ddf; }
  20. # span[lang=fr] { background-color:#fdd; }
  21. # span[lang=de] { background-color:#ffd; }
  22. # span[lang=it] { background-color:#dfd; }
  23. use strict;
  24. use v5.10;
  25. AddModuleDescription('lang.pl', 'Language Extension');
  26. our ($q, @HtmlStack, @MyRules, $FullUrl);
  27. push(@MyRules, \&LangRule);
  28. sub LangRule {
  29. if (m/\G\[([a-z][a-z])\]/cg) {
  30. my $html;
  31. $html .= "</" . shift(@HtmlStack) . ">" if $HtmlStack[0] eq 'span';
  32. return $html . AddHtmlEnvironment('span', "lang=\"$1\"") . "[$1]";
  33. }
  34. return;
  35. }
  36. *OldLangInitCookie = \&InitCookie;
  37. *InitCookie = \&NewLangInitCookie;
  38. sub NewLangInitCookie {
  39. OldLangInitCookie(@_);
  40. if ($q->param('setlang')) {
  41. my @old = split(/ /, GetParam('theme', ''));
  42. my @old_normal;
  43. my @old_languages;
  44. foreach my $entry (@old) {
  45. if (length($entry) == 2) {
  46. push(@old_languages, $entry);
  47. } else {
  48. push(@old_normal, $entry);
  49. }
  50. }
  51. my @new = $q->param('languages');
  52. SetParam('theme', join(' ', @old_normal, @new));
  53. }
  54. }
  55. *OldLangGetNearLinksUsed = \&GetNearLinksUsed;
  56. *GetNearLinksUsed = \&NewLangGetNearLinksUsed;
  57. sub NewLangGetNearLinksUsed {
  58. my $id = shift;
  59. my $html = OldLangGetNearLinksUsed($id);
  60. my @langs = qw(en de fr it pt);
  61. my @selected = split(/ /, GetParam('theme', '')); # may contain elements that are not in @langs!
  62. $html .= $q->div({-class=>'languages'}, "<form action='$FullUrl'>",
  63. $q->p(GetHiddenValue('action', 'browse'),
  64. GetHiddenValue('id', $id),
  65. T('Languages:'), ' ',
  66. $q->checkbox_group('languages', \@langs, \@selected),
  67. $q->hidden('setlang', '1'),
  68. $q->submit('dolang', T('Show!'))),
  69. '</form>');
  70. return $html;
  71. }