package Koha::I18N;
-# Copyright 2012 BibLibre
-#
# This file is part of Koha.
#
-# Koha is free software; you can redistribute it and/or modify it under the
-# terms of the GNU General Public License as published by the Free Software
-# Foundation; either version 2 of the License, or (at your option) any later
-# version.
+# Copyright 2012-2014 BibLibre
#
-# Koha 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.
+# Koha is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
#
-# You should have received a copy of the GNU General Public License along
-# with Koha; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-
-use base qw(Locale::Maketext);
+# Koha 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
+# along with Koha; if not, see <http://www.gnu.org/licenses>.
use Modern::Perl;
-use C4::Templates;
-use C4::Context;
+use base qw(Locale::Maketext Exporter);
+
+use CGI;
+use C4::Languages;
use Locale::Maketext::Lexicon {
'en' => ['Auto'],
. '/misc/translator/po/*-messages.po'
],
'_AUTO' => 1,
+ '_style' => 'gettext',
};
-sub get_handle_from_context {
- my ($class, $cgi, $interface) = @_;
-
- my $lh;
- my $lang = C4::Templates::getlanguage($cgi, $interface);
- if ($lang) {
- $lh = $class->get_handle($lang)
- or die "No language handle for '$lang'";
- } else {
- $lh = $class->get_handle()
- or die "Can't get a language handle";
+our @EXPORT = qw( gettext );
+
+my %language_handles;
+
+sub get_language_handle {
+ my $cgi = new CGI;
+ my $language = C4::Languages::getlanguage;
+
+ if (not exists $language_handles{$language}) {
+ $language_handles{$language} = __PACKAGE__->get_handle($language)
+ or die "No language handle for '$language'";
}
- return $lh;
+ return $language_handles{$language};
+}
+
+sub gettext {
+ my $lh = get_language_handle;
+ $lh->maketext(@_);
}
1;