[ic] Why am I always getting the default translation?
Marc Brevoort
marc.brevoort at armazemdedados.com
Thu Aug 14 10:37:39 EDT 2003
On Wed, 2003-08-13 at 21:13, John Matecsa wrote:
> > In a page I have a line saying
> > [LC][getlocale][en_US]About Us[/en_US][pt_PT]Quem somos[/pt_PT][/LC]
Most likely the problem was caused by LC working before the page is
parsed rather than during the parse. Adding persist=1 to the setlocale
ended up showing the correct translation, however only after reloading
the page.
John Mateca writes
> To get things in the templates directory to translate I had to
> resort to this.
> [if scratch mv_locale eq "fr_FR"]
> Favoris Globaux
> [else]
> Global Favourites
> [/else]
> [/if]
Racke suggested to this
> Try instead Locale fr_FR readfile 1 in your catalog.cfg and use the
> standard [L] etc. tags.
I tried, this, but things still didn't seem to work out. Unfortunately
internationalization seems pretty sensitive to quite a few configuration
settings which I don't fully understand yet, so I put together the
following tag as a solution. It mostly works using like I'd have
expected the LC tag to work, but does the translation while parsing the
page instead of before, giving a bit more predictable results.
file /usr/lib/interchange/lib/UI/usertag/xlat.tag
follows.
#------------------------cut here----------------------
Usertag xlat hasEndTag
Usertag xlat Interpolate 1
Usertag xlat Routine <<EOR
#######################################################
# This usertag is useful to make translations.
# it works just like the LC tag but works while
# parsing a page instead of before. Embedding
# tags other than the language tags inside this tag
# is untested and may give strange results.
#######################################################
sub {
my ($tagtotrans)=@_;
my $currlang=$Scratch->{mv_locale};
my $default=substr($tagtotrans,0,index($tagtotrans,'['));
my $hastrans=index($tagtotrans,'['.$currlang.']');
if ($hastrans==-1) {
# No translation found for this language
return $default;
}
# Translation found, search for its end
my $endoftrans=index($tagtotrans,'[/'.$currlang.']');
if ($endoftrans==-1) { $endoftrans=length($tagtotrans)-1; }
my $startpos=$hastrans+2+length($currlang);
my $trans=substr($tagtotrans,$startpos,$endoftrans-$startpos);
return $trans;
}
EOR
#------------------------cut here----------------------
Using this tag, the equivalent of
[LC]This is the default text.
[fr_FR] Text for the fr_FR locale. [/fr_FR]
[de_DE] Text for the de_DE locale. [/de_DE]
[/LC]
is rewritten as
[XLAT]This is the default text.
[fr_FR] Text for the fr_FR locale. [/fr_FR]
[de_DE] Text for the de_DE locale. [/de_DE]
[/XLAT]
Regards,
Marc Brevoort
--
e-mail: marc.brevoort at armazemdedados.com
web: http://www.armazemdedados.com
Armazem de Dados, Informatica, Lda
Dep. Desenvolvimento
Tel. +351 21 910 83 10 / Fax. +351- 21 910 83 19
More information about the interchange-users
mailing list