Question:
How can I put French and English language option to my web?
Alex B
2011-04-03 01:21:44 UTC
How can I out French and English language option to my web?
I have created a website with Dream Weaver and it's already finished (but not yet published). Now I want viewers to be able to choose either English or French as optional language. How can I go about it? An easy step by step will be much more appreciated.
Thanks in advance!
Three answers:
Dale
2011-04-03 01:40:35 UTC
There are a few ways to achieve this.



One way is to run your website through a translator or have it translated and have two copies of your site in two separate folders (en & fr) and provide a link to switch between the folders.



Another way is to use some server side technology (PHP, ASP) and use a method of switching between the languages. For example using PHP you could move all the content of your site into a language file, lets call it lang.en.php and it's content may be like this:




$lang_header = "Welcome to mywebsite.com!";

?>



You would then have another file called lang.fr.php and the contents would be as such:




$lang_header = "Bienvenue à mywebsite.com!";

?>



You would use some method to dynamically change the file being included, such as a url variable lang, http://www.example.com?lang=en or http://www.example.com?lang=fr



In your files you would use some statement to include the appropriate language file




$lang = $_GET['lang'];

include( "lang.$lang.php" );

?>



And finally you would replace the actual content of your pages to the chunk of text you want to use.









This is the first few ideas that came to mind, there may be better ways to achieve this, also I used google translate to create the French header so it might be completely messed up I don't know I don't speak French :)
just "JR"
2011-04-03 01:56:13 UTC
Pitty you have already finished the site!

When thinking of developing a multi-lingual site, you should think of its structure before writing any code.

The most common (but incorrect) way is to have every page "duplicated" (copied, identical, but with different languages), thus accessing "register_en", "register_fr", or changing directory: mysite/fr and mysite/en. Both methods present a serious problem of maintenance: to change a text somewhere, you have to review every page!



A better solution is to use a database, with a table called, say, "languages":

table "languages"

id, varchar (25), index, unique

en, text

fr, text

..

Avantage: to add another language, just add a column in your table!



Set-up a global variable $GLang to "en" for English, "fr" for French etc...



Then, write a php function

function p_text($id)

{

global $GLang;

if ($GLang == "")

$GLang = "en"; // set-up a default

$link = dbconnect();

$sql = "select `".$GLang."` from `languages` where `id`='".$id."'";

$list = mysql_query($sql);

$lst = mysql_fetch_array($list);

mysql_free_result($list);

if ($lst[0] == "")

$lst[0] = $id; // if the field is not set, dislay the ID, so you can correct it

$txt = htmlentities($lst[0]); // allow for accentuated characters

$txt = str_replace("\r\n","
",$txt); // CRLF stored in db use \r\n: convert to HTML

mysql_close($link);

return($txt);

}



and call it when you need:

echo (p_text("welcome"));



entry in table:

id = "welcome";

en = "Welcome";

fr = "Bienvenue";

pt = "Bemvindo"; etc...



See an example (work in progress) at http://aa.web2coders.com

Click a flag to change language!
2016-03-02 01:40:56 UTC
Keep trying to get in touch with the photographer. Do not listen to spud. For two reasons. 1. He is encouraging copyright infringement and 2. the images you get off the website will be extremely low resolution and not suitable for printing.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...