Jump to content


Multilanguage Snippets


  • You cannot reply to this topic
No replies to this topic

#1 Piggy

    Etomite Forum Newbie

  • Member
  • 38 posts

Posted 24 June 2005 - 10:22 AM

Hi,

just when starting to translate snippets in my Etomite site to my native language (German), I thought about a convenient way to let snippets automatically change language when the Manager area's language setting changes. This of course would not give you a multilanguage site, as only one language is in effect at any given time, yet it would make things easier for people who are supposed to modify the site, but are not familiar with the English language, but at the same time retain the possibility to switch back to the default (English) language.

So this is what I came up with:
- At the beginning of each snippet utilizing this feature, I'm reading the language setting from the site's configuration
- A String containing the concatenated language dependent terms valid for that snippet has to be defined for each to-be-supported language
- The code then creates an array of terms dependent on the site's language setting
- Each term is being applied within the snippet code at the position where the default English string constant resided before

Of course you'll initially have to overhaul each snippet to get the array values in place, but after that changes can easily be applied through the $language and $msgs_.. variables.

Here's what it could look like in the 'GetStats' snippet:

$language = $etomite->config['manager_language'];

$msgs_en = "Page Impressions#Visits#Visitors#Today#This Month#All Time";
$msgs_de = "Seitenaufrufe#Besuche#Besucher#Heute#Diesen Monat#Insgesamt";

if ($language == "german") {
   $msgarray = explode('#', $msgs_de);
} else {
   $msgarray = explode('#', $msgs_en);
}


$tmpArray = $etomite->getSiteStats();

$output = "
<table width='100%' cellspacing='1' bgcolor='#003399'>
    <tr class='fancyRow'>
        <td width='25%'>&nbsp;</td>
        <td width='25%'><b>".$msgarray[0]."</b></td>
        <td width='25%'><b>".$msgarray[1]."</b></td>
        <td width='25%'><b>".$msgarray[2]."</b></td>
    </tr>
    <tr>
        <td class='fancyRow2'><b>".$msgarray[3]."</b></td>
        <td bgcolor='white'>".number_format($tmpArray['piDay'])."</td>
        <td bgcolor='white'>".number_format($tmpArray['viDay'])."</td>
        <td bgcolor='white'>".number_format($tmpArray['visDay'])."</td>
    </tr>
    <tr>
        <td class='fancyRow2'><b>".$msgarray[4]."</b></td>
        <td bgcolor='white'>".number_format($tmpArray['piMonth'])."</td>
        <td bgcolor='white'>".number_format($tmpArray['viMonth'])."</td>
        <td bgcolor='white'>".number_format($tmpArray['visMonth'])."</td>
    </tr>
    <tr>
        <td class='fancyRow2'><b>".$msgarray[5]."</b></td>
        <td bgcolor='white'>".number_format($tmpArray['piAll'])."</td>
        <td bgcolor='white'>".number_format($tmpArray['viAll'])."</td>
        <td bgcolor='white'>".number_format($tmpArray['visAll'])."</td>
    </tr>
</table>
";

return $output;

Hope this is useful for somebody... :betterwink:

Heiko





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users