Hi Yaerox. The thread you referenced is well-found; it contains three posts, each with a good idea.

You will have to decide whether storing in a DB or in text files is the best solution for you (the questions of how the text is updated, and by whom, will be most of the decision, IMO). But whatever you do about that, you will need to get the text out of your code, and one step more, out of the HTML.

Personally I have used, for big projects and for small, and I really like using, the Template Toolkit -- I find it easy to use and very powerful. You can pass complex data structures to the template and process them with conditional logic, or you can use logic to design your template library and pass simple data to the templates. You'll also be able to use the same system for other output, such as email messages you need to send in different languages, etc.

You might have to spend a few days figuring out your setup, but once you have it going you will have an easy time.

Basically you should separate the text both from the programmatic code, and from the display code.

[ Perl programs to create output data ] V [ Languages library in DB or textfiles ] V [ Template Toolkit templates to display output ]

For your example, you could make the change to your demo program as simple as follows:

#!/usr/bin/perl # Includes use strict; use warnings; use MyPackages; use Template; my $tt = Template->new({ INCLUDE_PATH => '/usr/local/templates', INTERPOLATE => 1, }) || die "$Template::ERROR\n"; my ($lang, $data) = &MyPackages::MyFunctions(); # Module above changed to return data, not HTML # You're going to love deleting all that non-perl code!!! # $data is { first_name => 'Joe', last_name => 'Bloe' } $tt->process("${lang}/homepage.tmpl", $data) || die $tt->error(), "\n";
# in en/homepage.tmpl Welcome $first_name $last_name # or, if you set INTERPOLATE to 0 Welcome [% first_name %] [% last_name %] # in es/homepage.tmpl Bienvenido $first_name $last_name # ...

And so on.

I strongly recommend keeping separate templates for your languages rather than trying to build on the fly, as in

# in single_template.tmpl # Do not do this! $welcome $first_name $last_name, $next_sentence. $second_paragraph. ...

Languages are too different in structure for that.

Good luck: I think you will do fine, based on how you have researched your question so far. You have a lot of work ahead for a few weeks, then one day you will notice that you are able to advance much. much quicker than before the upgrade.

Remember: Ne dederis in spiritu molere illegitimi!

In reply to Re: Concepts of multilangual CGI-Website? by 1nickt
in thread Concepts of multilangual CGI-Website? by Yaerox

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.