How can I make a website is Multi-Language

Member Avatar for diafol

Try Google.

//EDIT

Well, depends if you're using client-side language or server-side language to implement the language interface. Server-side is 'easiest' in my opinion. I regularly develop bilingual and the odd multilingual sites.

You have a few options:

1. You can use a CMS like Joomla and implement Joomfish. It's a little awkward, but tends to be quite easy after the initial fiddle.
2. gettext - use po files - this is really awkward and I don't suggest this unless you know what you're doing.
3. language (array) files - probably the easiest DIY method. I find this easiest when using a template engine like RainTPL or Smarty.

A simple method:

in a folder called 'lang', have the individual language files of your choice:

en.php (English), cy.php (Welsh), it.php (Italian), etc etc

each will need to have an identical structure:

//ENGLISH
$lang = array(
 //meta and nav info
 "lang_name"   => "English",
 "meta_code"   => "en-GB",
 "lang_native" => "English",
 "lang_dir"    => "ltr",
 //login form
 "lbl_username"=> "Username:",
 "lbl_password"=> "Password:",

...(more)...
);
//WELSH
$lang = array(
 //meta and nav info
 "lang_name"   => "Welsh",
 "meta_code"   => "cy-GB",
 "lang_native" => "Cymraeg",
 "lang_dir"    => "ltr",
 //login form
 "lbl_username"=> "Defnyddiwr:",
 "lbl_password"=> "Cyfrinair:",

...(more)...
);

Get the idea?

Now you need a way of including the appropriate lang file into the page:

//get the current language from the $current_lang variable - set this in your config file - could be changed via $_GET or $_POST. I recommend $_GET - easier.

<?php
 include("lang/{$current_lang}.php");
?>
(...DTD...)
<html xmlns="http://www.w3.org/1999/xhtml" dir="<?php echo $lang['lang_dir'];?>" lang="<?php echo $meta_code;?>" xml:lang="<?php echo $lang['lang_dir'];?>">
<head>
 <meta name="language" content="<?php echo $lang_name;?>" />
 <meta http-equiv="Content-Language" content="<?php echo $meta_code;?>" />

...(more)...

</head>
<body>
...(more)...
<label for="username"><?php echo $lang['lbl_username'];?></label>
...(more)...
</body>
</html>

Notice how tedious the php echoes are: you can use a templating engine to make life easier.

If you're interested in this method, I can give you more examples, such as selecting a language / storing language choice, using RainTPL, etc.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.