[Koha-devel] Templates internationalisation

Jerome Vizcaino vizcainj at esiee.fr
Fri Jun 6 05:19:05 CEST 2003


Hi

This mail contains a modification we made to make Koha template
translation a lot more easier.
Here is the idea :
We created a table in Koha named opac_text containing three field 
	- id : the identifier of the text
	- lang : corresponding language
	- label : the text to be used

Using the Label.pm, we use a gettexttemplate to get the label
corresponding to the requested id. This way, with only one .tmpl file,
unlimited languages are available without any changes in the .tmpl file.

To prove this trick is usable and not so hard to implement we've
attached 4 files : Label.pm, opac-detail.pl, opac-detail.tmpl and
opac_text.sql.

Here is how to test it :

1 - Create the table containing the labels : 
	mysql -u root -p < opac_text.sql

2 - Copy the Label.pm in the C4 module directory

3 - Copy opac-detail.pl to the opac/ cgi-bin directory

4 - Copy opac-detail.tmpl to the opac/htdocs/opac-tmpl/default/en
directory. Make a link to this file in the
opac/htdocs/opac-tmpl/default/fr so that no physical duplication is
needed. This way changing the opaclanguages preference will still use
the generic template.

Now try and search a book and click on one of the result to show the
details. If you're using either 'en' or 'fr' opaclanguages option.
Changing the preference will change the language in the display.

For sure, it requires a little more cpu to display the page but with a
PII 350 (our test machine) no noticable slow down was reported.

Using a system like the authorised value builder, creation of new
languages would be made easier.

We need some feedback on this please :)

Thanks

Jerome and Michel


-------------- next part --------------
A non-text attachment was scrubbed...
Name: opac_text.sql
Type: text/x-sql
Size: 2855 bytes
Desc: not available
URL: </pipermail/koha-devel/attachments/20030606/c4cc304f/attachment-0002.bin>
-------------- next part --------------
<TMPL_INCLUDE NAME="opac-top.inc">

<TMPL_IF NAME="loggedinusername">
    <p align=left><TMPL_VAR NAME="TEXT_LOGGED_IN_AS"> <TMPL_VAR NAME="loggedinuser"> [<a
    href=/cgi-bin/koha/opac-user.pl><TMPL_VAR NAME ="TEXT_MEMBERS_HOME"></a>][<a
    href=/cgi-bin/koha/opac-main.pl?logout.x=1><TMPL_VAR NAME = "TEXT_LOGOUT"></a>]</p>
<TMPL_ELSE>
    <p align=left><a href=/cgi-bin/koha/opac-user.pl><TMPL_VAR NAME = "TEXT_LOG_IN_TO_KOHA"></a></p>
</TMPL_IF>

<TMPL_UNLESS NAME="norequests">
<p align=right><a href=/cgi-bin/koha/opac-reserve.pl?bib=<TMPL_VAR NAME="biblionumber"
ESCAPE=URL><TMPL_VAR NAME = "TEXT_REQUEST"></a></p>
</TMPL_UNLESS>



<TMPL_LOOP NAME="BIBLIO_RESULTS">
<font SIZE=6><em><TMPL_VAR NAME="title"> (<TMPL_VAR NAME="author">)
<TMPL_VAR NAME="class"></em></font><p>
<!-- FIXME - "callpadding" should be "cellpadding", right? -->
<table cellspacing="0" callpadding="5" border="1" align="left" width="220">
<!-----------------BIBLIO RECORD TABLE--------->
<tr valign="top">

<td bgcolor="#99cccc">
<b><TMPL_VAR NAME = "TEXT_BIBLIO_RECORD"></b>

<TMPL_VAR NAME="biblionumber">
</td>
</tr>
<tr valign="top">
<td>
<FONT SIZE=2  face="arial, helvetica">
<b><TMPL_VAR NAME = "TEXT_SUBTITLE"></b> <TMPL_VAR NAME="subtitle"><br>
<b><TMPL_VAR NAME = "TEXT_AUTHOR"></b> <TMPL_VAR NAME="author"><br>
<b><TMPL_VAR NAME = "TEXT_SUBJECT"></b> <TMPL_VAR NAME="subject"><br>
<b><TMPL_VAR NAME = "TEXT_COPYRIGHT"></b> <TMPL_VAR NAME="copyrightdate"><br>
<b><TMPL_VAR NAME = "TEXT_NBITEMS"></b> <TMPL_VAR NAME="count">
<p>
</font></td>
</tr>
</table>
</TMPL_LOOP>
<center>
<table border=0 cellspacing=0 cellpadding=2>
<tr bgcolor="#99cccc">
<td><TMPL_VAR NAME="TEXT_ITEMTYPE"></td>
<td><TMPL_VAR NAME="TEXT_CLASS"></td>
<td><TMPL_VAR NAME="TEXT_LOCATION"></td>
<td><TMPL_VAR NAME="TEXT_DATE_DUE"></td>
<td><TMPL_VAR NAME="TEXT_LAST_SEEN"></td>
<td><TMPL_VAR NAME="TEXT_BARCODE"></td>
</tr>
<TMPL_LOOP NAME="ITEM_RESULTS">
<tr>
<td><TMPL_VAR NAME="itemtype"></td>
<td><TMPL_VAR NAME="class"></td>
<td><TMPL_VAR NAME="branchname"></td>
<td><TMPL_VAR NAME="datedue"></td>
<td><TMPL_VAR NAME="datelastseen"></td>
<td><TMPL_VAR NAME="barcode"></td>
</tr>
</TMPL_LOOP>
<TMPL_LOOP NAME="WEB_RESULTS">
<tr>
<td><TMPL_VAR NAME="TEXT_ITEMTYPE"></td>
<td><TMPL_VAR NAME="TEXT_WEBSITE"></td>
<td><TMPL_VAR NAME="TEXT_ONLINE"></td>
<td><TMPL_VAR NAME="TEXT_AVAILABLE"></td>
<td></td>
<td><TMPL_VAR NAME="url"></td>
</tr>
</TMPL_LOOP>
</table>
<p>
</center>
<br clear=all>
<p />
<TMPL_INCLUDE NAME="opac-bottom.inc">
-------------- next part --------------
A non-text attachment was scrubbed...
Name: opac-detail.pl
Type: text/x-perl
Size: 3041 bytes
Desc: not available
URL: </pipermail/koha-devel/attachments/20030606/c4cc304f/attachment-0002.pl>
-------------- next part --------------
package C4::Label;


# Copyright 2000-2002 Katipo Communications
#
# 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.
#
# 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, write to the Free Software Foundation, Inc., 59 Temple Place,
# Suite 330, Boston, MA  02111-1307 USA

use strict;
require Exporter;

use vars qw($VERSION @ISA @EXPORT);
use C4::Context;

# set the version for version checking
$VERSION = 0.01;

@ISA = qw(Exporter);
@EXPORT = qw(&gettextlabel);

sub gettextlabel {
  my ($id) = @_;
  my $dbh = C4::Context->dbh;
  my $sth = $dbh->prepare("SELECT label FROM opac_text WHERE id=? AND lang=?");
  my $label;
  my $lang = C4::Context->preference("opaclanguages");

  $sth->execute($id, $lang);

  if( $sth->rows != 0)
  {
	  $label = $sth->fetchrow();
	  $sth->finish();
	  return $label;
  }
  else
  {
	  $label = "Unknown label id";
	  $sth->finish();
	  return $label;
  }
}


More information about the Koha-devel mailing list