lang.pl 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 3 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, see <http://www.gnu.org/licenses/>.
  15. # In your CSS file, use something like this, for example:
  16. # span[lang=en] { background-color:#ddf; }
  17. # span[lang=fr] { background-color:#fdd; }
  18. # span[lang=de] { background-color:#ffd; }
  19. # span[lang=it] { background-color:#dfd; }
  20. use strict;
  21. use v5.10;
  22. AddModuleDescription('lang.pl', 'Language Extension');
  23. our ($q, @HtmlStack, @MyRules, $FullUrl);
  24. push(@MyRules, \&LangRule);
  25. sub LangRule {
  26. if (m/\G\[([a-z][a-z])\]/cg) {
  27. my $html;
  28. $html .= "</" . shift(@HtmlStack) . ">" if $HtmlStack[0] eq 'span';
  29. return $html . AddHtmlEnvironment('span', "lang=\"$1\"") . "[$1]";
  30. }
  31. return;
  32. }
  33. *OldLangInitCookie = \&InitCookie;
  34. *InitCookie = \&NewLangInitCookie;
  35. sub NewLangInitCookie {
  36. OldLangInitCookie(@_);
  37. if ($q->param('setlang')) {
  38. my @old = split(/ /, GetParam('theme', ''));
  39. my @old_normal;
  40. my @old_languages;
  41. foreach my $entry (@old) {
  42. if (length($entry) == 2) {
  43. push(@old_languages, $entry);
  44. } else {
  45. push(@old_normal, $entry);
  46. }
  47. }
  48. my @new = $q->param('languages');
  49. SetParam('theme', join(' ', @old_normal, @new));
  50. }
  51. }
  52. *OldLangGetNearLinksUsed = \&GetNearLinksUsed;
  53. *GetNearLinksUsed = \&NewLangGetNearLinksUsed;
  54. sub NewLangGetNearLinksUsed {
  55. my $id = shift;
  56. my $html = OldLangGetNearLinksUsed($id);
  57. my @langs = qw(en de fr it pt);
  58. my @selected = split(/ /, GetParam('theme', '')); # may contain elements that are not in @langs!
  59. $html .= $q->div({-class=>'languages'}, "<form action='$FullUrl'>",
  60. $q->p(GetHiddenValue('action', 'browse'),
  61. GetHiddenValue('id', $id),
  62. T('Languages:'), ' ',
  63. $q->checkbox_group('languages', \@langs, \@selected),
  64. $q->hidden('setlang', '1'),
  65. $q->submit('dolang', T('Show!'))),
  66. '</form>');
  67. return $html;
  68. }