X-Git-Url: http://koha-dev.rot13.org:8081/gitweb/?a=blobdiff_plain;f=C4%2FLanguages.pm;h=2a74b925aa54770f8895cb0e2dfb6254eed49b57;hb=a07b32f4f9090ba0c50c3e510f0be56b8805faeb;hp=6bb9146447f021454bf4c8535cb3c27c936bf6e0;hpb=2c82872dcbea097932268573b05bc7e0f64f8af7;p=koha_fer diff --git a/C4/Languages.pm b/C4/Languages.pm index 6bb9146447..2a74b925aa 100644 --- a/C4/Languages.pm +++ b/C4/Languages.pm @@ -2,7 +2,7 @@ package C4::Languages; # Copyright 2006 (C) LibLime # Joshua Ferraro -# +# Portions Copyright 2009 Chris Cormack and the Koha Dev Team # This file is part of Koha. # # Koha is free software; you can redistribute it and/or modify it under the @@ -14,31 +14,30 @@ package C4::Languages; # 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, write to the Free Software Foundation, Inc., 59 Temple Place, -# Suite 330, Boston, MA 02111-1307 USA +# 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 strict; -#use warnings; #FIXME: turn off warnings before release +#use warnings; FIXME - Bug 2505 use Carp; use C4::Context; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $DEBUG); +eval { + if (C4::Context->ismemcached) { + require Memoize::Memcached; + import Memoize::Memcached qw(memoize_memcached); -use Memoize::Memcached - memcached => { - servers => [ C4::Context->config('memcached_servers') ], - key_prefix => C4::Context->config('memcached_namespace'), - }; - -memoize_memcached('getTranslatedLanguages', expire_time => 600); #cache for 10 minutes -memoize_memcached('getFrameworkLanguages' , expire_time => 600); -memoize_memcached('getAllLanguages', expire_time => 600); - + memoize_memcached('getTranslatedLanguages', memcached => C4::Context->memcached); + memoize_memcached('getFrameworkLanguages' , memcached => C4::Context->memcached); + memoize_memcached('getAllLanguages', memcached => C4::Context->memcached); + } +}; BEGIN { - $VERSION = 3.00; + $VERSION = 3.07.00.049; require Exporter; @ISA = qw(Exporter); @EXPORT = qw( @@ -60,6 +59,8 @@ use C4::Languages; =head1 DESCRIPTION +=cut + =head1 FUNCTIONS =head2 getFrameworkLanguages @@ -118,7 +119,6 @@ Returns a reference to an array of hashes: sub getTranslatedLanguages { my ($interface, $theme, $current_language, $which) = @_; my $htdocs; - my $all_languages = getAllLanguages(); my @languages; my @enabled_languages; @@ -160,7 +160,7 @@ sub getTranslatedLanguages { $seen{$_}++ for @languages; @languages = keys %seen; } - return _build_languages_arrayref($all_languages,\@languages,$current_language,\@enabled_languages); + return _build_languages_arrayref(\@languages,$current_language,\@enabled_languages); } =head2 getAllLanguages @@ -178,19 +178,35 @@ Returns a reference to an array of hashes: =cut sub getAllLanguages { + my $lang = shift; +# if no parameter is passed to the function, it returns english languages names +# if a $lang parameter conforming to RFC4646 syntax is passed, the function returns languages names translated in $lang +# if a language name is not translated in $lang in database, the function returns english language name my @languages_loop; my $dbh=C4::Context->dbh; - my $current_language = shift || 'en'; + my $default_language = 'en'; + my $current_language = $default_language; + if ($lang) { + $current_language = regex_lang_subtags($lang)->{'language'}; + } my $sth = $dbh->prepare('SELECT * FROM language_subtag_registry WHERE type=\'language\''); $sth->execute(); while (my $language_subtag_registry = $sth->fetchrow_hashref) { - - # pull out all the script descriptions for each language + my $desc; + # check if language name is stored in current language + my $sth4= $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag =? AND lang = ?"); + $sth4->execute($language_subtag_registry->{subtag},$current_language); + while (my $language_desc = $sth4->fetchrow_hashref) { + $desc=$language_desc->{description}; + } my $sth2= $dbh->prepare("SELECT * FROM language_descriptions LEFT JOIN language_rfc4646_to_iso639 on language_rfc4646_to_iso639.rfc4646_subtag = language_descriptions.subtag WHERE type='language' AND subtag =? AND language_descriptions.lang = ?"); - $sth2->execute($language_subtag_registry->{subtag},$current_language); - + if ($desc) { + $sth2->execute($language_subtag_registry->{subtag},$current_language); + } + else { + $sth2->execute($language_subtag_registry->{subtag},$default_language); + } my $sth3 = $dbh->prepare("SELECT description FROM language_descriptions WHERE type='language' AND subtag=? AND lang=?"); - # add the correct description info while (my $language_descriptions = $sth2->fetchrow_hashref) { $sth3->execute($language_subtag_registry->{subtag},$language_subtag_registry->{subtag}); @@ -257,10 +273,11 @@ sub _get_language_dirs { next if $lang_string =~/^\./; next if $lang_string eq 'all'; next if $lang_string =~/png$/; + next if $lang_string =~/js$/; next if $lang_string =~/css$/; next if $lang_string =~/CVS$/; next if $lang_string =~/\.txt$/i; #Don't read the readme.txt ! - next if $lang_string =~/img|images|famfam/; + next if $lang_string =~/img|images|famfam|js|less|lib|sound|pdf/; push @lang_strings, $lang_string; } return (@lang_strings); @@ -275,7 +292,7 @@ FIXME: this could be rewritten and simplified using map =cut sub _build_languages_arrayref { - my ($all_languages,$translated_languages,$current_language,$enabled_languages) = @_; + my ($translated_languages,$current_language,$enabled_languages) = @_; my @translated_languages = @$translated_languages; my @languages_loop; # the final reference to an array of hashrefs my @enabled_languages = @$enabled_languages; @@ -449,7 +466,6 @@ sub get_bidi { sub accept_language { # referenced http://search.cpan.org/src/CGILMORE/I18N-AcceptLanguage-1.04/lib/I18N/AcceptLanguage.pm - # FIXME: since this is only used in Output.pm as of Jan 8 2008, maybe it should be IN Output.pm my ($clientPreferences,$supportedLanguages) = @_; my @languages = (); if ($clientPreferences) {