[ic] Custom tag trouble

Elver Loho elver.loho at gmail.com
Tue Mar 21 09:36:32 EST 2006


Hiya!

This is a long mail, so feel free to scroll down to "=== THE PROBLEM ==="

We were using the LC tag for translations a while ago. However, it's
not centralized and it's hard to add utf-8 cyrillic and all that. So
we decided to write our own tag to handle localization that would grab
all the translations from the locale database.

So what used to look like:

[LC]estonian text[eng]english text[/eng][/LC]

Now looks like:

[lc2 generated_code]estonian text[/lc2]

The generated_code is a pointer to a row in the locale database for
which I wrote a little multiplatform GUI translation front-end. (I'm
not yet ready to GPL it. Needs some more testing.)

The lc2 usertag looks like this: (I suck at Perl. I'm a Python guy.)

# [lc2 code] message [/lc2]
#
#

UserTag lc2 hasEndTag   1
UserTag lc2 Interpolate 1
UserTag lc2 Order locale
UserTag lc2 Routine <<EOF
sub {
    my ($code, $message) = @_;
    my $ref;
    my $string;
    my $deflocname;

    $ref = $Vend::Cfg->{Locale_repository}{$Scratch->{mv_locale}};
    # $ref = $Vend::Cfg->{Locale_repository};
    $deflocname = $Vend::Cfg->{DefaultLocale};

    if($deflocname =~ /$Scratch->{mv_locale}/) {
        # 1) db[est]
        # 2) message
        # 3) db(deflocname)
        # NOES! 4) eng
        # NOES! 5) code/id
        $ref = $Vend::Cfg->{Locale_repository}{est};
        $string = $ref->{$code};
        unless ($string) {
                $string = $message;
                unless ($string) {
                        $ref = $Vend::Cfg->{Locale_repository}{$deflocname};
                        $string = $ref->{$code};
                        unless ($string) {
                                return '';
                        }
                        return $string;
                }
                return $string;
        }
        return $string;
    }

    $string = $ref->{$code};
        unless ($string) {
                $ref = $Vend::Cfg->{Locale_repository}{eng};
                $string = $ref->{$code};
                unless ($string) {
                        my $string = $message;
                        return $string;
                }
                return $string;
        }

    if ($Scratch->{mv_locale} =~ /(?:rus|lit|lat)/){
        $string = Encode::decode("utf8", $string);
        use utf8;

        if ($Values->{'latin'}){
                my (%chars,%latin,$char,$uchar,$uhex);
               
##################################################################
                # read in character codes
                open (ANDMED,'/home/kriso/catalogs/shop/codetable.dat');
                my ($j);
                while (<ANDMED>) {
                    /^\d/ && do {
                        my @data = split;
                        $latin{$data[0]} = $data[1];
                       }
                }
                close(ANDMED);
                foreach $char (keys %latin) {
                        $uhex=hex($char);
                        $uchar=pack("U",$uhex);
                        $string =~ s/$uchar/$latin{$char}/g;
                }
                $string=~ s/#//g;
        } else {
        #       $string =~ s/(\S)/sprintf("%1s%1s%s%1s",'&','#',ord($1),';')/eg;
                $string =~ s/(\S)/sprintf("%s",&html_code2(ord($1)))/eg;

        }
        return $string;

    } else {
        return $string;
    }

        sub html_code3 {

                my $codenr=$_[0];
                if ($codenr>255){
                        sprintf("%1s%1s%s%1s",'&','#',$_[0],';');
                } else {
                        chr($_[0]);
                }
        }
}
EOF

So what's the trouble? Suppose the database field contains stuff like:

"If you already have an username and password then please enter these
to the fields on the left. If you have lost your username or password
then please click on the [page lost_password]lost password[/page]
link. On this page you can enter your name and e-mail and your
username and password will be sent to your e-mail address. If you are
a new client please click [page new_account]new account[/page] link."

This is from the LC tag:

"[LC]
Kui Te omate juba kasutajanime ning parooli, siis sisestage need
vasakul ülal asuvatesse lahtritesse. Kui olete need unustanud, siis
klikkige lingil [page lost_password]unustasid parooli[/page]. Avaneval
lehel tuleks Teil täita mõned väljad ning kui leitakse nendele vastav
tellija, siis saadetakse kasutajanimi ning parool Teie e-maili
aadressile. Samuti võite meiega ühendust võtta <a
href="mailto:kriso at kriso.ee">e-maili</a> või telefoni teel. Kui Te
olete uus tellija, siis klikkige lingil [page
new_account]registreeri[/page].
[eng]If you already have an username and password then please enter
these to the fields on the left. If you have lost your username or
password then please click on the [page lost_password]lost
password[/page] link. On this page you can enter your name and e-mail
and your username and password will be sent to your e-mail address. If
you are a new client please click [page new_account]new account[/page]
link.[/eng]
[/LC]"

=== THE PROBLEM ===

The problem we're having is that with the lc2 tag, the [page ...]
stuff gets parsed to:

"/.../ If you are a new client please click <a
href="http://www.kriso.ee/cgi-bin/shop/new_account.html?id=IjMx5JnV&mv_pc=14102">new
account[/page] link."

Basically it seems that it doesn't see the [/page] part for some
reason. Any ideas?


Elver



More information about the interchange-users mailing list