From ecc63eda57d41be3d2046480fedb0f88ae904cf1 Mon Sep 17 00:00:00 2001 From: rangi Date: Tue, 26 Jun 2001 22:13:50 +0000 Subject: [PATCH] Scripts to permit koha webpages to display in different natural languages Courtesy of Pawel Skuza --- translator/translator.pl | 170 +++++++++++++++++++++++++++++++++++ translator/translator.readme | 28 ++++++ 2 files changed, 198 insertions(+) create mode 100755 translator/translator.pl create mode 100644 translator/translator.readme diff --git a/translator/translator.pl b/translator/translator.pl new file mode 100755 index 0000000000..3fe4632b3f --- /dev/null +++ b/translator/translator.pl @@ -0,0 +1,170 @@ +#!/usr/bin/perl + +use strict; + +use locale; +use POSIX; +use Locale::gettext; + +my $tofile; +if (exists $ENV{"HTTP_ACCEPT"}) { + $tofile=0; +} else { + $tofile=1; +} + + +print "Content-Type: text/html \n\n" unless($tofile); + +my $path=$ENV{"PATH_TRANSLATED"}; + +textdomain("koha"); + +my %lang=( + fr => "fr_FR", + pl => "pl_PL", +); + +my @lang=split/,/,$ENV{"HTTP_ACCEPT_LANGUAGE"}; +my $lang="us_US"; + +foreach (@lang){ + my $lg=$lang{$_}; + setlocale(LC_MESSAGES,$lg); + my $tmp = gettext($_); + if ($tmp ne $_) + { + $lang=$tmp; + last; + } +} + +setlocale(LC_MESSAGES,$lang); + +my @katalog; +my $plik; + +if ($tofile){ + + @katalog=`ls -R`; + + $plik=$ARGV[0]; + if ($plik eq ''){ + $plik="koha.gettext.c"; + } + +} else { + @katalog=("cos"); +} + +my $kat; +my (%dgettxt, %dane, %dane2, @dane2); +my $i; + +$dgettxt{'iso-8859-1'}=1; +my $txt =< + +TXT + +foreach(@katalog){ + + if (/:$/){ + $kat="$`/"; + next; + } + + if ($tofile){ + unless ($_=~/(\.html|\.inc)$/i) { + next; + } + } + + print "$kat$_" if ($tofile); + + my $dane; + { + local $/; + if ($tofile){ + open PL, "$kat$_"; + } else { + open PL, "$path"; + } + $dane=; + close PL; + } + + + $dane=~s//$txt/i; + + $dane=~s/%/&zamien/ges; # change % (specjal symbol) + $dane=~s/\\\'/&zamien/ges; # change \' + $dane=~s/\\\"/&zamien/ges; # change \" + + # taka out graphics + $dane=~s/[\"\']\/?([\w-\/\.]*?\.gif)[\"\']/&zamien($1)/ges; + +# $dane=~s/messenger\s*\((.*?)\)\s*[\}\{;]/&zamien($1)/ges; +# $dane=~s/\.write(ln)?\s*\((.*?)\)\s*[\};]/&zamien($2)/ges; + + # take out string in field alt + $dane=~s/alt\s*=\s*[\"]([^\"]*)[\"]/&zamien($1)/iges; + $dane=~s/alt\s*=\s*[\']([^\']*)[\']/&zamien($1)/iges; + + $dane=~s//&zamien/ges; + $dane=~s//&zamien/iges; + + $dane=~s/<[\w\/]\w*\s*((\w*\s*=\s*(\'[^\']*\'|\"[^\"]*\"|[\w-\/?&,\.=%#]*)|[%\d*%]|\w)\s*)*>/&zamien/ges; + $dane=~s//&zamien/ges; + $dane=~s/]*>/&zamien/ges; + $dane=~s/<#.*?#>/&zamien/ges; + + my $dane2=$dane; + $dane2=~s/(\s*%\d+%\s*)+/%/gs; + $dane2=~s/^%//g; + $dane2=~s/%$//g; + foreach my $tmp(split/%/,$dane2){ + my $tmp_ok = $tmp; + $tmp_ok=~s/\s+/ /gs; + next unless ($tmp_ok=~/\w+/); + $dgettxt{$tmp_ok}++ unless $dgettxt{$tmp_ok}; + $tmp=~s/([\)\(])/\\$1/g; + $dane=~s/$tmp/gettext($tmp_ok)/es; + } + unless ($tofile){ + while($dane=~/%\d+%/){ + $dane=~s/%(\d+)%/$dane2{$1}/g; + } + print $dane; + } +} + +if ($tofile) { + + open PK, ">$plik"; + foreach my $tmp(sort keys %dgettxt){ + $tmp=~s/\"/\\\"/gs; + print PK "gettext(\"$tmp\");\n"; + } + close PK; +} + +exit; + +########################################################### + +sub zamien { + my $tmp = $&; + unless ($dgettxt{$_[0]}) { + $dgettxt{$_[0]}++; + } + $tmp=~s/$_[0]/gettext($&)/es; + unless ($dane{$tmp}) { + push @dane2, $tmp; + $dane2{$i}=$tmp; + $dane{$tmp}=$i++; + } + return "%${\($dane{$tmp})}%"; +} + diff --git a/translator/translator.readme b/translator/translator.readme new file mode 100644 index 0000000000..c4baaa704e --- /dev/null +++ b/translator/translator.readme @@ -0,0 +1,28 @@ +This is small note about 'translator.pl'. +Author: Pawel Skuza +email: pawelzc@cz.top.pl + +Script 'translator.pl' do two things: +1. Prepare strings which can be translate; +2. Translate strings used gettext. + +1. Prepare strings which can be translate. +Copy file 'translator.pl' into root koha directory and execute it. +eg. + cd /usr/src/koha + cp scripts/translator.pl . + ./translator.pl some_file_name + xgettext some_file_name -okoha.po + vi koha.po //now you must translate koha.po + msgfmt koha.po -okoha.mo + cp koha.mo /usr/share/locale/$$/LC_MESSAGES //where $$ is your language + +note: if you omnit 'some_file_name' translator create 'koha.gettext.c' + +2. Translate strings used gettext. +You have to configure your apache. Put this lines in koha and opac virtual: + + Action text/html /cgi-bin/koha/translator.pl + Action text/plane /cgi-bin/koha/translator.pl + +Don't forget set up the language preference in your browser. -- 2.39.5