views:

192

answers:

3

I am building a English/french website and was wondering if there is a best practice for such a job.

  1. Duplicating the site and making a french and english folder with the appropriate site inside.

  2. Using PHP to swap the content with html tags. eg. if($lang=='en'):

  3. Use php to swap only the content leaving the html tags the same for both. eg. if statements all over the place. Would this be bad for efficiency?

Any other suggestions would be appreciated

+4  A: 

Use a templating system. Smarty Template Engine is probably one of the most well-known PHP ones. Not only does a templating system serve the exact purpose you're trying to accomplish, it also makes maintaining pages far easier by separating the display code from the content (which also allows you to use the same template for lots of different content pages of a similar nature).

Amber
Smarty looks cool. I tried to build my own templating engine. I'm looking for the best way to now make it multilingual.
chris
+3  A: 

We have a framework in place for when (if) our site goes international that works like this...

Folder structure;

/
  lang/
    english/
      images/
      text/
    dutch/
      images/
      text/

Any text or images that are language specific are removed from the page directly and replaced by constants. eg On the login screen, we drop in;

echo TEXT_LOGIN_WELCOME;

which is defined in /lang/english/text/login.php as;

define('TEXT_LOGIN_WELCOME', 'Welcome, please login:');

but in /lang/dutch/text/login.php it's defined as;

define('TEXT_LOGIN_WELCOME', 'Welcome, please login (in dutch):');

;-)

Each language define file is named exactly the same as the page it is used for, so when we load a public-facing page, we only need to figure out which language the user speaks and we can include the relevant language define file.

The good thing about this system is that all the language info is centralised. When you need to add a new language, simply copy the main (english?) folder, rename it, zip the whole thing up and send it to a translation service to work their magic. Of course, the downside of this system is the maintenance as both languages and content grow... If anyone has any bright ideas with regard to this then I'd love to hear them!

Btw, if you end up needing to guess a user's location by IP, you might want to check out geoIP.

MatW
could be hard for a website providing UI in too many languages, I think.
Sepehr Lajevardi
+5  A: 

As the simplest way I recommend you to use i18n internationalization method & gettext catalogs (.po files).
The famous WordPress project is using it as well.

Sepehr Lajevardi