Page 1 of 1

Multi-lingual page method

Posted: Mon Jul 18, 2005 11:29 pm
by anjanesh
Hi

Im trying to make my page multi-lingual. But I dont want a separate page for each language - that would require too many pages and same updates.

Instead I have a table that has fields like StringNo, English, Lang1, Lang2, Lang3.
The other 3 fields are not Lang1, Lang2 or Lang3 - I just replaced the actual field names.

Somewhere in the beginning of the page, I have

Code: Select all

$Language_Words = GetLanguageStrings(
$Language,
array(
      'Search','News','Enter your name','Something else','etc'
      )
);
This will return the language equivalent of the English String as an array.
I then do

Code: Select all

<tr><td><? echo $Language_Words['News']; ?></td></tr>
This is how my current page is like and is easier because all are in a single page.
But will this be very resource intensive ? Is this efficient ?
How are sites multi-lingual ?

Thanks

Posted: Tue Jul 19, 2005 2:56 am
by onion2k
One common way of making a multi-lingual site is to use constants. For example, on the front end display code you'd use:

Code: Select all

<?php
echo NAME.":<br>";
echo TELEPHONE.":<br>";
echo EMAIL.":<br>";
?>
Then you'd have a series of include files that define the words in each language. For example, english.inc.php might be:

Code: Select all

<?php
define("NAME","Name");
define("TELEPHONE","Telephone");
define("EMAIL","Email");
?>
french.inc.php might be:

Code: Select all

<?php
define("NAME","Nom");
define("TELEPHONE","La Telephone");
define("EMAIL","La Email");
?>
Then, to change language you'd just include() the correct language file.

PS. I can't speak French.

Posted: Tue Jul 19, 2005 3:11 am
by anjanesh
Yes. This is how phpMyAdmin does it too.
But wont defining all contants in a php file take too much memory ?
I know that loading all the values from a MySQL db will take more queries (resources) but I would need to load just the required ones - not all of them.

Thanks.

Posted: Tue Jul 19, 2005 3:18 am
by shiznatix
what i did was make the array like you did

Code: Select all

$words = array
(
  'HELLO' => array
  (
    'eng' => 'Hello',
    'est' => 'Tere',
  ),
  'BYE' => array
  (
    'eng' => 'Bye',
    'est' => 'Hea Aiga',
  ),
)

function dol($word)
{
  $word = $this->words[$word][$_SESSION['lang']];
  return $word;
}
//this was a class blah blah blah

//then to get the word i did 
$lang->dol('HELLO');
that might not have been the best way of doing it but it proved to not take up many resources because there really wasnt much to it other than an array and it was easy to add things and easy to see what i was doing

Posted: Tue Jul 19, 2005 9:12 am
by theda
Or you could be really lazy about it and just make a second page entirely for each page of yours ^_^;; That's what I use to do. Now I do it in an even lamer way... I do the same thing as before, but on the same file using switch(). but most of my content is static and isn't in the form of a forum or sorts, so I don't plan on changing from my current method.

My method explaineD:

Code: Select all

<?
switch($language) {
  default:
  case "en": print "Good day, how are you?"; break;
  case "de": print "Guten tag, wie gehts?"; break
}
?>