# Copyright 2006 (C) LibLime
# Joshua Ferraro <jmf@liblime.com>
-#
+# 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
# 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(
=head1 DESCRIPTION
+=cut
+
=head1 FUNCTIONS
=head2 getFrameworkLanguages
sub getTranslatedLanguages {
my ($interface, $theme, $current_language, $which) = @_;
my $htdocs;
- my $all_languages = getAllLanguages();
my @languages;
my @enabled_languages;
$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
=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});
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);
=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;
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) {