X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=Koha%2FI18N.pm;h=33730f99b81954c6caeb57db909125fc5fbc320f;hb=480847e81cca832a3e8eac35753532275ec49aec;hp=7b72793b81354461a33d3fcd69090c56b80dfb0f;hpb=061cff837d1667b0f714fbbfba59c2caed098d6b;p=koha_fer diff --git a/Koha/I18N.pm b/Koha/I18N.pm index 7b72793b81..33730f99b8 100644 --- a/Koha/I18N.pm +++ b/Koha/I18N.pm @@ -1,27 +1,27 @@ 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 . 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'], @@ -31,22 +31,28 @@ use Locale::Maketext::Lexicon { . '/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;