I won't claim to have all the answers. I'm a simpleton who cannot grasp, and therefore does not use, OOP. That said, many modules are beyond my comprehension as well, and I cannot use them.

However, I have developed multiple websites that were multilingual. If only a few languages are anticipated, it is simple enough to load them into a JavaScript array and switch languages "live" without a callback to the server. However, when the language data begins to become more weighty, what I have done is to store them in a database and use AJAX to retrieve them as necessary.

Here is an example for the code I use.

#LANGUAGE ARRAY IS DEFINED FIRST VIA PERL
#SOMETHING LIKE . . .

   my %ilanguages = (

   language	=> [ 'English','ไทย','ລາວ','Espaņol','việtnam','简体中文','繁体中文','한국어' ],
    submit	=> [ 'Submit','กดส่ง','ກົດສົ່ງ','Someter','gửi đi','提交','提交','' ],
    preferences	=> [ 'Preferences','การตั้งค่า','ການຕັ້ງຄ່າ','Preferencias','sở thích','喜好','喜好','' ],
    reposition	=>  [ 'Reposition','เปลี่ยนตำแหน่ง','ປ່ຽນຕໍາແຫນ່ງ','Reposicionar','tái định vị','复位','复位','' ],

    );

#THEN THE ARRAY IS USED TO HASH THE REQUESTED LANGUAGE COLUMN
#SOMETHING LIKE THIS...

sub interfaceLanguage {

my $language = shift @_;
    unless ($language) { $language='English' };
    if ($language eq 'Lao') { $language = 'ລາວ' };
    if ($language eq 'Thai') { $language = 'ไทย' };
    if ($language eq 'Spanish') { $language = 'Espaņol' };
    if ($language eq 'Vietnamese') { $language = 'việtnam' };
    if ($language eq 'Korean') { $language = '한국어' };
    if ($language eq 'Simplified Chinese') { $language = '简体中文' };
    if ($language eq 'Traditional Chinese') { $language = '繁体中文' };

    my $index = -1;
    if ($language ne '') { 

        foreach my $lng (@{$ilanguages{'language'}}) {
            ++$index;
            last if ($lng eq $language);
	}
    } else {
	$index = 0;
    } 

    for my $eachkey (keys %ilanguages) {
        # %ilang PRE-DECLARED AS GLOBAL
        $ilang{$eachkey} = $ilanguages{$eachkey}$index;
    };
	
    return;
	
} #END SUB interfaceLanguage


Then the HTML code is formed using the language "handle" for each required expression.
#BUTTON VALUE <input type="button" id="resetwindows" onclick="setScreen();setpos();s +etScreen();setpos();" value="$ilang{reposition}" />


So instead of making the value of your button say something like "Submit", you set the value to "$ilang{submit}". This will get replaced by whichever language is selected.

In the case of a form element in which its value is its text or label on the screen, the value can be updated via JavaScript without necessitating a page reload. If its value is stored in a JS array, this can be done entirely client-side. Or if there is other text, it can be placed in a <div id="preferences"></div> and updated to the language of choice via the innerHTML property for that div element, e.g. document.getElementById("preferences").innerHTML="$ilang{preferences}";. But if the site is to have many language options, AJAX becomes more attractive, and instead of the Perl array I excerpted as an example, a database table for the language data becomes more expedient.

One major advantage to this system is that it also facilitates translation into other languages. It would be simple to create a utility for adding a language column to the database. Adding the new language to the website would then be as simple as adding its name, and possibly a language flag-icon to represent it, to a language menu. Whichever language was selected, that column in the table would be found to supply the language items throughout the page.

Blessings,

~Polyglot~


In reply to Re: Multilingual design by Polyglot
in thread Multilingual design by Bod

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.