Bugzilla – Attachment 18490 Details for
Bug 9735
Choose language using URL parameters in any page
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 9735 - Let the language be selected through URL parameters
Bug-9735---Let-the-language-be-selected-through-UR.patch (text/plain), 3.92 KB, created by
Chris Cormack
on 2013-05-30 06:53:07 UTC
(
hide
)
Description:
Bug 9735 - Let the language be selected through URL parameters
Filename:
MIME Type:
Creator:
Chris Cormack
Created:
2013-05-30 06:53:07 UTC
Size:
3.92 KB
patch
obsolete
>From 5a52834d99028d46d79d00ecedbbff68d54b9a66 Mon Sep 17 00:00:00 2001 >From: Tomas Cohen Arazi <tomascohen@gmail.com> >Date: Sat, 2 Mar 2013 21:25:23 -0300 >Subject: [PATCH] Bug 9735 - Let the language be selected through URL > parameters >MIME-Version: 1.0 >Content-Type: text/plain; charset=UTF-8 >Content-Transfer-Encoding: 8bit > >Passing language=<valid_language_code> as a parameter in any Koha's URL can be used to set the desired language. >This patch touches > - C4::Templates > - C4::Auth > >Adds a new method getlanguagecookie that does exactly that, for use in get_template_and_user. >Also modifies getlanguage so it checks (a) if there's a 'language' parameter in the CGI object and (b) checks if its valid and enabled for the desired interface. > >To test: >* Without the patch > - access any koha page > - add ?language=code to the end of the URL (change code for a valid language code > it needs to be installed using perl translate install code, and enabled either for > the staff or opac interface, depending where are you testing) > - Nothing happens with the language parameter >* With the patch > - access any koha page > - add ?language=code (the same as before) and hit enter > - the language should be changed to the one you chose > - if you browse through some links, you will see > koha 'remembers' the language you passed as a parameter > (i.e. the language cookie has been updated). > >Regards >To+ > >Sponsored-by: Universidad Nacional de Córdoba >Signed-off-by: Brendan <brendan@bywatersolutions.com> >Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com> > >Comment: Works very well. No errors. >Signed-off-by: Chris Cormack <chrisc@catalyst.net.nz> >--- > C4/Auth.pm | 10 ++++++++++ > C4/Templates.pm | 34 +++++++++++++++++++++++++++++++++- > 2 files changed, 43 insertions(+), 1 deletion(-) > >diff --git a/C4/Auth.pm b/C4/Auth.pm >index 9dba387..e751be1 100644 >--- a/C4/Auth.pm >+++ b/C4/Auth.pm >@@ -468,6 +468,16 @@ sub get_template_and_user { > > $template->param(OpacPublic => '1') if ($user || C4::Context->preference("OpacPublic")); > } >+ >+ # Check if we were asked using parameters to force a specific language >+ if ( defined $in->{'query'}->param('language') ) { >+ # Extract the language, let C4::Templates::getlanguage choose >+ # what to do >+ my $language = C4::Templates::getlanguage($in->{'query'},$in->{'type'}); >+ my $languagecookie = C4::Templates::getlanguagecookie($in->{'query'},$language); >+ $cookie = [$cookie, $languagecookie]; >+ } >+ > return ( $template, $borrowernumber, $cookie, $flags); > } > >diff --git a/C4/Templates.pm b/C4/Templates.pm >index 88b9b01..0771fd4 100644 >--- a/C4/Templates.pm >+++ b/C4/Templates.pm >@@ -316,17 +316,49 @@ sub setlanguagecookie { > ); > } > >+=head2 getlanguagecookie >+ >+ my $cookie = getlanguagecookie($query,$language); >+ >+Returns a cookie object containing the calculated language to be used. >+ >+=cut >+ >+sub getlanguagecookie { >+ my ( $query, $language ) = @_; >+ my $cookie = $query->cookie( >+ -name => 'KohaOpacLanguage', >+ -value => $language, >+ -HttpOnly => 1, >+ -expires => '+3y' >+ ); >+ >+ return $cookie; >+} >+ >+=head2 getlanguage >+ >+ Select a language based on the URL parameter 'language', a cookie, >+ syspref available languages & browser >+ >+=cut > > sub getlanguage { > my ($query, $interface) = @_; > >- # Select a language based on cookie, syspref available languages & browser > my $preference_to_check = > $interface eq 'intranet' ? 'language' : 'opaclanguages'; >+ # Get the available/valid languages list > my @languages = split /,/, C4::Context->preference($preference_to_check); > > my $lang; > >+ # Chose language from the URL >+ $lang = $query->param( 'language' ); >+ if ( defined $lang && any { $_ eq $lang } @languages) { >+ return $lang; >+ } >+ > # cookie > if ( $query->cookie('KohaOpacLanguage') ) { > $lang = $query->cookie('KohaOpacLanguage'); >-- >1.8.1.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 9735
:
15832
|
16081
|
16091
|
18490
|
18685
|
20915
|
21421
|
21422
|
21423
|
21526
|
21527
|
21528