2004-03-14 17:35:47 +00:00
|
|
|
# Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
2016-08-16 14:59:13 +02:00
|
|
|
# the Free Software Foundation; either version 3 of the License, or
|
2004-03-14 17:35:47 +00:00
|
|
|
# (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# You should have received a copy of the GNU General Public License
|
2016-08-16 14:59:13 +02:00
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-03-14 17:35:47 +00:00
|
|
|
|
|
|
|
|
# In your CSS file, use something like this, for example:
|
|
|
|
|
|
|
|
|
|
# span[lang=en] { background-color:#ddf; }
|
|
|
|
|
# span[lang=fr] { background-color:#fdd; }
|
|
|
|
|
# span[lang=de] { background-color:#ffd; }
|
|
|
|
|
# span[lang=it] { background-color:#dfd; }
|
|
|
|
|
|
2015-03-27 03:01:01 +02:00
|
|
|
use strict;
|
2015-08-18 10:48:03 +02:00
|
|
|
use v5.10;
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2014-08-21 22:23:23 +02:00
|
|
|
AddModuleDescription('lang.pl', 'Language Extension');
|
2004-03-14 17:35:47 +00:00
|
|
|
|
2015-04-10 13:31:28 +03:00
|
|
|
our ($q, @HtmlStack, @MyRules, $FullUrl);
|
2015-03-27 03:01:01 +02:00
|
|
|
|
2004-03-14 17:35:47 +00:00
|
|
|
push(@MyRules, \&LangRule);
|
|
|
|
|
|
|
|
|
|
sub LangRule {
|
2015-08-23 21:22:12 +03:00
|
|
|
if (m/\G\[([a-z][a-z])\]/cg) {
|
2004-03-14 17:35:47 +00:00
|
|
|
my $html;
|
|
|
|
|
$html .= "</" . shift(@HtmlStack) . ">" if $HtmlStack[0] eq 'span';
|
|
|
|
|
return $html . AddHtmlEnvironment('span', "lang=\"$1\"") . "[$1]";
|
|
|
|
|
}
|
2015-02-27 12:10:18 +02:00
|
|
|
return;
|
2004-03-14 17:35:47 +00:00
|
|
|
}
|
2004-03-19 23:51:34 +00:00
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldLangInitCookie = \&InitCookie;
|
|
|
|
|
*InitCookie = \&NewLangInitCookie;
|
2004-03-19 23:51:34 +00:00
|
|
|
|
|
|
|
|
sub NewLangInitCookie {
|
|
|
|
|
OldLangInitCookie(@_);
|
2004-05-07 22:03:15 +00:00
|
|
|
if ($q->param('setlang')) {
|
|
|
|
|
my @old = split(/ /, GetParam('theme', ''));
|
|
|
|
|
my @old_normal;
|
|
|
|
|
my @old_languages;
|
2015-03-27 03:01:01 +02:00
|
|
|
foreach my $entry (@old) {
|
2004-05-07 22:03:15 +00:00
|
|
|
if (length($entry) == 2) {
|
|
|
|
|
push(@old_languages, $entry);
|
|
|
|
|
} else {
|
|
|
|
|
push(@old_normal, $entry);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
my @new = $q->param('languages');
|
|
|
|
|
SetParam('theme', join(' ', @old_normal, @new));
|
|
|
|
|
}
|
2004-03-19 23:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-11 23:41:33 +03:00
|
|
|
*OldLangGetNearLinksUsed = \&GetNearLinksUsed;
|
|
|
|
|
*GetNearLinksUsed = \&NewLangGetNearLinksUsed;
|
2004-03-19 23:51:34 +00:00
|
|
|
|
2004-03-21 01:45:16 +00:00
|
|
|
sub NewLangGetNearLinksUsed {
|
2004-03-19 23:51:34 +00:00
|
|
|
my $id = shift;
|
2004-03-21 01:57:57 +00:00
|
|
|
my $html = OldLangGetNearLinksUsed($id);
|
2004-03-19 23:51:34 +00:00
|
|
|
my @langs = qw(en de fr it pt);
|
2004-05-07 22:03:15 +00:00
|
|
|
my @selected = split(/ /, GetParam('theme', '')); # may contain elements that are not in @langs!
|
2006-02-26 03:12:35 +00:00
|
|
|
$html .= $q->div({-class=>'languages'}, "<form action='$FullUrl'>",
|
2004-08-13 02:28:22 +00:00
|
|
|
$q->p(GetHiddenValue('action', 'browse'),
|
|
|
|
|
GetHiddenValue('id', $id),
|
|
|
|
|
T('Languages:'), ' ',
|
|
|
|
|
$q->checkbox_group('languages', \@langs, \@selected),
|
|
|
|
|
$q->hidden('setlang', '1'),
|
2006-02-26 03:12:35 +00:00
|
|
|
$q->submit('dolang', T('Show!'))),
|
|
|
|
|
'</form>');
|
2004-03-21 01:45:16 +00:00
|
|
|
return $html;
|
2004-03-19 23:51:34 +00:00
|
|
|
}
|